01./*
02.* 程序的版权和版本声明部分
03.* Copyright (c)2013, 烟台大学计算机学院学生
04.* All rightsreserved.
05.* 文件名称:lianbiao .cpp
06.* 作 者:赵冠哲
07.* 完成日期:2012年3月13日
08.* 版本号: v1.0
09.* 输入描述:
10.* 问题描述:
11.*/
#include <fstream>
#include <iostream>
using namespace std;
struct Student
{
char num[14];
char name[14];
int cpp;
int math;
int english;
int total;
struct Student *next;
};
int main( )
{
int stuNum=0;
int sum=0;
int aver,i;
Student *head=NULL,*p,*q;
ifstream infile("score.txt",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
stuNum=0;
while(!infile.eof())
{
p = new Student;
infile>>p->num>>p->name>>p->cpp>>p->math>>p->english;
p->total = p->cpp + p->math + p->english;
sum=sum+p->total;
p->next=NULL;
if (stuNum==0)
head=p;
else
q->next=p;
++stuNum;
q=p;
}
infile.close();
aver=sum/stuNum;
cout<<"总分平均为:"<<aver<<endl;
cout<<"总分高于平均总分且没有挂科的同学有:"<<endl;
p=head;
i=1;
while(p!=NULL)
{
if(p->total>=aver&&p->cpp>=60&&p->math>=60&&p->english>=60)
{
cout<<i<<" "<<p->num<<" "<<p->name<<" "<<p->total<<endl;
i++;
}
p=p->next;
}
return 0;
}
运行结果: