C++编程:编写一个函数print,打印一个学生的成绩数组,该书组中有五个学生的数据

2016-06-24 14:21:47  分类: c++程序设计第三版谭浩强课后答案  参与:

C++编程:编写一个函数print,打印一个学生的成绩数组,该书组中有五个学生的数据,每个学生的数据包括num(学号)、name(姓名)、score[3]](3门课的成绩)、用主函数输入这些数据,用print函数输出这些记录。

以下是此题的【c++源代码】,需要【c源代码】请点击进入

#include <iostream>
#include <iomanip>
using namespace std;
const int n=5;
struct student
{ char num[6];
  char name[8];
  int score[4];
}stu[n];
int main()
{void print(student stu[6]);
 int i,j;
 for (i=0;i<n;i++)
 {cout<<"input scores of student "<<i+1<<":"<<endl;
  cout<<"NO.: ";
  cin>>stu[i].num;
  cout<<"name: ";
  cin>>stu[i].name;
  for (j=0;j<3;j++)
    {cout<<"score "<<j+1<<":";
     cin>>stu[i].score[j];
    }
  cout<<endl;
 }
print(stu);
return 0;
}

void print(student stu[6])
 {int i,j;
  cout<<" NO.      name      score1   score2   score3"<<endl;
  for (i=0;i<n;i++)
   {cout<<stu[i].num<<"  "<<setw(10)<<stu[i].name<<"      ";
    for (j=0;j<3;j++)
      cout<<setw(3)<<stu[i].score[j]<<"      ";
    cout<<endl;
   }
 }
 



C++编程:编写一个函数print,打印一个学生的成绩数组,该书组中有五个学生的数据

来源:c++程序设计第三版谭浩强课后答案

本文链接:http://www.wb98.com/cjia/post/cjia_7.3.html


本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

赞助商链接