2013第2週上機任務項目4(ダイナミックチェーンテーブル初試験)

2511 ワード

 
 

 

/* 
* Copyright (c) 2013,                               
* All rights reserved.                     
*     :test.cpp                     
*   :                       
*     :2013  3 11                      
*    :v1.0                   
*                     
*     :                      
*     :            ,          ;        ,     。                  
*     :
*     :                    
*     :                      
*/         
#include  <iostream>
#include  <fstream>
using namespace std;
struct Student
{
    char num[13]; 
    char name[10]; 
    int cpp;
    int math;
    int english;
    int grade;
    struct Student *next;   //         
};
int main( )
{
    Student *head=NULL,*p,*q;
    int stuNum=0,i=1;
    int sum=0,ave;   //     
    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->grade = p->cpp + p->math + p->english;
        sum+=p->grade;
        p->next=NULL;
        if (stuNum==0)
            head=p;   //      
        else
            q->next=p;   // q         ,      ,  q     
        ++stuNum;
        q=p;
    }
    infile.close();
    //     
    ave=sum/stuNum;
    cout<<"     :"<<ave<<endl;
    //                         、  、  。
    cout<<"                 :"<<endl;
    p=head;
    while(p!=NULL)
    {
        if(p->grade>=ave&&p->cpp>=60&&p->math>=60&&p->english>=60)
        {
            cout<<i<<" "<<p->num<<" "<<p->name<<" "<<p->grade<<endl;
            i++;
        }
        p=p->next;
    }
    return 0;
}