C++程序设计第三版第七章第三题
该题主要利用结构体来完成,在实现过程中,不能忘记数组的传递以实现功能。
#include<iostream>
#include<string>
using namespace std;
void print(int num, char name[30], int score[3]);
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 j,n = 3;
for (i = 1; i <= m; i++)
{
printf("输入学生%d的情况!\n",i);
cin >> xuesheng[i].num
>> xuesheng[i].name;
for (j = 0; j < n; j++)
{
cin >> xuesheng[i].score[j];
}
}
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;
}