include
include<string.h>
include<windows.h>
using namespace std;
struct student {
char name[10];
int c, math, english;
double average;
};
int main()
{
int index,n;
struct student s[10], temp;
cout << "请输入学生人数:";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "请输入姓名:" << endl;
cin >> s[i].name;
if (strcmp(s[i].name,"贾鸥翼")==0)
{
cout << "这一看就是个卷B"<<endl;
Sleep(1000);
}
cout << "请分别输入第" << i+1 << "位学生的数学,英语,c语言的成绩:";
cin >> s[i].math;
cin >> s[i].english;
cin >> s[i].c;
s[i].average = (s[i].math + s[i].english + s[i].c) * 1.0 / 3;
}
cout << "正在计算平均分并按照平均分排序"<<endl;
Sleep(1000);
for (int i = 0; i < n-1; i++)
{
index = i;
for (int j = i+1; j < n; j++)
{
s[index].average = (s[index].average > s[i].average) ? s[index].average : s[i].average;
}
temp = s[index];
s[index] = s[i];
s[i] = temp;
}
if (strcmp(s[0].name, "贾鸥翼") == 0)
{
cout << "不出意料,卷B又是第一名" << endl;
}
else {
cout << "我屮,有个卷B在控分"<<endl;
Sleep(1000);
cout << "虽然很反感控分这种行为,但程序还是要正常运行" << endl;
}
for (int i = 0; i < n; i++)
{
cout << s[i].name<<endl;
cout << s[i].average<<endl;
cout << " " << "\n";
}
return 0;
}
标签:index,cout,11.19,int,average,cin,打卡,每日,name From: https://www.cnblogs.com/formygloryandpeacefulday/p/18555674