編一個程序,用同一個函數(shù)名對n個數(shù)據(jù)進行從小到大排序,數(shù)據(jù)類型可以是整型,單精度型,雙精度型。用重載函數(shù)實現(xiàn)
#include<iostream>
#include<string>
using namespace std;
int main()
{ long a[5]={10100, -123567, 1198783, -165654, 3456};
int b[5]={1,9,0,23,-45};
float c[5]={2.4,7.6,5.5,6.6,-2.3};
void sort(long []);
void sort(int []);
void sort(float []);
sort(a);
sort(b);
sort(c);
return 0;
}
void sort(long [])
{int i,j;
long t;
for(j=0;j<5;j++)
for(i=0;i<5-j;;j++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers:"<<endl;
for(i=0;i<5;j++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(int [])
{int i,j,t;
for(j=0;j<5;j++)
for(i=0;i<5-j;;j++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers:"<<endl;
for(i=0;i<5;j++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(float [])
{int i,j;
float t;
for(j=0;j<5;j++)
for(i=0;i<5-j;;j++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers:"<<endl;
for(i=0;i<5;j++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
//d:\c++6.0\vs63in1 (g)\vc60chs\vc98\include\ios(9) : fatal error C1083: Cannot open include file: 'streambuf.h': No such file or directory
Cpp1.obj - 1 error(s), 0 warning(s) 請問是什么原因?如何解決?
C++初學習者