Problem Description
Example rewriting method of an array of structures 9-1
[Example 9-1] Table 9-1 in the form of input from the keyboard in sequence each student number, name, date of birth, 3 course results, calculate and print out of each student's grade point average.
Entry
The first line, integer n, there are n represents a student.
Start from the second row a total of n lines, each line containing the number, name, date of birth, mathematics, English, C language, separated by a space, the name does not contain spaces, date of birth separate input
Export
A total of n lines, each line containing the number, name, date of birth / month, mathematics, English, C language, grade point average.
Output of the floating point% .0f, date of birth with / separated.
Sample input
2
901 hulei 1990 8 67 78 89
902 fangang 1991 7 85 69 76
Sample Output
901 hulei 1990/8 67 78 89 78
902 fangang 1991/7 85 69 76 77
AC Code
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef struct Stu{
int num;
char name[20];
int year;
int month;
int math;
int english;
int C_language;
float ave;
};
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
Stu stu;
cin >> stu.num >> stu.name >> stu.year >> stu.month >> stu.math >> stu.english >> stu.C_language;
stu.ave = ceil((stu.math + stu.english + stu.C_language) / 3.0);
cout << stu.num << " "<< stu.name << " " << stu.year << "/" << stu.month << " " << stu.math << " " << stu.english << " " << stu.C_language << " ";
printf("%.0f\n",stu.ave);
}
}