第十六周任务(二)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class student
{
private:
	string name;
	double cpp;
	double math;
	double english;
	double zong;
public:
	student(){};
	student(string nam,double c,double m,double e):name(nam),cpp(c),math(m),english(e){zong=c+m+e;}
	void set(string nam,double c,double m,double e);
    string get_name(){return name;}  
    double get_cpp(){return cpp;}  
    double get_math(){return math;}  
    double get_english(){return english;}  
    double get_zong(){return zong;}  
    void set_cpp(double c){cpp=c;}  
    void set_math(double m){math=m;}  
    void set_english(double e){english=e;}  
    void set_zong(double z){zong=z;}  
};
void student::set(string nam,double c,double m,double e)
{
	name=nam;
	cpp=c;
	math=m;
	english=e;
	zong=c+e+m;
}

int main()
{
	student a[100],t;
	int i,j;
	string Name;
	double Cpp,Math,English;
	ifstream infile("score.dat",ios::in);
	if(!infile)
	{
		cerr<<"open error"<<endl;
		exit(1);
	}
    for(i=0;i<10;i++)
	{
		infile>>Name>>Cpp>>Math>>English;
		a[i].set(Name,Cpp,Math,English);
	}
	infile.close();

    student b("nobody",0,0,0);
	for(i=0;i<100;i++)
	{
		if(a[i].get_cpp()>b.get_cpp())
		{
			b.set_cpp(a[i].get_cpp());
		}
		if(a[i].get_math()>b.get_math())
		{
			b.set_math(a[i].get_math());
		}
		if(a[i].get_english()>b.get_english())
		{
			b.set_english(a[i].get_english());
		}
		if(a[i].get_zong()>b.get_zong())
		{
			b.set_zong(a[i].get_zong());
		}
	}
	for(j=0;j<100-2;j++)
		for(i=0;i<99-j;i++)
			if(a[i].get_zong()>a[i+1].get_zong())
		{
			t=a[i];
			a[i]=a[i+1];
			a[i+1]=t;
		}
    cout<<"C++最高分为: "<<b.get_cpp()<<endl;  
    cout<<"高等数学最高分为: "<<b.get_math()<<endl;  
    cout<<"英语最高分为: "<<b.get_english()<<endl;  
    cout<<"总分最高分为: "<<b.get_zong()<<endl;  
  
ofstream outfile("ordered_salary.txt",ios::out); 
if(!outfile)
{
	cout<<"open error"<<endl;
	exit(1);
}
for(i=0;i<100;i++)
{
	outfile<<a[i].get_name()<<" ";
	outfile<<a[i].get_cpp()<<" ";
	outfile<<a[i].get_math()<<" ";
	outfile<<a[i].get_english()<<" ";
	outfile<<a[i].get_zong()<<endl;
}
   outfile.close();      
   system("pause");  
    return 0;  
}  
C++最高分为: 98
高等数学最高分为: 98
英语最高分为: 96
总分最高分为: 270
请按任意键继续. . .



这次的任务使我认识到自己的不足,并没有真正的掌握所学的的知识,此次任务中所犯的错误就是,忘记了私有成员是无法在主函数中被调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值