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

kkk快快快

c++编写

#include <iostream>

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:"<<Max1(a,b)<<endl;

cout<<"please enter three integer:";

cin>>a>>b>>c;

cout<<"there is the answer:"<<Max1(a,b,c)<<endl;

double x,y,z;

cout<<"please enter two numder:";

cin>>x>>y;

cout<<"there is the answer:"<<Max1(x,y)<<endl;

cout<<"please enter three number:";

cin>>x>>y>>z;

cout<<"there is the answer:"<<Max1(x,y,z)<<endl;

return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-02
int max(int a,int b){ if(a<b) return b; else if(a>b) return a; else return a;} int max(int a,int b,int c){ int max; if(a<b) max=a; else max=b; if(max<c) max=c; else max=max; return max;}双精度的也差不多
第2个回答  2016-09-21
#include <iostream>
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:"<<Max1(a,b)<<endl;

cout<<"please enter three integer:";
cin>>a>>b>>c;
cout<<"there is the answer:"<<Max1(a,b,c)<<endl;

double x,y,z;
cout<<"please enter two numder:";
cin>>x>>y;
cout<<"there is the answer:"<<Max1(x,y)<<endl;

cout<<"please enter three number:";
cin>>x>>y>>z;
cout<<"there is the answer:"<<Max1(x,y,z)<<endl;

return 0;
}本回答被网友采纳
第3个回答  2013-08-02
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);这样就可以了。
第4个回答  2013-08-02
这个书上都有写的吧。。。
第5个回答  2013-08-02
int max(int a,int b){ if(a<b) return b; else if(a>b) return a; else return a;} int max(int a,int b,int c){ int max; if(a<b) max=a; else max=b; if(max<c) max=c; else max=max; return max;}双精度的也差不多
第6个回答  2016-09-21
#include <iostream>
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:"<<Max1(a,b)<<endl;

cout<<"please enter three integer:";
cin>>a>>b>>c;
cout<<"there is the answer:"<<Max1(a,b,c)<<endl;

double x,y,z;
cout<<"please enter two numder:";
cin>>x>>y;
cout<<"there is the answer:"<<Max1(x,y)<<endl;

cout<<"please enter three number:";
cin>>x>>y>>z;
cout<<"there is the answer:"<<Max1(x,y,z)<<endl;

return 0;
}本回答被网友采纳
第7个回答  2013-08-02
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);这样就可以了。
第8个回答  2013-08-02
这个书上都有写的吧。。。
相似回答
大家正在搜