class compare
{
private:
int a;
int b;
int c;
public:
//~compare(); /////////////////为什么要注释掉
//compare(); /////////////////为什么要注释掉
int comparing(int);
char comparing(char);
double comparing(double);
};
int compare:: comparing(int max)
{
cout<<"lease input three integers!!"<<endl;
int a,b,c;
cin>>a >>b >>c;
cout<<endl;
if(b>a)
a=b;
if(c>a)
a=c;
max=a;
cout<<"The max integer is "<< max<<endl;
return max;
}
char compare:: comparing(char max)
{
cout<<"lease input three strings!!"<<endl;
char a,b,c;
cin>>a >>b >>c;
cout<<endl;
if(b>a)
a=b;
if(c>a)
a=c;
max=a;
cout<<"The max string is "<< max<<endl;
return max;
}
double compare:: comparing(double max)
{
cout<<"lease input three floats!!"<<endl;
double a,b,c;
cin>>a >>b >>c;
cout<<endl;
if(b>a)
a=b;
if(c>a)
a=c;
max=a;
cout<<"The max float is "<< max<<endl;
return max;
}
int main()
{
compare MAX;
int flag;
cout<<"lease input a value for flag!! The value must be 0 or 1 or 2"<<endl;
cin>>flag;
switch(flag)
{
case 0:
int max1;
MAX.comparing(max1);
break;
case 1:
char max2;
MAX.comparing(max2);
break;
case 2:
double max3;
MAX.comparing(max3);
break;
default:
cout<<"input error!!"<<endl;
exit(0);
}
[kevin@kevin C]$ g++ -o test a.cpp
[kevin@kevin C]$ ./test
Please input a value for flag!! The value must be 0 or 1 or 2
0
Please input three integers!!
2 3 4