| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 326 人关注过本帖
标题:[求助]小问题
只看楼主 加入收藏
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
快速回复:[求助]小问题
数据加载中...
 
   



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

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