1613-3-傅溥衍 总结《2016年12月22日》【连续第八十三天总结】

关键词:写代码
内容:读取成绩文件
A今日完成情况
1.读取成绩文件100%

B具体内容

读取成绩文件

#include<iostream>
#include<fstream>
using namespace std;
float getscore(string filename,int stdno){
	int stdno_temp;
	float score;
	ifstream in(filename.c_str());   //打开成绩文件
	if(!in){   //判断文件是否打开正确
	cout<<"文件打开错误" <<endl;
	return 0; 
	} 
}

bool flag=false;
while(in){
	in>>stdno_temp>>score;
	if(in){
		if(stdno_temp==stdno){
			flag=true;
			break;
		}
	}
}
if(!flag){
	score=0;
}
ostream&operator<<(ostream&out,Student&student)
{
	out<<student.no<<'\t'<<student.name<<
	'\t'<<student.classname;
	out<<'\t'<<student.math;
	out<<'\t'<<student.english;
	out<<'\t'<<student.computer;
	out<<'\t'<<student.average;
	out<<endl; 
}

int main()
{
	ifstream in("info.txt");   //学生信息文件 
	ofstream out("student.txt");  //学生完整信息文件
	if(!in||!out){
		cout<<"文件打开错误"<<endl;
		return 1;
	} 
	out<<"学号\t\t姓名\t班级\t高数\t英语\t计算机\t平均"<<endl;
	while(in){
		Student student;
		in>>student.no>>student.name>>student.classname;
		if(!in){
			break;
		}
		student.math=getscore("math.txt",student.no);
		student.english=getscore("english.txt",student.no);
		student.computer=getscore("computer.txt",student.no);
		student.average=(student.math+student.english+student.computer)/3;
		out<<student;
		out.close();
		in.close();
		cout<<"建立成功"<<endl;
			}
			return 1;
}


C明日计划
A继续写



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值