data.txt的文档格式:
10001111 Fiong Charles 68 67 49 78 89
10003333 Wong Benny 88 90 91 93 99
我写了一段代码,可是不知道为什么average文件里面的数据都是0和空格(如:0 0000000)
#include
#include
char name1,name2;
long POF;
int no;
double mark1,mark2,mark3,mark4,mark5,average;
void read(int no,char name1,char name2,double mark1,double mark2,double mark3,double mark4,double mark5);
double cal(double mark1,double mark2,double mark3,double mark4,double mark5,double average);
long pof(double average,long POF);
void out(int no,char name1,char name2,double mark1,double mark2,double mark3,double mark4,double mark5,double average,long POF);
using namespace std;
int main ()
{
read(no,name1,name2,mark1,mark2,mark3,mark4,mark5);
cal(mark1,mark2,mark3,mark4,mark5,average);
pof(average,POF);
out(no,name1,name2,mark1,mark2,mark3,mark4,mark5,average,POF);
}
void read(int no,char name1,char name2,double mark1,double mark2,double mark3,double mark4,double mark5)
{
ifstream inStream;
inStream.open("data.txt");
inStream>>no>>name1>>name2>>mark1>>mark2>>mark3>>mark4>>mark5;
inStream.close();
}
double cal(double mark1,double mark2,double mark3,double mark4,double mark5,double average)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
average=(mark1+mark2+mark3+mark4+mark5)/5;
return (average);
}
long pof(double average,long POF)
{
if (average>=50)
POF='Pass';
else if (average<50)
POF='Fail';
return (POF);
}
void out(int no,char name1,char name2,double mark1,double mark2,double mark3,double mark4,double mark5,double average,long POF)
{
ofstream outStream;
outStream.open("average.txt");
outStream<<no<<name1<<name2<<mark1<<mark2<<mark3<<mark4<<mark5<<average<<POF<<endl;
outStream.close();
}
[此贴子已经被作者于2007-11-18 13:26:44编辑过]