标题:[求助]小问题
取消只看楼主
jiruanl062
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-11-6
 问题点数:0 回复次数:0 
[求助]小问题

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

struct Studentrecord
{
int student_number;
int s_1,s_2,s_m,s_t;
char grade;
};
void get_input(Studentrecord& the_student);

double score(Studentrecord& the_student);

char grade(double score);


void get_input(Studentrecord& the_student)
{
cout<<"student_number"<<endl;
cin>>the_student.student_number;
cout<<"s_1"<<endl;
cin>>the_student.s_1;
cout<<"s_2"<<endl;
cin>>the_student.s_2;
cout<<"s_m"<<endl;
cin>>the_student.s_m;
cout<<"s_t"<<endl;
cin>>the_student.s_t;
}

double score(Studentrecord& thestudent)
{
double rate1=50,rate2=25;
double percent1,percent2;
percent1=rate1/100;
percent2=rate2/100;
return((thestudent.s_t)*percent1+(thestudent.s_m)*percent2+(thestudent.s_1+thestudent.s_2)*5*percent2);
// return score;
}
char grade(double score)
{
if(score>=90) return 'A';
else if(score>=80) return 'B';
else if(score>=70) return 'C';
else if(score>=60) return 'D';
else return 'F';
}

int main()
{
Studentrecord student;
double score1;
char grade1;
char ans;
do
{ ofstream fout;
ifstream fin;

fin.open("student.dat");
fout.open("student.dat",ios::app);
if(fout.fail())
{
cout<<"----------"<<endl;
exit(1);
}

double next,sum=0;
double average;
int count=0;
while(fin>>next)
{
sum=sum+next;
count++;
}
average=sum/count;

get_input(student);
score1 = score(student);
grade1 = grade(score1);

fout<<setw(2)<<score1;
cout<<score1<<endl;
cout<<grade1<<endl;
cout<<"the average is:"<<average<<endl;

cin>>ans;


fin.close();
fout.close();

}while(ans=='y'||ans=='Y');


return 0;
}

帮忙解决下
怎么样可以使得打开的文件内容为空值的话怎么让
average=sum/count;
不执行

搜索更多相关主题的帖子: include double 
2007-11-10 00:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-184951-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.480487 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved