有 5 个学生,每个学生的数据包括学号、姓名、3 门课的成绩,从键盘输入每个学生的数据,打印出每个学生的总分及三门课的平均成绩。注意:使用结构体,自定义两个函数(非 main 函数),一个读入数据,一个实现输出。
输入样例:
202001 wang 60 80 78
202002 tang 75 88 91
202003 sang 83 92 88
#include<iostream>
using namespace std;
struct Student
{
int Sno;//学号
string Name;//姓名
float Score1;
float Score2;
float Score3;
};
void writeInfo(Student stu[])
{
int sno;
string name;
float score1, score2, score3;
cout << "依次输入数据,按照学号、姓名、三个成绩" << endl;
for (int i = 0; i < 5; i++)
{
cin >> sno >> name >> score1 >> score2 >> score3;
stu[i].Sno = sno;
stu[i].Name = name;
stu[i].Score1 = score1;
stu[i].Score2 = score2;
stu[i].Score3 = score3;
cout << endl;
}
}
void printInfo(Student stu[])
{
for (int i = 0; i < 5; i++)
{
cout << stu[i].Sno << stu[i].Name << stu[i].Score1 << stu[i].Score2 << stu[i].Score3 << endl;
}
}
int main()
{
Student stu[5];
writeInfo(stu);
printInfo(stu);
}