2-4动态列表
/** 程序的版权和版本声明部分* Copyright (c)2013, 烟台大学计算机学院学生* All rightsreserved.* 文件名称:score.cpp * 作 者:纪子龙 * 完成日期:2013 年3 月 8 日* 版本号: v1.0 * 输入描述:无* 问题描述:无* 输出:无*/#include <iostream>#include <fstream> //操作文件必写using namespace std;struct Score{ char num[14];char nam[30];int cpp;int math;int english;int sumg;struct Score *next;};void sort1(Score p[],int n);void output(Score p[],int n);int main(){Score *head=NULL,*p,*q;int i=0,j,m;long asg[200];Score score[200];//以输入的方式(ios::in)打开文件,注意score.txt必须在文件夹中存在ifstream infile("score.txt",ios::in);//测试是否成功打开,打开失败时(如要读的数据文件不存在)退出if(!infile) {cerr<<"open error!"<<endl;exit(1);}while(!infile.eof()){ p=new Score;infile>>p->num>>p->nam>>p->cpp>>p->math>>p->english;p->sumg=p->cpp+p->math+p->english;p->next=NULL;if(i==0)head=p;elseq->next=p;q=p;i++;}infile.close();p=head;asg[0]=head->sumg;for(j=1;j<i;j++)asg[j]=asg[j-1]+score[j].sumg;m=asg[j]/j;cout<<"总分高于平均总分且没有挂科的同学及成绩单:"<<endl;while(p!=NULL){if((p->cpp)>59&&(p->math)>59&&(p->english)>59&&(p->sumg)>m){cout<<p->nam<<" "<<p->cpp<<" "<<p->math<<" "<<p->english<<" "<<p->sumg<<endl;p=p->next;}elsep=p->next;}return 0;}运行结果 :