/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.* 文件名称:分数
* 作 者: 郭岩岩
* 完成日期:2012 年6月 12日
* 版 本 号: vc.1
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
*程序头部的注释结束
*/
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Student
{
private:
string name;
int cpp;
int Math;
int English;
int All_score;
double Average;
public:
Student();
Student(int c,int math,int english,int all_score,double average):cpp(c),Math(math),English(english),All_score(all_score),Average(average){}
friend void arrange_all_score(Student stu[]); //排列总成绩
friend void get_frome_file(Student stu[]); //从文件中读入成绩
friend void save_to_file(Student stu[]); //保存到文件中
friend void get_heigh_allscore(Student stu[]); //得到最高分
friend void get_height_Cscore(Student stu[]); //得到最高c++成绩
friend void get_height_Mathscore(Student stu[]); //得到最高高数成绩
friend void get_height_Englishscore(Student stu[]);//得到最高英语成绩
friend void getagain_fome_file(Student stu[]); //再次从文件中读出
};
Student::Student()
{
cpp=0;
Math=0;
English=0;
All_score=0;
Average=0;
}
void arrange_all_score(Student stu[])
{
int i,j;
Student t;
for( j=0;j<100;j++)
{
for( i=0;i<100-j;i++)
if(stu[i].All_score<stu[i+1].All_score)
{
t=stu[i+1];
stu[i+1]=stu[i];
stu[i]=t;
}
}
}
void get_heigh_allscore(Student stu[])
{
Student s;
int i=0;
s.All_score=stu[i].All_score;
for(i=0;i<101;i++)
{
if(stu[i].All_score>s.All_score)
{
s.All_score =stu[i].All_score ;
}
}
cout<<"总分成绩最高为:"<<s.All_score<<endl;
}
void get_height_Cscore(Student stu[])
{
Student s;
int i=0;
s.cpp=stu[i].cpp;
for(i=0;i<101;i++)
{
if(stu[i].cpp>s.cpp)
{
s.cpp=stu[i].cpp;
s.name =stu[i].name ;
}
}
cout<<"C++成绩最高为:"<<s.cpp<<'\t'<<endl;
}
void get_height_Mathscore(Student stu[])
{
Student s;
int i=0;
s.Math=stu[i].Math;
for(i=0;i<101;i++)
{
if(stu[i].Math>s.Math)
{
s.Math =stu[i].Math;
s.name =stu[i].name ;
}
}
cout<<"高数成绩最高为:"<<s.Math<<endl;
}
void get_height_Englishscore(Student stu[])
{
Student s;
int i=0;
s.English=stu[i].English;
for(i=0;i<101;i++)
{
if(stu[i].English>s.English)
{
s.English =stu[i].English;
s.name =stu[i].name ;
}
}
cout<<"英语成绩最高为:"<<s.English<<endl;
}
void get_frome_file(Student stu[])
{
ifstream infile("score.dat",ios::in);
if(!infile)
{
cerr<<"open score.dat error!"<<endl;
exit(1);
}
for(int i=0;i<100;i++)
{
infile>>stu[i].name>>stu[i].cpp>>stu[i].Math>>stu[i].English;
stu[i].Average=(stu[i].cpp+stu[i].Math+stu[i].English)/3;
stu[i].All_score=stu[i].cpp+stu[i].Math+stu[i].English;
}
stu[100].name="郭岩岩";
stu[100].cpp=100;
stu[100].Math=100;
stu[100].English=100;
stu[100].Average =100;
stu[100].All_score =300;
infile.close();
}
void save_to_file(Student stu[])
{
ofstream outfile("binary_score.dat",ios::binary);
if (!outfile)
{
cerr<<"open error!"<<endl;
}
for(int i=0;i<101;i++)
{
outfile.write((char*)&stu[i],sizeof(stu[i]));
}
outfile.close();
}
void getagain_fome_file(Student stu[])
{
ifstream infile("binary_score.dat",ios::binary);
if(!infile)
{
cerr<<"open score.dat error!"<<endl;
exit(1);
}
cout<<"姓名"<<'\t'<<"C++"<<'\t'<<"高数"<<'\t'<<"英语"<<'\t'<<"平均分"<<'\t'<<"总分"<<endl;
for(int i=0;i<101;i++)
{
infile.read((char*)&stu[i],sizeof(stu[i]));
cout<<stu[i].name<<'\t'<<stu[i].cpp<<'\t'<<stu[i].Math<<'\t'<<stu[i].English<<'\t'<<stu[i].Average<<'\t'<<stu[i].All_score<<endl;
}
infile.close();
}
int main()
{
Student stu[101];
get_frome_file(stu); //读入原始文件
arrange_all_score( stu);
get_heigh_allscore(stu);
cout<<endl;
get_height_Cscore( stu);
cout<<endl;
get_height_Mathscore( stu);
cout<<endl;
get_height_Englishscore( stu);
cout<<endl;
cout<<endl;
save_to_file(stu); //保存到文件中
cout<<endl;
getagain_fome_file(stu);
system("pause");
return 0;
}
总分成绩最高为:300
C++成绩最高为:100
高数成绩最高为:100
英语成绩最高为:100
姓名 C++ 高数 英语 平均分 总分
郭岩岩 100 100 100 100 300
王琦 98 95 98 97 291
宋宗杰 94 100 92 95 286
杨阔 90 91 98 93 279
冼丹 100 89 89 92 278
范振光 98 87 89 91 274
魏佳 100 94 80 91 274
张昊 94 83 96 91 273
赵旭洋 87 91 94 90 272
吴清正 89 97 85 90 271
高举 81 99 91 90 271
冯松 89 98 83 90 270
马婧 98 84 87 89 269
李朋 90 82 97 89 269
韩明 83 97 88 89 268
张迪 99 88 80 89 267
王芳 71 97 99 89 267
文静 93 88 85 88 266
王磊 87 86 92 88 265
刘盈 99 72 93 88 264
王瑞麒 89 83 91 87 263
叶丹 87 80 96 87 263
李桐 93 83 86 87 262
杨洁 96 79 87 87 262
董一伟 93 88 80 87 261
张佳玮 61 98 96 85 255
杨梦婕 89 99 67 85 255
刘紫亮 72 98 84 84 254
刘亚新 77 81 95 84 253
王蒙 67 97 89 84 253
黄金龙 85 90 78 84 253
徐嘉琦 90 75 87 84 252
王姝 70 91 90 83 251
崔赞 91 67 93 83 251
马佳 60 90 100 83 250
葛志伟 100 79 71 83 250
张笑 86 88 76 83 250
王锐 63 90 96 83 249
张敏 85 75 89 83 249
裴培 75 82 91 82 248
冷云 89 88 71 82 248
宋媛媛 61 94 92 82 247
张里响 85 65 96 82 246
马立 73 90 83 82 246
何煜中 90 73 82 81 245
王竞 90 87 67 81 244
梁雅宁 55 88 100 81 243
高清 76 83 84 81 243
吴佳林 96 65 82 81 243
蔺剑飞 88 75 79 80 242
唐楠 68 97 77 80 242
宋航彬 80 71 91 80 242
马里 73 95 73 80 241
张龙 62 100 78 80 240
贾伟林 63 90 86 79 239
李悦 63 79 97 79 239
周恒 87 82 69 79 238
鲁继森 84 79 75 79 238
徐金竹 75 89 73 79 237
田苗苗 75 91 71 79 237
佟欣 60 79 98 79 237
边里 56 94 87 79 237
陈美珠 82 72 83 79 237
高路 63 74 98 78 235
印虹 92 68 75 78 235
张扬 77 65 93 78 235
薛淇文 89 71 75 78 235
于浩 78 84 72 78 234
刘得意 60 98 75 77 233
黄京 62 75 96 77 233
苏明霞 59 79 94 77 232
张雯 69 70 93 77 232
孙大伟 65 69 98 77 232
王欣欣 71 83 78 77 232
郭倩 69 94 69 77 232
王悦 79 82 70 77 231
任盛达 57 86 88 77 231
杨华鑫 81 81 68 76 230
贺祺 61 96 72 76 229
金昕 92 67 69 76 228
宋静 69 85 73 75 227
陈世勃 70 92 65 75 227
王磊 71 78 77 75 226
方圆 70 79 76 75 225
汤娜 68 85 71 74 224
林倩 67 77 80 74 224
刘京西 67 78 78 74 223
何佳成 70 75 78 74 223
兰天 83 66 74 74 223
杨超 67 73 82 74 222
周俊升 57 68 96 73 221
冯佳媛 61 79 81 73 221
马骁 62 67 90 73 219
赵媛媛 77 75 66 72 218
卫青 66 73 77 72 216
白涛 57 82 75 71 214
吴玮 69 76 68 71 213
于莉 55 66 78 66 199
桂佳 60 73 65 66 198
徐一菡 85 45 62 64 192
王欢欢 57 33 66 52 156
请按任意键继续. . .