/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:score.cpp
* 作 者: 李洋
* 完成日期: 2013 年 3 月 13 日
* 版本号: v1.0
* 输入描述:无
* 问题描述:无
* 输出:按总分的排序,以及获奖学金同学的名单
*/
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
struct Score
{
char num[13];
char name[14];
int cpp;
int math;
int english;
int sum;
};
void paixu(Score score[],int n);
void output(Score score[],int n);
void jiangxuejin(Score score[],int n);
int main()
{
int i,j,n=0;
Score score[300];
ifstream infile("score.txt",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
while(!infile.eof())
{
infile>>score[n].num>>score[n].name>>score[n].cpp>>score[n].math>>score[n].english;
++n;
}
infile.close();
paixu(score,n);
output(score,n);
jiangxuejin(score,n);
return 0;
}
void paixu(Score score[],int n)
{
int i,j;
Score t;
for(i=0;i<n;++i)
{
score[i].sum=score[i].cpp+score[i].math+score[i].english;
}
for(j=1;j<n;++j)
{
for(i=0;i<=n-j-1;++i)
if(score[i].sum<score[i+1].sum)
{
t=score[i];
score[i]=score[i+1];
score[i+1]=t;
}
}
}
void jiangxuejin(Score score[],int n)
{
int i,j=0;
cout<<"获得奖学金的同学有:"<<endl;
for(i=0;i<n;++i)
{
if(j<30)
{
if(score[i].cpp>=60&&score[i].math>=60&&score[i].english>=60)
{
cout<<setw(8)<<score[i].name;
j=j+1;
}
}
else
{
break;
}
}
cout<<endl;
}
void output(Score score[],int n)
{
int i;
for(i=1;i<n;i++)
{
cout<<score[i].num<<" "<<score[i].name<<" "<<score[i].cpp<<" "<<score[i].math<<" "<<score[i].english<<" "<<score[i].sum<<endl;
}
}