private怎么用?
既然不能输入,要来干什么?好象也无法修改吧?#include <iostream.h>
class yunsuan
{
public:
int add(int a,int b);
int cha(int a,int b);
int ji(int a,int b);
int shang(int a,int b);
private:
int a,b;
};
yunsuan::add(int a,int b)
{
return a+b;
}
yunsuan::cha(int a,int b)
{
return a-b;
}
yunsuan::ji(int a,int b)
{
return a*b;
}
yunsuan::shang(int a,int b)
{
return a/b;
}
int main()
{
yunsuan temp;
int a,b;
int c;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"select 1:+;2:-;3:*;4:/;";
cin>>c;
switch (c){
case 1:
{
cout<<temp.add(a,b)<<endl;
break;
}
case 2:
{
cout<<temp.cha(a,b)<<endl;
break;
}
case 3:
{
cout<<temp.ji(a,b)<<endl;
break;
}
case 4:
{
if(b==0)cout<<"erreo"<<endl;
else
cout<<temp.shang(a,b)<<endl;
break;
}
default:
cout<<"erreo"<<endl;
}
return 0;
}