求一个c++程序,要求用函数重载,实现两个整数和三个浮点数的排序,并按照从小到大的顺序将排序结果输出

要完整的程序,不要写个大概,因为我要交作业,我实在不太会(初学者+零基础+c语言挂科),请给我一个确实是编译正确的,不要在往上瞎抄,帮帮初学者,谢谢了

#include <iostream>
using namespace std;
void sort(int &a,int &b)
{
int temp;
if (a>b)
{
temp = a;
a = b;
b = temp;
}
}
void sort(float &a,float &b,float &c)
{
int temp[3];
if (b>a)
{
temp[0] = a;
temp[1] = b;
if (c>b)
temp[2] = c;
else
{
if (c<a)
{
temp[0] = c;
temp[1] = a;
temp[2] = b;
}
else
{
temp[1] = c;
temp[2] = b;
}

}
}
else
{
temp[0] = b;
temp[1] = a;
if (a>c)
{
if (b>c)
{
temp[0] = c;
temp[1] = b;
temp[2] = a;
}
else
{
temp[1] = c;
temp[2] = a;
}
}
else
temp[2] = c;
}
a = temp[0];
b = temp[1];
c = temp[2];
}
int main()
{
int a,b;
float c,d,e;
cout<<"请输入两个整数:"<<endl;
cin>>a>>b;
sort(a,b);
cout<<"排序之后:"<<a<<"\t"<<b<<"\t"<<endl;
cout<<"请输入三个浮点数:"<<endl;
cin>>c>>d>>e;
sort(c,d,e);
cout<<"排序之后:"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<endl;
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-10-20
这个问题并不难,自己想想肯定会。
初学者更应该好好学,而不是在这里要代码追问

江湖救急啊,我要加作业了,我会好好学的,你到底会不会啊,别整那些没有用的

追答

你既然说出了"你到底会不会啊"这种话,我还有可能真的替你写这破玩意么?

追问

小伙,你太有性格了,哈哈

追答

我到底会不会,你看看我回答了别人多少c++问题,就能知道

追问

我现在赐予你“c++中的教父”的称号,你高兴了吧,要是高兴了就帮我写一个

相似回答