编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据,每个学生的数据包括num(学号)、name(姓名)、score[3](3门课的成绩)。用主函数输入这些数据,用print函数输出这些数据。
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
struct Student
{
int num;
string name;
int score[3];
};
void print(Student stu[5])
{
for(int i=0;i<5;i++)
{
cout<<stu[i].num<<endl;
cout<<stu[i].name<<endl;
cout<<stu[i].score[0]<<" "<<stu[i].score[1]<<" "<<stu[i].score[2]<<endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Student student[5]; //定义结构体数组
for(int j=0;j<5;j++)
{
cin>>student[j].num;
cin>>student[j].name;
for(int k=0;k<3;k++)
{
cin>>student[j].score[k];
}
}
print(student);
return 0;
}
C++实现:打印学生成绩数组
这篇博客介绍如何在C++中编写一个名为print的函数,用于打印包含5个学生数据的成绩数组。每个学生数据包括学号、姓名以及3门课程的成绩。主函数负责输入数据,print函数则负责输出。示例代码展示了具体的实现过程。
3756

被折叠的 条评论
为什么被折叠?



