- /*
- * 程序的版权和版本声明部分
- * Copyright (c)2013, 烟台大学计算机学院学生
- * All rightsreserved.
- * 文件名称:score.cpp
- * 作 者:王俊
- * 完成日期:2013 年 3 月 13 日
- * 版本号: v1.0
- * 输入描述:
- * 问题描述:
- * 输出:
- */
- 代码程序:
#include <iostream> #include <iomanip> #include <fstream> using namespace std; struct Student {char num[13]; char name[10];int cpp;int math;int english;int grade; }; const int N=100; int main( ) {int i, stuNum=0;Student stu[N];ifstream infile("score.txt",ios::in); if(!infile) {cerr<<"open error!"<<endl;exit(1);}i=0;while(!infile.eof()){infile>>stu[i].num>>stu[i].name>>stu[i].cpp>>stu[i].math>>stu[i].english;stu[i].grade=stu[i].cpp+stu[i].math+stu[i].english;++stuNum;++i;}infile.close();for(i=0; i<stuNum; ++i){cout<<setw(10)<<stu[i].num<<setw(8)<<stu[i].name<<setw(5)<<stu[i].cpp<<setw(5)<<stu[i].math<<setw(5)<<stu[i].english<<setw(5)<<stu[i].grade<<setw(5)<<endl;}return 0; }
- 运行结果:
:
15.心得体会:说实话,对于这个程序我还是有些不太明白。能写出来照着葫芦画瓢成分居多。