帮我看看!
#include <iostream.h>void main()
{
double fristnum;
char sop;
double secondnum;
int frist;
int second;
cout<<"请输入表达式:"<<endl;
cin>>fristnun>>sop>>secondnum;
cout<<"结果:"<<calc(fristnum,sop,secondnum)<<endl;
}
double calc(double fristnum,char sop,double secondnum)
{
calculator *pcalc=NULL;
pcalc=judge(fristnum,sop,secondnum);
double frusult=pclac->result();
delete pcalc;
return fresult;
}
class calcultor
{
public:
double data1();
{
return m_fdata1;
}
void setdata1(double fristnum)
{
m_fdata1=fristnum;
}
double data2();
{
return m_fdata2;
}
void setdata2(double secondnum)
{
m_fdata2=secondnum;
}
double result() const=0;
private:
double m_fdata1,m_fdata2;
};
calcultor *judge(double fristnum,char sop,double secondnum)
{
calcultor *pcalc=NULL;
if(sop='+')
pcalc=new add();
else if(sop='-')
pcalc=new sub();
else if(sop='^')
pcalc=new power();
else if(sop='%')
pcalc=new compement();
else
throw string("不可识别的运算符!");
pcalc->setdata1(fristnum);
pcalc->setdata2(secondnum);
return pcalc;
}
class add:public calcultor
{
public:
add(double fristnum=0.,double secondnum=0.)
{
calcultor(fristnum,secondnum);
}
double result() const
{
return data1()+data2();
}
};
class sub:public calcultor
{
public:
sub(double fristnum=0.,double secondnum=0.)
{
calcultor(fristnum,secondnum);
}
double result() const
{
return data1()-data2();
}
};
class power:public calcultor
{
public:
power(double fristnum=0.,double secondnum=0.)
{
calcultor(fristnum,secondnum);
}
double result() const
{
return data1()^data2();
}
};
class complement:public calcultor
{
public:
complement(double fristnum=0.,double secondnum=0.)
{
calcultor(fristnum,secondnum);
}
double result() const
{
return data1()%data2();
}
};
报的错是calnew.cpp(63) : error C2143: syntax error : missing ';' before '}'
不知为啥?求指导~
[ 本帖最后由 ll564992764 于 2011-10-15 20:24 编辑 ]