#include<iostream.h>
int max_(int a,int b);
float max_(float x,float y);
int max_(int a,int b,int c);
float max_(float x,float y,float z);
int main(int argc,char **argv)
{
int d;
int a,b,c,max_1,max_1_;
float x,y,z,max_2,max_2_;
cout<<"1 两个整数"<<endl<<"2 三个整数"<<endl<<"3 两个双精度数"<<endl<<"4 三个双精度数"<<endl;
while(1)
{
cout<<"请选择";cin>>d;
switch(d)
{
case 1: cout<<"please enter two numbers(int)"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
max_1=max_(a,b);
cout<<"the max is "<<max_1<<endl;break;
case 2: cout<<"please enter three numbers(int)"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
max_1_=max_(a,b,c);
cout<<"the max is "<<max_1_<<endl;break;
case 3: cout<<"please enter two numbers(float)"<<endl;
cout<<"x=";
cin>>x;
cout<<"y=";
cin>>y;
max_2=max_(x,y);
cout<<"the max is "<<max_2<<endl;break;
case 4: cout<<"please enter three numbers(float)"<<endl;
cout<<"x=";
cin>>x;
cout<<"y=";
cin>>y;
cout<<"z=";
cin>>z;
max_2_=max_(x,y,z);
cout<<"the max is "<<max_2_<<endl;break;
}
}
return 0;
}
int max_(int a,int b)
{
if(a>b)
return a;
else return b;
}
float max_(float x,float y)
{
if(x>y)
return x;
else return y;
}
int max_(int a,int b,int c)
{
if(a>b)
{if(a>c)
return a;
else return c;
}
else
{
if(b>c)
return b;
else return c;}
}
float max_(float x,float y,float z)
{
if(x>y)
{if(x>z)
return x;
else return z;
}
else
{
if(y>z)
return y;
else return z;
}
}
C++重载函数及重载函数模板的使用
5星 · 超过95%的资源 需积分: 33 146 浏览量
2011-06-22
09:55:24
上传
评论 4
收藏 3KB ZIP 举报
jie1793162945
- 粉丝: 3
- 资源: 9
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈