学会链表
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct Student
{
char num[12];
string name;
float score1;
float score2;
float score3;
float score;
struct Student *next;
};
int main( )
{
Student *head=NULL, *p, *q;
//下面的程序建立起一个有三个节点的动态链表
int i;
float s=0;
ifstream infile("score.txt",ios::in);
if (!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
for(i=0;i<180;i++)
{
p = new Student ;
infile >> p -> num >> p -> name >> p -> score1 >> p -> score2 >> p -> score3;
p -> score = p -> score1 + p -> score2 + p -> score3;
s=s+p->score;
p->next=NULL;
if (i==0)
head=p;
else
q->next=p;
q=p;
}
infile.close();
s = s/180.0;
//输出所有的节点
p = head;
while(p != NULL)
{
if(p->score >= s)
cout<<p->num<<'\t'<<p->name <<'\t'<<p->score<<endl;
p=p->next;
}
return 0;
}
