/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者:雷恒鑫
* 完成日期:2012 年06 月 07 日
* 版 本 号:V1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
#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';
}
运行结果:
分享到:
相关推荐
(0-255)十进制-二进制-八进制-十六进制对照表,(0-255)十进制-二进制-八进制-十六进制对照表,(0-255)十进制-二进制-八进制-十六进制对照表
到此这篇关于Linux bash:./xxx:无法执行二进制文件报错的文章就介绍到这了,更多相关Linux 无法执行二进制文件 内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!...
VB--十进制-八进制-十六进制-二进制相互转换大全.doc
1:本程序读取二进制文件,并把读到的二进制文件保存为文本数据 2:二进制文件内容一系列的三维点云数据,由扫描仪器扫描获得 3:本程序采用了多线程技术,读取二进制文件时,界面不会卡顿 4:实例二进制文件为data....
MySQL二进制文件开启及查看详解,就解释了如何分析日志文件 .
C语言-顺序栈实现十进制转换为二进制-八进制-十六进制
学习目标 1、学习二进制、十进制、十六进制的特点、表示方式 2、学习二进制的状态表示 3、学习二进制、十六进制转换为十进制的方法 单片机-进制-PPT全文共63页,当前为第2页。 1、计算机的数制有哪些 2、十进制、二...
CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二进制安装mysql5.7、CentOS-二...
该文件为docker-compose的二进制文件,解压之后就能放到/usr/bin/下就能直接使用。
将任意指定的文件,以二进制的方式,指定区间进行切割。 可以将HTTP的请求图片、视频导出 可以去除文本文件BOM头 可以提取文件中间的乱码字节
自己写的关于将二进制文件转换为十六进制并显示的小工具,也可以保存为文本文件。
打开任何文件,转化为二进制保存;读取二进制文件,另存文件.
将文件以二进制流的格式写入数据库:首先获得文件路径,然后将文件以二进制读出保存在一个二进制数组中具体请祥看本文,希望对你有所帮助
ASCII表(十进制-十六进制-二进制-字符)[归纳].pdf
一个很有用的工具,可以将二进制文件转换为文本文件
将内容为十六进制的文本文件转换成二进制内容的bin文件
Binary Viewer二进制文件读取软件,可读取二进制的语音数据,图像数据,从而分析音频或者图像存储的二进制信息
vb2005案例-二进制文件的读写操作vb2005案例-二进制文件的读写操作
支持16进制,10进制,二进制,8进制查看。 可自定义列数,独特码查找、不定帧长查看。方便数据帧分析。 免安装。 使用时可能需要先使用管理员权限启动。 注意事项: 1,一定要解压出来再用。 2,默认需要先打开bes,...
minio 的二进制 可执行文件,适用于linux系统,加权限带参数执行即可