关键词:写代码
内容:读取成绩文件
A今日完成情况
1.读取成绩文件100%
内容:读取成绩文件
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继续写