用c++编写重载函数max1课分别求取2个整数、3个整数、2个双精度数和3个双精度数的最大值。

kkk快快快
2024-11-22 23:52:58
推荐回答(5个)
回答(1):

c++编写

#include

using namespace std;

int Max1(int a,int b){

if(a>b)

return a;

else 

return b;

}

double Max1(double x,double y){

if(x>y)

return x;

else 

return y;

}

int Max1(int a,int b,int c){

return Max1(a,Max1(b,c));

}

double Max1(double x,double y,double z){

return Max1(x,Max1(y,z));

}

int main(){

int a,b,c;

cout<<"please enter two integer:";

cin>>a>>b;

cout<<"there is the answer:"<

cout<<"please enter three integer:";

cin>>a>>b>>c;

cout<<"there is the answer:"<

double x,y,z;

cout<<"please enter two numder:";

cin>>x>>y;

cout<<"there is the answer:"<

cout<<"please enter three number:";

cin>>x>>y>>z;

cout<<"there is the answer:"<

return 0;

}

回答(2):

int max(int a,int b){ if(ab) return a; else return a;} int max(int a,int b,int c){ int max; if(a

回答(3):

#include
using namespace std;
int Max1(int a,int b){
if(a>b)
return a;
else
return b;
}
double Max1(double x,double y){
if(x>y)
return x;
else
return y;
}
int Max1(int a,int b,int c){
return Max1(a,Max1(b,c));
}
double Max1(double x,double y,double z){
return Max1(x,Max1(y,z));
}

int main(){
int a,b,c;
cout<<"please enter two integer:";
cin>>a>>b;
cout<<"there is the answer:"<
cout<<"please enter three integer:";
cin>>a>>b>>c;
cout<<"there is the answer:"<
double x,y,z;
cout<<"please enter two numder:";
cin>>x>>y;
cout<<"there is the answer:"<
cout<<"please enter three number:";
cin>>x>>y>>z;
cout<<"there is the answer:"<
return 0;
}

回答(4):

int max(int a , int b );int max(int a , int b , int c);int max(double a,double b);int max(double a,double b,double c);这样就可以了。

回答(5):

这个书上都有写的吧。。。