首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读下列说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 某学校在学生毕业时要求对其成绩进行综合评定,学生的综合成绩(GPA)由其课程加权平均成绩(Wg)与附加分(Ag)构成,即GPA=Wg+Ag。 设一个
阅读下列说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 某学校在学生毕业时要求对其成绩进行综合评定,学生的综合成绩(GPA)由其课程加权平均成绩(Wg)与附加分(Ag)构成,即GPA=Wg+Ag。 设一个
admin
2013-07-03
19
问题
阅读下列说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。
【说明】
某学校在学生毕业时要求对其成绩进行综合评定,学生的综合成绩(GPA)由其课程加权平均成绩(Wg)与附加分(Ag)构成,即GPA=Wg+Ag。
设一个学生共修了n门课程,则其加权平均成绩(Wg)定义如下:
其中,grade
i
、C
i
分别表示该学生第i门课程的百分制成绩及学分。
学生可以通过参加社会活动或学科竞赛获得附加分(Ag)。学生参加社会活动所得的活动分(Apoints)是直接给出的,而竞赛分(Awards)则由下式计算(一个学生最多可参加m项学科竞赛):
其中,l
i
和S
i
分别表示学生所参加学科竞赛的级别和成绩。
对于社会活动和学科竞赛都不参加的学生,其附加分按活动分为0计算。
下面的程序实现计算学生综合成绩的功能,每个学生的基本信息由抽象类Student描述,包括学号(stuNo)、姓名(name)、课程成绩学分(grades)和综合成绩(GPA)等,参加社会活动的学生由类ActStudent描述,其活动分由Apoints表示,参加学科竞赛的学生由类CmpStudent描述,其各项竞赛的成绩信息由awards表示。
【C++代码】
#include
#include
using namespace std;
const int n=5; /*课程数*/
const int m=2; /*竞赛项目数*/
class Student{
protected:
int stuNo;string name;
double GPA; /*综合成绩*/
int(*grades)[2]; /*各门课程成绩和学分*/
public:
Student(const int stuNo,const string&name,int grades[][2]){
this->stuNo=stuNo;this->name=name;this->grades=grades;
}
Virtual~Student(){}
int getstuNo(){/*实现略*/}
string getName(){/*实现略*/}
(1)
;
double computeWg(){
int totalGrades=0,totalCredits=0:
for(int i=0;i<N;i++){
totalGrades+=grades
[0]*grades
[1];totalGredits+=grades
[1];
}
return GPA=(double)totalGrades/totalCredits;
}
};
class ActStudent;public Student{
int Apoints;
public;
ActStudent(const int stuNo,const string&name,int gs[][2],int Apoints)
:
(2)
{
this->Apoints=Apoints:
}
double getGPA(){return GPA=
(3)
;}
};
class CmpStudent:public Student{
private:
int(*awards)[2];
public:
cmpstudent(const int stuNo,const string&name,int gs[][2],int awards[][2])
:
(4)
{ this->award=award;}
double getGPA()f
int Awards=0;
for(int i=0;i<M;i++){
Awards+=awards
[0]*awards
[1]:
}
Return GPA=
(5)
;
}
};
int main()
{ //以计算3个学生的综合成绩为例进行测试
int g1[][2]={{80,3},{90,2},{95,3},{85,4},{86,3}},
g2[][2]={{60,3},{60,2),{60,3},{60,4},{65,3}},
g3[][2]={{80,3},(90,2},{70,3},{65,4},{75,3}}; //课程成绩
int c3[][2]={{2,3},{3,3)}; //竞赛成绩
Student*student[3]={
new ActStudent(101,”John”,g1,3), //3为活动分
new ActStudent(102,”Zhang”,g2,0),
new ActStudent(103,”Li”,g3,c3),
};
//输出每个学生的综合成绩
for(int i=0;i<3;i++)
cout<<
(6)
<<end1;
delete*student;
return 0;
}
选项
答案
(1)virtual double getGPA()=0 (2)Student(stuNo,name,gs) (3)computeWg()+Apoints或Student::computeWg()+Apoints (4)Student(stuNo,name,gs) (5)computeWg()+Awards或Student::computeWg()+Awards (6)students[i]->getGPA()
解析
本题的程序功能是计算学生的综合成绩(GPA)其中GPA由其课程加权平均成绩Wg与附加分Ag构成,即GPA=Wg+Ag。首先定义了一个getGPA()函数并为函数赋初始为0,(1)填virtual double getGPA()=0,其中virtual是指在windows下C++的开发环境,double定义了GPA的值都为双精度浮点数。(2)是计算学生的活动的附加分,调用Student()函数,括号内的变量用已经定义过的变量名替代,即Student(stuNo,name,gs)。在Student()函数中调用了getGPA函数,引用了题目中给的公式GPA=Wg+Ag,所以(3)应填computeWg()+Apoints。(4)是计算学生竞赛的附加分的函数,其中又调用了一次Student函数,所以同(2)一样填Student(stuNo,name,gs)。(5)同(3)一样,是在Student函数中调用了get-GPA函数,引用了题目中给的公式GPA=Wg+Ag,所以(5)应填computeWg()+Awards,与(3)不同的是,这次Wg加的是竞赛的附加分。(6)是在主函数的for循环里面,由于共有3个学生,所以i的取值范围为0~3,并将students
的值赋值给GPA,所以(6)应填students
->getGPA()。
转载请注明原文地址:https://kaotiyun.com/show/knjZ777K
本试题收录于:
程序员下午应用技术考试题库软考初级分类
0
程序员下午应用技术考试
软考初级
相关试题推荐
某计算机房夏季的环境温度要求控制在28℃至32℃,该范围可简写为______。
在Word2007中,若用户需要将一篇文章中的字符串“Internet”全部替换为字符串“因特网”,则可以在编辑菜单中选择()命令。
某企业长期从事大量的数据处理工作,所建立的一系列规范中一般不包括________。
在Word编辑状态下,有些英文单词或汉字下面会自动加上红色或绿色的波浪型细下划线。以下叙述中,“波浪型细下划线(44)”是错误的。
在Excel2010的A1单元格中输入函数“=IF(1<>2,1,2)”,按回车键后,A1单元格中的值为________________。
某商场记录(统计)销售情况的数据库中,对每一种商品采用了国家统一的商品编码。这种做法的好处不包括(11)________________。
某公司下设4个分公司A、B、C、D,上月各分公司的销售额及其在总公司所占比例如下表所示。由于此表单受潮,有些数据看不清了,但还可以推算出来。根据推算, D公司上月的销售额为(68)万元。
某公司统计一季度考勤情况如下:根据公司规定,凡缺勤不超过2天的人,每人发200元考勤奖;凡缺勤天数超过5天的人,每人每天缺勤从工资中扣50元,用于发放其他人的考勤奖。根据上表,计算该公司还需要拿出(29)元作为一季度的考勤奖。
某Word文档共有100页,现需要打印该文档的第5页到第9页和第12页,在打印对话框中,可输入打印页码()。
该公司用一个C类地址块202.119.110.0/24组网,将下表中的(1)~(6)处空缺的主机地址或子网掩码填写在答题纸的相应位置。可以采用(10)方法防止IP地址被盗用。(10)A.IP地址与子网掩码进行绑定B.IP地址与MAC地址进行
随机试题
消息写作“新”的特点指的是时间上最新发生的事件。
积聚的主要病位在
患儿,女,13岁。不慎服用有机磷农药(对硫磷),予紧急洗胃,则选择的洗胃液是
泥浆护壁成孔过程中,泥浆的作用除了保护孔壁、防止塌孔外,还有()。
纳税人超过应纳税额缴纳的税款,自结算缴纳税款之日起()发现的,可要求退还。
人民币活期存款的起存点为()。
根据会议的主导思想和会议记录,对会议的重要内容、决定事项进行整理、综合、摘要、提高而形成的一种具有纪实性的公文种类为()。
假如一国央行规定的法定准备金率是r=20%,流通中的现金C=3200亿美元,支票存款D=1万亿美元,超额准备金ER=600亿美元。请写出货币乘数的公式。
“多情自古伤离别”的下句是:_______。
"It’snotwhatyouknow,butwhoyouknowthatcounts."Thisoversimplifiedstatementoftenangersthosewhobelievethatal
最新回复
(
0
)