（由于是做一道题目时发现的这个问题，所以就没有简略的代码和图片了，代码问题部分加粗了，主要为语句cout << one[i].id）
#include
using namespace std;
struct information
{
char name[20];
int id;
double MT;
double EN;
double PH;
double AVG;
};
void input(information[], int);
void output1(information[], int);
void output2(information[], int);
void operation(information[], int);
void R(information[], int);
int main()
{
information student[100];
int total;
cout << "请输入学生人数";
cin >> total;
cout << "请完善各个学生的数据" << "\n";
input(student, total);
operation(student, total);
cout << "下列为所有学生的成绩表" << "\n";
output1(student, total);
R(student, total);
cout << "其中成绩尤为突出学生是" << "\n";
output2(student, total);
}
void input(information one[], int x)
{
for (int i = 0;i < x;i++)
{
cout << "请输入第" << i + 1 << "个学生的数据" << endl;
cout << "他的学号为";
cin >> one[i].id;
cout << "他的名字为";
cin >> one[i].name;
cout << "他的数学成绩为";
cin >> one[i].MT;
cout << "他的英语成绩为";
cin >> one[i].EN;
cout << "他的物理成绩为";
cin >> one[i].PH;
}
}
void operation(information one[], int x)
{
for (int i = 0;i < x;i++)
{
one[i].AVG = (one[i].MT + one[i].EN + one[i].PH) / 3;
}
}
void output1(information one[], int x)
{
for (int i = 0;i < x;i++)
{
**cout << one[i].id
<< "\t" << one[i].name<< "\t" << one[i].MT << "\t" << one[i].EN << "\t" << one[i].PH << "\t";
printf("%3.4f", one[i].AVG);
cout << "\n";
}**
}
void R(information one[], int x)
{
int i, j;
information team;
for (i = 0;i < x;i++)
{
for (j = 0;j <= x - i - 1;j++)
{
if (one[j].AVG < one[j + 1].AVG)
{
team = one[j];
one[j] = one[j + 1];
one[j + 1] = team;
}
}
}
}
void output2(information one[], int x)
{
for (int i = 0;i < 3;i++)
{
cout << "第" << i + 1 << "名";
cout << one[i].name << "同学,";
cout << "他的平均分是 ";
printf("%3.4f", one[i].AVG);
cout << " 分。" << "\n";
}
}

1个回答

int id;

dearMakiseKurisu 刚刚看程序才发现，我为自己的无厘头感到羞愧，想过来撤销，结果您已经回答了，浪费阁下时间了。
4 个月之前 回复