* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:词典* 作 者: 任小宁
* 完成日期: 2012 年 6月11日
* 版 本 号: 201158504431
* 对任务及求解方法的描述部
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
class Student
{
public:
Student();
Student(string name,int C_plus_plus,int Math,int English,int All_score,double Average);
void set_name(string name);
void set_C_plus_plus(int C_plus_plus);
void set_Math(int Math);
void set_English(int English);
void set_All_score(int All_score);
void set_Average(double Average);
string get_name();
int get_C_plus_plus();
int get_Math();
int get_English();
int get_All_score();
double get_Average();
friend void high_C_plus_plus_score(Student s[]);
friend void high_Math_score(Student s[]) ;
friend void high_English_score(Student s[]);
friend void high_All_score(Student s[]);
friend void Descending_order(Student s[]);//排序,降序;
friend void All_score(Student s[]);
friend void Average_score(Student s[]);
friend ostream& operator << (ostream&,Student&); //重载流插入运算符“<<” ;
friend void insert_data(Student s[]);
friend void check_data();
private:
string name;
int C_plus_plus;
int Math;
int English;
int All_score;
double Average;
};
void input_student(Student s[]);
void ordered_student_dat(Student s[]);
int main()
{
Student s1[101],s2,s3[1];
input_student(s1);//读入100人的原始分数
//ordered_student_dat(s1);
insert_data(s1);
All_score(s1);
Average_score(s1);
cout<<"C++的最高分为:";
high_C_plus_plus_score(s1);
cout<<endl;
cout<<"高数的最高分为:";
high_Math_score(s1);
cout<<endl;
cout<<"英语的最高分为:";
high_English_score(s1);
cout<<endl;
cout<<"总分的最高分为:";
high_All_score(s1);
cout<<endl;
Descending_order(s1);
ordered_student_dat(s1);
check_data();
cout<<endl;
system("PAUSE");
return 0;
}
Student::Student()
{
name="unknow";
C_plus_plus=0;
Math=0;
English=0;
All_score=0;
Average=0.0;
}
Student::Student(string name,int C_plus_plus,int Math,int English,int All_score,double Average)
{
this->name=name;
this->C_plus_plus=C_plus_plus;
this->Math=Math;
this->English=English;
this->All_score=All_score;
this->Average=Average;
}
void input_student(Student s[])
{
int i=0;
string name;
int C_plus_plus;
int Math;
int English;
ifstream infile("score.dat",ios::in);
if (!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
for (i=0;i<101;i++)
{
infile>>name;
s[i].set_name(name);
infile>>C_plus_plus;
s[i].set_C_plus_plus(C_plus_plus);
infile>>Math;
s[i].set_Math(Math);
infile>>English;
s[i].set_English(English);
}
infile.close();
//cout<<endl;
}
void ordered_student_dat(Student s[])
{
ofstream outfile("binary_score.dat",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
// outfile<<'\t'<<"\t"<<"\t"<<"\t"<<"姓名"<<'\t'<<'\t'<<"\t"<<"C++"<<"\t"<<"英语"<<"\t"<<"高数"<<"\t"<<"总分"<<"\t"<<"平均分"<<'\n'<<'\n';
for(int i=0;i<101;i++)
outfile<<'\t'<<"\t"<<"\t"<<"\t"<<s[i].get_name()<<'\t'<<'\t'<<"\t"<<s[i].get_C_plus_plus()<<"\t"<<s[i].get_Math()<<"\t"<<s[i].get_English()<<"\t"<<s[i].get_All_score()<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<s[i].get_Average()<<'\n';
outfile.close();
return ;
}
void Student::set_name(string name)
{
this->name=name;
}
void Student::set_C_plus_plus(int C_plus_plus)
{
this->C_plus_plus=C_plus_plus;
}
void Student::set_Math(int Math)
{
this->Math=Math;
}
void Student::set_English(int English)
{
this->English=English;
}
void Student::set_All_score(int All_score)
{
this->All_score=All_score;
}
void Student::set_Average(double Average)
{
this->Average=Average;
}
string Student::get_name()
{
return name;
}
int Student::get_C_plus_plus()
{
return C_plus_plus;
}
int Student::get_Math()
{
return Math;
}
int Student::get_English()
{
return English;
}
int Student::get_All_score()
{
return All_score;
}
double Student::get_Average()
{
return Average;
}
void high_C_plus_plus_score(Student s[])
{
Student student;
int score;
int i=0,j=0;
string name;
score=s[i].get_C_plus_plus();
student.set_C_plus_plus(score);
for(i=0;i<100;++i)
{
if(student.get_C_plus_plus()<s[i+1].get_C_plus_plus())
{
score=s[i+1].get_C_plus_plus();
student.set_C_plus_plus(score);
name=s[i+1].get_name();
student.set_name(name);
}
}
cout<<student.get_C_plus_plus()<<'\n';
cout<<endl;
cout<<"获得C++最高分的这几名同学叫:";
for(i=0;i<101;++i)
{
if(student.get_C_plus_plus()==s[i].get_C_plus_plus())
cout<<s[i].get_name()<<'\t';
}
cout<<'\n';
return ;
}
void high_Math_score(Student s[])
{
Student student;
int score,i=0;
string name;
score=s[i].get_Math();
student.set_Math(score);
for(i=0;i<100;++i)
{
if(student.get_Math()<s[i+1].get_Math())
{
score=s[i+1].get_Math();
student.set_Math(score);
name=s[i+1].get_name();
student.set_name(name);
}
}
cout<<student.get_Math()<<'\n';
cout<<endl;
cout<<"获得高数最高分的这几名同学叫:";
for(i=0;i<101;++i)
{
if(student.get_Math()==s[i].get_Math())
cout<<s[i].get_name()<<'\t';
}
cout<<'\n';
return ;
}
void high_English_score(Student s[])
{
Student student;
int score,i=0;
string name;
score=s[i+1].get_English();
student.set_English(score);
for(i=0;i<100;++i)
{
if(student.get_English()<s[i+1].get_English())
{
score=s[i+1].get_English();
student.set_English(score);
name=s[i+1].get_name();
student.set_name(name);
}
}
cout<<student.get_English()<<'\n';
cout<<endl;
cout<<"获得英语最高分的这几名同学叫:";
for(i=0;i<101;++i)
{
if(student.get_English()==s[i].get_English())
cout<<s[i].get_name()<<'\t';
}
cout<<'\n';
return ;
}
void high_All_score(Student s[])
{
Student student;
int score,i=0;
string name;
score=s[i].get_All_score();
student.set_All_score(score);
for(i=0;i<100;++i)
{
if(student.get_All_score()<s[i+1].get_All_score())
{
score=s[i+1].get_All_score();
student.set_All_score(score);
name=s[i+1].get_name();
student.set_name(name);
}
}
cout<<student.get_All_score()<<'\n';
cout<<endl;
cout<<"获得总分最高分的这几名同学叫:";
for(i=0;i<101;++i)
{
if(student.get_All_score()==s[i].get_All_score())
cout<<s[i].get_name()<<'\t';
}
cout<<'\n';
return ;
}
void Descending_order(Student s[])
{
Student student;
string name;
int i,j;
for(i=0;i<101-1;i++)
{
for(j=0;j<101-i-1;j++)
{
if(s[j].get_All_score()<s[j+1].get_All_score())
{
student=s[j+1];
s[j+1]=s[j];
s[j]=student;
}
}
}
/*for (i=0;i<101;i++)
{
cout<<s[i].get_All_score()<<" ";
} */
}
void All_score(Student s[])
{
int score;
for(int i=0;i<101;++i)
{
score=s[i].get_C_plus_plus()+s[i].get_Math()+s[i].get_English();
s[i].set_All_score(score);
}
}
void Average_score(Student s[])
{
double average;
for(int i=0;i<101;++i)
{
average=double(s[i].get_C_plus_plus()+s[i].get_Math()+s[i].get_English())/3;
s[i].set_Average(average);
}
}
ostream& operator << (ostream&output,Student&s)
{
if(s.get_C_plus_plus()!=0)
{
output<<s.get_C_plus_plus()<<'\t'<<"该同学名叫:"<<s.get_name()<<endl;
}
else if(s.get_Math()!=0)
{
output<<s.get_Math()<<'\t'<<"该同学名叫:"<<s.get_name()<<endl;
}
else if(s.get_English()!=0)
{
output<<s.get_English()<<'\t'<<"该同学名叫:"<<s.get_name()<<endl;
}
else
{
output<<s.get_All_score()<<'\t'<<"该同学名叫:"<<s.get_name()<<endl;
}
return output;
}
void insert_data(Student s[])
{
string name;
int C_plus_plus;
int Math;
int English;
cout<<"请输入您的姓名,C++成绩,高数成绩和英语成绩,中间以空格顿开:"<<'\n';
cin>>name>>C_plus_plus>>Math>>English;
s[100].set_name(name);
s[100].set_C_plus_plus(C_plus_plus);
s[100].set_Math(Math);
s[100].set_English(English);
cout<<endl;
/*-ifstream outfile("binary_score.dat",ios::in|ios::binary);//|ios::binary
if(!outfile)
{
cerr<<"open error!"<<endl;
abort( );
}
outfile<<s[100].get_name()<<s[100].get_C_plus_plus()<<s[100].get_Math()<<s[100].get_English();
outfile.close();*/
}
void check_data()
{
Student s[107];
int i=0;
string name,str[6];
int C_plus_plus;
int Math;
int English;
int All_score;
double Average;
ifstream infile("binary_score.dat",ios::in);
if (!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
/* for (i=0;i<6;i++)
{
infile>>str[i];
}*/
for (i=0;i<107;i++)
{
infile>>name;
s[i].set_name(name);
infile>>C_plus_plus;
s[i].set_C_plus_plus(C_plus_plus);
infile>>Math;
s[i].set_Math(Math);
infile>>English;
s[i].set_English(English);
infile>>All_score;
s[i].set_All_score(All_score);
infile>>Average;
s[i].set_Average(Average);
}
infile.close();
/* for (i=0;i<6;i++)
{
cout<<str[i];
}*/
cout<<s[0].get_name()<<"\t"<<s[0].get_C_plus_plus()<<"\t"<<s[0].get_Math()<<"\t"<<s[0].get_English()<<"\t"<<s[0].get_All_score()<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<s[0].get_Average()<<'\n';
for(i=1;i<101;i++)
cout<<s[i].get_name()<<'\t'<<"\t"<<s[i].get_C_plus_plus()<<"\t"<<s[i].get_Math()<<"\t"<<s[i].get_English()<<"\t"<<s[i].get_All_score()<<"\t"<<setiosflags(ios::fixed)<<setprecision(2)<<s[i].get_Average()<<'\n';
}
获得C++最高分的这几名同学叫:葛志伟 魏佳 冼丹 任小宁
高数的最高分为:100
获得高数最高分的这几名同学叫:宋宗杰 张龙 任小宁
英语的最高分为:100
获得英语最高分的这几名同学叫:马佳 梁雅宁 任小宁
总分的最高分为:300
获得总分最高分的这几名同学叫:任小宁
任小宁 100 100 100 300 100.00
王琦 98 95 98 291 97.00
宋宗杰 94 100 92 286 95.33
杨阔 90 91 98 279 93.00
冼丹 100 89 89 278 92.67
范振光 98 87 89 274 91.33
魏佳 100 94 80 274 91.33
张昊 94 83 96 273 91.00
赵旭洋 87 91 94 272 90.67
吴清正 89 97 85 271 90.33
高举 81 99 91 271 90.33
冯松 89 98 83 270 90.00
马婧 98 84 87 269 89.67
李朋 90 82 97 269 89.67
韩明 83 97 88 268 89.33
张迪 99 88 80 267 89.00
王芳 71 97 99 267 89.00
文静 93 88 85 266 88.67
王磊 87 86 92 265 88.33
刘盈 99 72 93 264 88.00
王瑞麒 89 83 91 263 87.67
叶丹 87 80 96 263 87.67
李桐 93 83 86 262 87.33
杨洁 96 79 87 262 87.33
董一伟 93 88 80 261 87.00
张佳玮 61 98 96 255 85.00
杨梦婕 89 99 67 255 85.00
刘紫亮 72 98 84 254 84.67
刘亚新 77 81 95 253 84.33
王蒙 67 97 89 253 84.33
黄金龙 85 90 78 253 84.33
徐嘉琦 90 75 87 252 84.00
王姝 70 91 90 251 83.67
崔赞 91 67 93 251 83.67
马佳 60 90 100 250 83.33
葛志伟 100 79 71 250 83.33
张笑 86 88 76 250 83.33
王锐 63 90 96 249 83.00
张敏 85 75 89 249 83.00
裴培 75 82 91 248 82.67
冷云 89 88 71 248 82.67
宋媛媛 61 94 92 247 82.33
张里响 85 65 96 246 82.00
马立 73 90 83 246 82.00
何煜中 90 73 82 245 81.67
王竞 90 87 67 244 81.33
梁雅宁 55 88 100 243 81.00
高清 76 83 84 243 81.00
吴佳林 96 65 82 243 81.00
蔺剑飞 88 75 79 242 80.67
唐楠 68 97 77 242 80.67
宋航彬 80 71 91 242 80.67
马里 73 95 73 241 80.33
张龙 62 100 78 240 80.00
贾伟林 63 90 86 239 79.67
李悦 63 79 97 239 79.67
周恒 87 82 69 238 79.33
鲁继森 84 79 75 238 79.33
徐金竹 75 89 73 237 79.00
田苗苗 75 91 71 237 79.00
佟欣 60 79 98 237 79.00
边里 56 94 87 237 79.00
陈美珠 82 72 83 237 79.00
高路 63 74 98 235 78.33
印虹 92 68 75 235 78.33
张扬 77 65 93 235 78.33
薛淇文 89 71 75 235 78.33
于浩 78 84 72 234 78.00
刘得意 60 98 75 233 77.67
黄京 62 75 96 233 77.67
苏明霞 59 79 94 232 77.33
张雯 69 70 93 232 77.33
孙大伟 65 69 98 232 77.33
王欣欣 71 83 78 232 77.33
郭倩 69 94 69 232 77.33
王悦 79 82 70 231 77.00
任盛达 57 86 88 231 77.00
杨华鑫 81 81 68 230 76.67
贺祺 61 96 72 229 76.33
金昕 92 67 69 228 76.00
宋静 69 85 73 227 75.67
陈世勃 70 92 65 227 75.67
王磊 71 78 77 226 75.33
方圆 70 79 76 225 75.00
汤娜 68 85 71 224 74.67
林倩 67 77 80 224 74.67
刘京西 67 78 78 223 74.33
何佳成 70 75 78 223 74.33
兰天 83 66 74 223 74.33
杨超 67 73 82 222 74.00
周俊升 57 68 96 221 73.67
冯佳媛 61 79 81 221 73.67
马骁 62 67 90 219 73.00
赵媛媛 77 75 66 218 72.67
卫青 66 73 77 216 72.00
白涛 57 82 75 214 71.33
吴玮 69 76 68 213 71.00
于莉 55 66 78 199 66.33
桂佳 60 73 65 198 66.00
徐一菡 85 45 62 192 64.00
王欢欢 57 33 66 156 52.00
请按任意键继续. . .