用结构体数组的方法改写例9-1
【例9-1】按表9-1的形式从键盘依次输入每个学生的学号、姓名、出生年月、3门课的成绩,计算并打印出每个学生的平均成绩。
输入
第一行,整数n,表示一共有n个学生。
从第二行开始共n行,每行包含学号,姓名,出生年月,数学,英语,C语言,空格隔开,姓名不含空格,出生年月分开输入。
输出
共n行,每行包含学号,姓名,出生年/月,数学,英语,C语言,平均成绩。
输出浮点数使用%.0f,出生年月用/分开。
样例输入 Copy
2
901 hulei 1990 8 67 78 89
902 fangang 1991 7 85 69 76
样例输出 Copy
901 hulei 1990/8 67 78 89 78
902 fangang 1991/7 85 69 76 77
代码示例(自己写的,只能过平台,不完美)
//#include<iostream>
//#include<string>
//#include<string.h>
//#include <algorithm>
//using namespace std;
//
//struct student{
// int um;
// char name[20];
// int year,mon;
// double math,eng,c;
// double aver;
//}stu[20];
//
//int main(){
// int n = 0;
// while(cin >> n){
// for(int i = 0; i < n; i++){
// scanf("%d %s %d %d %lf %lf %lf",&stu[i].um,&stu[i].name,&stu[i].year,&stu[i].mon,&stu[i].math,&stu[i].eng,&stu[i].c);
// stu[i].aver = (stu[i].math + stu[i].eng + stu[i].c) / 3;
// }
// for(int i = 0; i < n; i++){
// printf("%d %s %d",stu[i].um,stu[i].name,stu[i].year);
// cout << "/";
// printf("%d %g %g %g ",stu[i].mon,stu[i].math,stu[i].eng,stu[i].c);
// printf("%.0f\n",stu[i].aver);
// }
// }
// return 0;
//}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。