Title Description
Write a function print that prints an array of students ' scores, with data for 5 students, each of which includes NUM (student number), name (name), Score[3] (3-course score). Write a function input that is used to enter data for 5 students.
Input
5 student's number, name, 3-course Grade
Output
5 student's number, name, 3-course Grade
Sample input
1001 Zhangsan 861002 Lisi, 801003 Wangwu, 891004 yanping, 1001005 Xiaoxiao 60 60 60
Sample output
1001 Zhangsan 861002 Lisi, 801003 Wangwu, 891004 yanping, 1001005 Xiaoxiao 60 60 60
Tips
The main function is given below, and it is not required to include the following main function when committing
/* C code */
int main ()
{
const int n=5;
struct student stu[n];
void input (struct student [],int);
void print (struct student [],int);
Input (stu,n);
Print (stu,n);
return 0;
}
/* C + + code */
int main ()
{
const int n=5;
Student Stu[n];
void input (student [],int);
void print (student [],int);
Input (stu,n);
Print (stu,n);
return 0;
}
The full code is as follows:
#include <iostream>using namespace std;struct student{ int num; string name; int score[3];}; void input (student stu[],int N) {for (int i=0;i<n;i++) { cin>>stu[i].num>>stu[i].name; for (int j=0;j<3;j++) { cin>>stu[i].score[j]; }} } void print (student stu[],int N) {for (int i=0;i<n;i++) { cout<<stu[i].num<< "" << stu[i].name<< "" <<stu[i].score[0]<< "<<stu[i].score[1]<<" "<<stu[i].score[2" <<endl;} } int main () { const int n=5; Student Stu[n]; void input (student [],int); void print (student [],int); Input (stu,n); Print (stu,n); return 0;}
Operation Result:
ytuoj-student scores input and output (user-defined type)