| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:[求助]初学C++的作业题,求帮排下错及优化--
只看楼主 加入收藏
jiruanl062
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-11-6
收藏
 问题点数:0 回复次数:3 
[求助]初学C++的作业题,求帮排下错及优化--

#include <iostream>
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& thestudent);

char grade(double score);


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

double score(Studentrecord& thestudent)
{
int rate1=50,rate2=25;
double percent1,percent2;
percent1=rate1/100;
percent2=rate2/100;
return(score=(Studentrecord.s_t)*percent1+(Studentrecord.s_m)*percent2+(Studentrecord.s_1+Studentrecord.s_2)*5*percent2);
}
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;
char ans;
do
{
get_input(student);
score1=score(student);
grade1=grade(score);

cout<<score1<<endl;
cout<<grade1<<endl;
cin>>ans;
}while(ans=='y'||ans=='Y');

return 0;
}

搜索更多相关主题的帖子: 作业 初学 
2007-11-09 21:47
海子星竹
Rank: 1
等 级:新手上路
威 望:1
帖 子:58
专家分:0
注 册:2007-9-4
收藏
得分:0 
#include <iostream>
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& thestudent);

char grade(double score);


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

double score(Studentrecord& thestudent)
{
int 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
{
get_input(student);
score1 = score(student);
grade1 = grade(score1);

cout<<score1<<endl;
cout<<grade1<<endl;
cin>>ans;
}while(ans=='y'||ans=='Y');

return 0;
}

2007-11-09 22:02
jiruanl062
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-11-6
收藏
得分:0 

语法没错了
但是--结果计算不对……

2007-11-09 22:38
jiruanl062
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-11-6
收藏
得分:0 
double score(Studentrecord& thestudent)
{
int 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;


这里有问题……
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);


知道了 写到头晕那么简单的错都看不出来了
谢谢咯
2007-11-09 22:52
快速回复:[求助]初学C++的作业题,求帮排下错及优化--
数据加载中...
 
   



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

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