第十六周任务(二)

#include <fstream>
#include<iostream>
#include<string>
using namespace std;

//定义学生类
class Student
{
public:
	Student(){};
	Student(string nam, double c, double m, double e):name(nam),cpp(c),math(m),english(e){total=c+m+e;}
	void set_value(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_total(){return total;}
	void set_cpp(double c){cpp=c;}
	void set_math(double m){math=m;}
	void set_english(double e){english=e;}
	void set_total(double t){total=t;}
private:
	string name;
	double cpp;
	double math;
	double english;
	double total;
};

void Student::set_value(string nam, double c, double m, double e)
{
	name=nam;
	cpp=c;
	math=m;
	english=e;
	total=c+m+e;
}

int main( )
{
	Student stud[100],t; //stud[100]为保存数据的对象数组
	string name;
	double cpp, math, english;
	int i,j;

	//将文件中的数据读入到对象数组中
	ifstream infile("score.dat",ios::in);  //以输入的方式打开文件
	if(!infile)       //测试是否成功打开
	{
		cerr<<"open error!"<<endl;
		exit(1);
	}
	for(i=0;i<100;i++)
	{
		infile>>name>>cpp>>math>>english;
		stud[i].set_value(name, cpp, math, english);
	}
	infile.close();

	//求各科最高分及总分最高分
	Student max_stud("nobody",0,0,0);  //max_stud是一个不存在的学生,存储最高分
	for(i=0;i<100;i++)
	{
		if(stud[i].get_cpp()>max_stud.get_cpp()) 
			max_stud.set_cpp(stud[i].get_cpp());
		if(stud[i].get_math()>max_stud.get_math()) 
			max_stud.set_math(stud[i].get_math());
		if(stud[i].get_english()>max_stud.get_english()) 
			max_stud.set_english(stud[i].get_english());
		if(stud[i].get_total()>max_stud.get_total()) 
			max_stud.set_total(stud[i].get_total());
	}

	//按总分排序
	for(j=0;j<100-2;j++) 
	{
		for(i=0;i<100-j-1;i++)   
			if (stud[i].get_total()<stud[i+1].get_total()) 
			{
				t=stud[i]; 
				stud[i]=stud[i+1];
				stud[i+1]=t;
			}
	}

	//显示各科及总分的最高分
	cout<<"C++最高分为: "<<max_stud.get_cpp()<<endl;
	cout<<"高等数学最高分为: "<<max_stud.get_math()<<endl;
	cout<<"英语最高分为: "<<max_stud.get_english()<<endl;
	cout<<"总分最高分为: "<<max_stud.get_total()<<endl;

	//将按总分排序后的结果存入文件
	ofstream outfile("ordered_salary.txt",ios::out); 
	if(!outfile)    
	{
		cerr<<"open error!"<<endl;
		exit(1);
	}
	for(i=0;i<100;i++)
	{
		outfile<<stud[i].get_name()<<"\t";
		outfile<<stud[i].get_cpp()<<"\t";
		outfile<<stud[i].get_math()<<"\t";
		outfile<<stud[i].get_english()<<"\t";
		outfile<<stud[i].get_total()<<endl;
	}
	for(i=0;i<100;i++)
	{
		cout<<stud[i].get_name()<<"\t";
		cout<<stud[i].get_cpp()<<"\t";
		cout<<stud[i].get_math()<<"\t";
		cout<<stud[i].get_english()<<"\t";
		cout<<stud[i].get_total()<<endl;
	}
	outfile.close();    
	system("pause");
	return 0;
}
C++最高分为: 100
高等数学最高分为: 100
英语最高分为: 100
总分最高分为: 291
王琦    98      95      98      291
宋宗杰  94      100     92      286
杨阔    90      91      98      279
冼丹    100     89      89      278
范振光  98      87      89      274
魏佳    100     94      80      274
张昊    94      83      96      273
赵旭洋  87      91      94      272
吴清正  89      97      85      271
高举    81      99      91      271
冯松    89      98      83      270
马婧    98      84      87      269
李朋    90      82      97      269
韩明    83      97      88      268
张迪    99      88      80      267
王芳    71      97      99      267
文静    93      88      85      266
王磊    87      86      92      265
刘盈    99      72      93      264
王瑞麒  89      83      91      263
叶丹    87      80      96      263
李桐    93      83      86      262
杨洁    96      79      87      262
董一伟  93      88      80      261
张佳玮  61      98      96      255
杨梦婕  89      99      67      255
刘紫亮  72      98      84      254
刘亚新  77      81      95      253
王蒙    67      97      89      253
黄金龙  85      90      78      253
徐嘉琦  90      75      87      252
王姝    70      91      90      251
崔赞    91      67      93      251
马佳    60      90      100     250
葛志伟  100     79      71      250
张笑    86      88      76      250
王锐    63      90      96      249
张敏    85      75      89      249
裴培    75      82      91      248
冷云    89      88      71      248
宋媛媛  61      94      92      247
张里响  85      65      96      246
马立    73      90      83      246
何煜中  90      73      82      245
王竞    90      87      67      244
梁雅宁  55      88      100     243
高清    76      83      84      243
吴佳林  96      65      82      243
蔺剑飞  88      75      79      242
唐楠    68      97      77      242
宋航彬  80      71      91      242
马里    73      95      73      241
张龙    62      100     78      240
贾伟林  63      90      86      239
李悦    63      79      97      239
周恒    87      82      69      238
鲁继森  84      79      75      238
徐金竹  75      89      73      237
田苗苗  75      91      71      237
佟欣    60      79      98      237
边里    56      94      87      237
陈美珠  82      72      83      237
高路    63      74      98      235
印虹    92      68      75      235
张扬    77      65      93      235
薛淇文  89      71      75      235
于浩    78      84      72      234
刘得意  60      98      75      233
黄京    62      75      96      233
苏明霞  59      79      94      232
张雯    69      70      93      232
孙大伟  65      69      98      232
王欣欣  71      83      78      232
郭倩    69      94      69      232
王悦    79      82      70      231
任盛达  57      86      88      231
杨华鑫  81      81      68      230
贺祺    61      96      72      229
金昕    92      67      69      228
宋静    69      85      73      227
陈世勃  70      92      65      227
王磊    71      78      77      226
方圆    70      79      76      225
汤娜    68      85      71      224
林倩    67      77      80      224
刘京西  67      78      78      223
何佳成  70      75      78      223
兰天    83      66      74      223
杨超    67      73      82      222
周俊升  57      68      96      221
冯佳媛  61      79      81      221
马骁    62      67      90      219
赵媛媛  77      75      66      218
卫青    66      73      77      216
白涛    57      82      75      214
吴玮    69      76      68      213
于莉    55      66      78      199
桂佳    60      73      65      198
徐一菡  85      45      62      192
王欢欢  57      33      66      156
请按任意键继续. . .

感悟:感觉怎么与他越来越远了呢,可以说是无从下手,拿了任务不知道第一步该干什么,尽管看程序能够看懂,自己写就难了呢

迷茫了···唉!但是不会放弃的


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值