C++程序设计第三版(谭浩强)第七章第四题
该题和第三题类似,引用函数即可。
#include<iostream>
#include<string>
using namespace std;
void print(int num, char name[30], int score[3]);
void input(int m,int n);
struct chengji {
int num;
char name[30];
int score[3] ;
};
chengji xuesheng[6];
int main()
{
typedef int renshu;
typedef int menshu;
renshu i,m = 5;
menshu n = 3;
for (i = 1; i <= m; i++)
{
input(i, n);
}
for (i = 1; i <= m; i++)
{
print(xuesheng[i].num, xuesheng[i].name, xuesheng[i].score);
}
}
void print(int num, char name[30], int score[3])
{
cout << num << " " << name << " " << score[0] << " " << score[1] << " " << score[2] << endl;
}
void input(int m,int n)
{
printf("输入学生%d的情况!\n", m);
cin >> xuesheng[m].num
>> xuesheng[m].name;
for (int j = 0; j < n; j++)
{
cin >> xuesheng[m].score[j];
}
}