首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

vc++有关问题,

2012-02-23 
vc++问题,急~~~~~~~!!!!#include stdio.h#includestring.h #includestdlib.h #includemath.h #inc

vc++问题,急~~~~~~~!!!!
#include <stdio.h>
#include   "string.h "
#include   "stdlib.h "
#include   "math.h "
#include   "process.h "
#include   "iostream.h "

#define   TRUE   1
#define   FALSE   0
#define   OK   1
#define   ERROR   0
#define   OVERFLOW       _OVERFLOW
#define   STACK_INIT_SIZE   100
#define   STACKINCREMENT   10

typedef   char   SElemType;
typedef   struct   SqStack
{
      double   *base;
      double   *top;
      int   stacksize;
}SqStack;  

void   InitStack(SqStack   &S);
double   ClearStack(SqStack   &S);  
double   GetTop(SqStack   S,double   *e);  
void   Push(SqStack   &S,double   e);  
double   Pop(SqStack   &S,double   *e);    
char   precede(char   a,char   b);  
int   flag(char   ch);  
double   Operate1(double   a,char   theta,double   b);    
double   Operate2(char   theta,double   a);  
double   In(char   c);  

double   Operate1(double   a,char   theta,double   b)
{
      double   c;
      switch(theta)
      {
          case '+ ':c=a+b;break;
          case '- ':c=a-b;break;
          case '* ':c=a*b;break;
          case '/ ':if(b!=0)   c=a/b;
                          else   printf( "syntax   error! ");
                          break;
          case '^ ':c=pow(a,b);break;
      }
          return   c;
}

double   Operate2(char   theta,double   a)
{
      double   c;
      switch(theta)
        {
            case 's ':c=sin(a);break;
            case 'c ':c=cos(a);break;
            case 'l ':if(a> 0)
                            c=log(a);
                            break;
            case 'g ':if(a> 0)
                            c=log10(a);
                            break;
        }
      return   c;
}

double   In(char   c)
{  
      switch(c)
        {
            case '+ ':
            case '- ':
            case '* ':


            case '/ ':
            case '( ':
            case ') ':
            case '= ':
            case '^ ':
            case 's ':
            case 'l ':
            case 'g ':
            case 'c ':return   1;
            default:return   0;
        }
}

void   InitStack(SqStack   &S)
{  
      if(!(S.base=(double   *)malloc(STACK_INIT_SIZE*sizeof(double))))
          exit(OVERFLOW);  
      S.top=S.base;
      S.stacksize=STACK_INIT_SIZE;
}

double   ClearStack(SqStack   &S)
{
    S.top=S.base;
    return   OK;
}

double   GetTop(SqStack   S,double   *e)
{  
      if(S.top==S.base)     return   ERROR;
      else
          *e=*(S.top-1);
        cout < < "OK ";      
}

void   Push(SqStack   &S,double   e)
{  
      if(S.top-S.base> =S.stacksize)
      {
          S.base=(double   *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(double));
          if(!S.base)
              exit(OVERFLOW);  
          S.top=S.base+S.stacksize;
          S.stacksize+=STACKINCREMENT;
      }
      *(S.top)++=e;
      cout < < "OK ";
}

double   Pop(SqStack   &S,double   *e)
{  
      if(S.top==S.base)
          return   ERROR;
      *e=   *   --S.top;
      cout < < "OK ";
}

int   flag(char   ch)
{
switch(ch)
    {
      case '+ ':   return   0;   break;
      case '- ':   return   1;   break;
      case '* ':   return   2;   break;
      case '/ ':   return   3;   break;
      case '( ':   return   4;   break;
      case ') ':   return   5;   break;
      case '# ':   return   6;   break;
      default:   return   7;
    }
}


char   precede(char   a,char   b)
{
int   i,j;
char   ch[7][7]={{ '> ', '> ', ' < ', ' < ', ' < ', '> ', '> '},
{ '> ', '> ', ' < ', ' < ', ' < ', '> ', '> '},
{ '> ', '> ', '> ', '> ', ' < ', '> ', '> '},


{ '> ', '> ', '> ', '> ', ' < ', '> ', '> '},
{ ' < ', ' < ', ' < ', ' < ', ' < ', '= ', '0 '},
{ '> ', '> ', '> ', '> ', '0 ', '> ', '> '},
{ ' < ', ' < ', ' < ', ' < ', ' < ', '0 ', '= '}
};
i=flag(a);
j=flag(b);
cout < <ch[j];
}


void   main()
{
      printf( "\now   we   defined:s()=sin(),c()=cos(),l()=ln(),g()=lg()\n ");

      SqStack   OPTR,OPND;
      int   e;
      double   a,b,x,theta;
      double   d,f,p;
      char   c   ;
      char   z[60];
      int   i;

      InitStack(OPTR);   Push(OPTR, '# ');
      InitStack(OPND);   c   =   getchar();  

      while(c!= '# '||GetTop(OPND,p)!= '# ')//
        {
            if(In(c))
              {
        switch(Precede(GetTop(OPTR),c))
            {
                case   ' < ':
                                    Push(OPTR,c);
                                    c=getchar();
                                    GetTop(OPTR,theta);
                                    break;

                case   '= ':
                                  Pop(OPTR,theta);
                                  GetTop(OPTR,theta);
                                  if(theta== 's '||theta== 'l '||theta== 'c '||theta== 'g ')
                                  {
                                  Pop(OPND,f);
                                  Pop(OPTR,theta);
                                  Push(OPND,Operate2(theta,f));
                                  GetTop(OPTR,theta);
                                  c=getchar();


                                  break;
                                  }
                                  else
                                  {
                                    c=getchar();
                                    break;
                                  }
                case   '> ':
                                  if(theta== '+ '||theta== '- '||theta== '* '||theta== '/ '||theta== '^ ')
                                    {
                                    Pop(OPTR,theta);
                                    Pop(OPND,b);
                                    Pop(OPND,a);
                                    f=Operate1(a,theta,b);1
                                    Push(OPND,f);
                                    GetTop(OPTR,theta);
                                    break;
                                    }    
                                      else   break;
                                      }
              }
              else   if(c> = '0 '&&c <= '9 '||c== '. ')
                  {
                      i=0;
                      do
                {
                    z=c;i++;
                    c=getchar();
                }
                      while((c <= '9 '&&c> = '0 ')||c== '. ');


                      z=0;
                      d=atof(z);
                      Push(OPND,d);
                  }
                  else
                    {
                printf( "error\n ");
                exit(ERROR);
                    }
}
      GetTop(OPND,x);
      printf( "%f ",x);
      ClearStack(OPTR);
      ClearStack(OPND);
      printf( "\nDo   you   want   to   use   it   again?Yes:Y,No:N ");
      scanf( "%d ",&e);
      x=getchar();
}
      while(e);
      printf( "\nThanks   for   using   the   calulating   device!!! ");
      printf( "\npress   any   key   to   continue... ");
      x=getchar();
      x=getchar();
}


为什么以上程序在vistual   studio   6.0   上编译有错,请各位大侠帮帮忙,
小弟有急用,谢谢了

[解决办法]
先从这个语句
while(c!= '# '||GetTop(OPND,p)!= '# ')//
看起,那个GetTop(OPND,p)的参数p传递的应该是一个地址,而你的调用全是值调用!
从而引起了相关的一系列错误!

热点排行