![]() |
#2
糖包包2011-06-15 15:43
|
编写一个程序,用来从键盘读取本班同学的期末成绩,并把该成绩保存在score.dat文件中。
Score.dat文件内容如下:
number Chinese English C
1 87 76 67
2 67 87 65
3 76 88 87
4 46 89 88
我写的

#include <iostream>
#include <fstream>
using namespace std;
void main()
{
ofstream ofile("e:\\score.dat");
if(!ofile)
cout<<"打开的文件是错误的"<<endl;
else
{
ofile<<"number"<<"Chinese"<<"English"<<"C"<<endl;
ofile<<"1"<<"87"<<"76"<<"67"<<endl;
ofile<<"2"<<"67"<<"87"<<"65"<<endl;
ofile<<"3"<<"76"<<"88"<<"87"<<endl;
ofile<<"4"<<"46"<<"89"<<"88"<<endl;
}
}
可是老师说用键盘读取的意思是要用键盘输入成绩再存入文件中!!#include <fstream>
using namespace std;
void main()
{
ofstream ofile("e:\\score.dat");
if(!ofile)
cout<<"打开的文件是错误的"<<endl;
else
{
ofile<<"number"<<"Chinese"<<"English"<<"C"<<endl;
ofile<<"1"<<"87"<<"76"<<"67"<<endl;
ofile<<"2"<<"67"<<"87"<<"65"<<endl;
ofile<<"3"<<"76"<<"88"<<"87"<<endl;
ofile<<"4"<<"46"<<"89"<<"88"<<endl;
}
}

怎么从键盘输入成绩啊,那还有一大堆字母要怎么处理啊.....
还有怎么用这个数据文件计算其平均成绩和期末成绩啊,还要输出成绩不及格的学生的学号!!!这不是太难了嘛!~~~
完全不会,我要崩溃了!!!!