首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1。此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正
请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1。此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正
admin
2017-07-04
22
问题
请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1。此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
学号:12345678 课程:英语 总评成绩:85
注意:只修改每个“//ERROR****found****”下的一行,不要改动程序中的其他内容。
#include
using namespace std;
class Score{
public:
Score(const char*the course,
const char*the id,int the normal,
int the midterm,int the end of term)
:course(the course),normal(the
normal),midterm(the midterm),end
of term(the end of term){
//ERROR**********found**********
strcpy(the id,student_id);
}
const char*getCourse()const{return course;)//返回课程名称
//ERROR**********found**********
const char*getID()const{return
&student id;) //返回学号
int getNormal()const { return normal;) //返回平时成绩
int getMidterm()const f return mid
term;}
//返回期中考试成绩
int getEnd0fTerm《)const{return
end_of_term;) //返回期末考试成绩
int getFinal()const;//返回总评成绩
private:
const char*course;//课程名称
char student id[12]; //学号
int normal;//4时成绩
int midterm; //期中考试成绩
int end of term; //期末考试成绩
};
//总评成绩中平时成绩占20%,期中考试占
30%,期末考试占50%,最后结果四舍五入为
一个整数
//ERROR**********found**********
int getFinal()const{
return normal*0.2+midterm*0.3+
end_of_term*0.5+0.5;
}
int main(){
char English[]=”英语”;
Score score(English,”12345678”,
68,83,92);
cout<<”学号:”<
cout<<”课程:”<
<<””;
cout<<”总评成绩:”<
nal()<
return 0;
}
选项
答案
(1)strcpy(student_id,the_id); (2)const char*getID()const{retum student_id;} (3)int Score::getFinal()const{
解析
(1)主要考查考生对strcpy()函数的掌握情况,strcpy(参数一,参数二)函数的功能是将参数二的字符串复制给参数一,因此在这里student_id应该位于参数一的位置,即strcpy(student_id,the_id);。
(2)主要考查考生对函数返回值的掌握情况,根据注释:返回学号可知学号应该由一个字符串组成。再看函数要返回的类型:const char*,可知要返回一个char型指针,也就是一个char型数组,而&student_id是一个char型数组指针,因此直接写student_id即可。
(3)主要考查考生对类的成员函数的掌握情况,因为getFinal函数是Score类的成员函数,所以在定义时要加上类名和作用域符,即Score::。
转载请注明原文地址:https://kaotiyun.com/show/sLAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行完下列语句 int a,b, *c=&a; int * &p=c; p=&b; 后c指向
以下程序的输出结果是 int a, b; void fun() {a=100; b=200; } main() { int a=5, b=7; fun(); cout<<a<<b<<e
若有以下宏定义: # define N 2 # define Y(n) ((N+1)*n) 则执行语句z=2*(N+Y(5));后的结果是
有下列二叉树,对此二叉树前序遍历的结果为( )。
下列程序的执行结果是【 】。#include<iostream.h>classStudent{public:Student(intxx){x=xx;}virtualfloatcalcFuition();protecte
执行语句序列charstrl[10]="ABCD",str2[10]="XYZxyz";for(inti=0;strl[i]=str2[i];i++)后,数组str1中的字符是XYZxyz,数组str2中的字符串是【 】。
在下面程序的横线处填上适当的语句,使该程序执行结果为10。#include<iostream>usingnamespacestd;classMyClass{public:MyClasS(in
定义如下变量和数组:inti;inty[2][3]={2,4,6,8,10,12};则下面语句的输出结果是【】。for(i=0;i<2;i++)cout<<y[1-i)[i+1]<<",";
转义字符序列中的首字符是______字符。
以下选项中合法的用户标识符是
随机试题
()包括对与工作有关的事故、事件,其他损失(如财产损失),不良的职业健康安全绩效和职业健康安全管理体系的失效情况的确认、报告和调查。
OnthefourthThursdayinNovember,AmericanscelebratethefeastofThanksgiving.Thisfeastisatimewhenthefamilycomesto
对破伤风患者的护理正确的是
某患者.右上中切牙金属烤瓷冠修复后。检查:金属烤瓷冠颜色、形态良好,不松动.颈部边缘探针可探入.邻接点牙线可以勉强通过.正中合时右下1切端咬在金属烤瓷冠的瓷面上.此冠为
某宾馆为了8月8日的开业庆典,于8月7日向电视台租借一台摄像机。庆典之日,工作人员不慎摔坏摄像机,宾馆决定按原价买下,以抵偿电视台的损失,遂于8月9日通过电话向电视台负责人表明此意,对方表示同意。8月15日,宾馆依约定向电视台支付了价款。摄像机所有权何时转
2007年1月2日,乙公司涉及一起诉讼案。2007年12月31日,乙公司尚未接到法院的判决。根据公司法律顾问的职业判断,公司认为,胜诉的可能性为40%,败诉的可能性为60%。如果败诉,需要赔偿450~525万元之间,同时还应承担诉讼费3万元。乙公司在资产负
纳税人应当在向公安机关等车辆管理机构(),缴纳车辆购置税。
某单位需要派出下乡扶贫人员1至2人。经过宣传号召,众人纷纷报名。经过一番考虑,领导最后将扶贫人选集中在小王和小张两人身上。大家对最终的挑选结果作了如下猜测:(1)小王会被挑选上。(2)如果小王被挑选上,那么小张就不会被挑选上。
设f(x)在[1,+∞)上有连续的二阶导数,f(1)=0,fˊ(1)=1,且二元函数z=(x2+y2)f(x2+y2)满足,求f(x)在[1,+∞)的最大值
For:【L5】______Blake.From:【L6】______Anderson.Tomorrow’s【L7】______iscancelled.Helen’stelephonenumber:【L8】______.【L8】
最新回复
(
0
)