cs
#include <iostream>
using namespace std;
struct stu
{
private:
int num;
private:
double score[32];
public:
void setNum()
{
cout <<"请输入学生人数:";
cin >>num;
}
void input()
{
cout<<"请输入学生的成绩:"<<endl;
for(int i=0; i<num; i++)
{
cout<<"第"<<i+1<<"个学生成绩:";
cin>>score[i];
}
}
void sort()
{
double temp;
int flag = 0;
for(int i=1; i<num; i++)
{
flag =0;
for(int j=0; j<num-i; j++)
{
if(score[j]<score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
flag = 1;
}
}
if(0 ==flag)
break;
}
}
void show()
{
for(int i=0; i<num; i++)
{
cout <<score[i]<<" ";
}
cout <<endl;
}
};
int main()
{
stu s;
s.setNum();
s.input();
s.sort();
s.show();
return 0;
}