编写一个函数print,打印一个学生的成绩数组

C++实现:打印学生成绩数组
这篇博客介绍如何在C++中编写一个名为print的函数,用于打印包含5个学生数据的成绩数组。每个学生数据包括学号、姓名以及3门课程的成绩。主函数负责输入数据,print函数则负责输出。示例代码展示了具体的实现过程。

编写一个函数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;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值