/*
题目:输入三个整数x,y,z,请把这三个数由小到大输出。
1.程序分析:选用运算符号<和>重载函数分别算出最大值和最小值
然后再判断中间值
by adengou 2011.8.13
win7 dev c++5.0 and vs 2010 通过
*/
#include <iostream>
using namespace std;
class Cmax
{
private :
double x;
public:
Cmax(double a=0.0){x=a;}
//double val(){return x;}
/*求小值,运算符重载函数*/
friend Cmax operator<(Cmax c1,Cmax c2)
{
return(c1.x<c2.x?c1:c2);
}
/*求大值,运算符重载函数*/
friend Cmax operator>(Cmax c1,Cmax c2 )
{
return(c1.x>c2.x?c1:c2);
}
void min_max(Cmax c1,Cmax c2,Cmax c3);
};
void Cmax::min_max(Cmax c1,Cmax c2,Cmax c3)
{
int i;
double arrayNum[]={c1.x,c2.x,c3.x};
double *pt;pt=arrayNum;
Cmax min,max,mid;
min=c1<c2<c3;
max=c3>c2>c1;
for(i=0;i<3;i++){if(*(pt+i)!=min.x &&*(pt+i)!=max.x){mid.x=*(pt+i);}}
cout<<c1.x<<"、"<<c2.x<<"、"<<c3.x<<"三个数从小到大排序是:"<<min.x<<" "<<mid.x<<" "<<max.x<<endl;
};
int main()
{ double v,m,n;
cout<<"please input thtee numbers:\n"; cin>>v>>m>>n;
Cmax A(v),B(m),C(n),D;
D.min_max(A,B,C);//从小到大排序函数
system("pause");
return 0;
}