#include"iostream"
using namespace std;
class zhengshu
{
public:
float jia(float a,float b)
{ return a+b;}
float jian(float a,float b)
{ return a-b;}
float cheng(float a,float b)
{ return a*b;}
float chu(float a,float b)
{ return a/b;}
};
int main()
{ zhengshu one;
float a,b,c;
char i;
cout<<"请输入两个整数的计算式:"<<endl;
cin>>a;
cin>>i;
cin>>b;
cout<<"结果为:";
if(i=='+')
cout<<one.jia (a,b);
if(i=='-')
cout<<one.jian(a,b);
if(i=='*')
cout<<one.cheng(a,b);
if(i=='/')
cout<<one.chu(a,b);
cout<<endl;
if(i!='+'&&i!='-'&&i!='*'&&i!='/')
cout<<"输入有误!!!"<<endl;
}
疑问如下:
zhengshu one;
cout<<one.jia (a,b);
表示什么意思,求解答
------解决方案--------------------
把a和b加起来的结果显示在屏幕上
------解决方案--------------------
zhengshu one;
这句话,声明一个类zhengshu的对象one;
cout<<one.jia(a,b);
这句,调用one 的jia方法,参数是a和b,并把结果输出到标准输出(屏幕)上