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;
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++)
{
if (s[j].average > s[index].average)
{
index = j;
}
}
temp = s[index];
s[index] = s[i];
s[i] = temp;
}
for (int i = 0; i < n; i++)
{
cout << "第" << i + 1 << "名是" << s[i].name << endl;
cout << s[i].average << endl;
cout << " " << "\n";
}
return 0;
}
标签:index,cout,11.19,int,每日,cin,打卡,include,math From: https://www.cnblogs.com/formygloryandpeacefulday/p/18555724