首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两
请打开考生文件夹下的解决方案文件proj2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两
admin
2020-04-07
45
问题
请打开考生文件夹下的解决方案文件proj2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
改换教室前:
学号:0789姓名:张三班级:062113教室:521
学号:0513姓名:李四班级:062113教室:521
改换教室后:
学号:0789姓名:张三班级:062113教室:311
学号:0513姓名:李四班级:062113教室:311
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class Class{ //“班级”类
public:
Class(const char * id,const char * Eoom){
strcpy(class id,id);
//**********found**********
_____________
}
const char * getClassTD()const { return class_id; } //返回班号
//**********found**********
const char * getClassEoom()const{________} //返回所在教室房号
void changeRoomTo(const char* new_Eoom) { //改换到另一个指定房号的教室
strcpy(classroom,new_room);
}
private:
char class_id[20]; //班号
char classroom[20]; //所在教室房号
};
class Student{ //“学生”类
char my_id[10]; //学号
char my_name[20];//姓名
Class &my_class; / /所在教室
public:
//**********found**********
Student(const char * the_id,const char * the_name,Class&the_class):__________{
strcpy(my_id,the_id);
strcpy(my_name,the_name);
}
const char * getID()const{return my_id;}
const char * getName()const{return my_name;}
Class getClass()const{return my_class;}
};
void showStudent ( Student * stu){
cout<<"学号:"<<stu->getID()<<" ";
cout<<"姓名:"<<stu->getName()<<" ";
cout<<"班级:"<<stu->getClass().getClasSID()<<"";
cout<<"教室:"<<stu->getClass().getClassroom() <<endl;
}
int main(){
ClasS cla("062113","521");
Student Zhang("0789","张三",cla),Li("0513","李四",cla);
cout<<"改换教室前:"<<endl;
showStudent(&Zhang);
showStudent(&Li);
//062113班的教室由521改换到311
//********** found **********
________
cout<<"改换教室后:"<<endl;
showStudent(&Zhang);
showStudent(&Li);
return 0;
}
选项
答案
(1)strcpy(classroom,room); (2)return classroom; (3)my_class(the_class) (4)cla.changeRoomTo("311");
解析
(1)主要考查考生对strcpy函数的掌握情况,根据上一条语句:strcpy(class_id,id);可知,这条语句要复制字符串room,因此使用strcpy函数复制,即strcpy(classroom,room);。
(2)主要考查考生对函数返回值的掌握情况,根据函数要求:返回所在教室房号及函数要求返回的类型为const char * ,可以得出这里直接使用return语句返回classroom即可。
(3)主要考查考生对构造函数的掌握情况,先看函数体中:
strcpy(my_id,the_id);
strcpy(my_name,the_name):
可知只有参数Class &the_class未使用,因此在这里使用成员列表初始化给my_class赋初始值。
(4)主要考查考生对成员函数调用的掌握,程序要求052113班的教室由521改换到311。在类Class中已经定义了函数:void changeRoomTo(const char * new_room),因此直接调用函数changeRoomTo即可。
转载请注明原文地址:https://jikaoti.com/ti/tPA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行这个程序的输出结果是();#include<iostream>usingnamespacestd;classTestClass1{public:voidfun1(){cout<<"
下列程序的输出结果是#include<iostream.h>intmin(inta,intb){if(a<b)returna;elsereturnb;return0;
下列对模板的声明中,正确的是()。
以下程序的输出结果是()。main(){inta=4,b=5,c=0,d;d=!a&&!b)||!c;cout<<d<<endl;}
有如下类声明:classXA{intx;public:XA(intU)}x=n;}};classXB:publicXA{inty;public:XB(in
有关构造函数的叙述不正确的是
虚函数必须是类的()。
有如下类定义:classPoint{private:staticinthow_many;};______how_many=0;要初始化Point类的静态成员how_many,在下画线处应填入的内容是
下列语句的作用是计算正整数n的各位数字之和,例如:n=123,sum=1+2+3。请将下列语句补充完整。Do{Sum+=【7】:n=n/10;)while(n!=0)
有如下类定义:classTest{chara:constcharb:public:Test(charc){a=c;b=c;}//第1行voidf(chara)const{this.>a=a;}
随机试题
患者,女性,45岁。有胆囊结石病史,反复腹痛、发热、黄疸1年,近3天上述症状加重,高热、黄疸不退。入院体温40℃,脉搏120次/分,血压70/50mmHg。该患者首选的治疗为
甲状腺功能亢进症患者具有特征性的神经系统症状是()。
鼻黏膜给药和直肠给药常会产生肝脏首过作用。()
月经产生是
A.清骨散B.知柏地黄丸C.清营汤D.黄连解毒汤E.五味消毒饮有清骨蒸潮热作用的方剂是
()和使用计划就是根据经济与社会发展的需要和土地资源的情况,在时空上对一定区域内土地资源的合理分配和协调利用的提前安排,是我国土地开发利用的指导性文件。
某大型百货商场因扩大经营规模,需要对外招聘营业员。根据历史数据分析得知,营业员数量与商场营业规模成线性相关关系,回归系数a、b分别为25.12、10.25。去年商场实现营业额10亿元,有营业员120名。今年商场计划实现营业额12亿。请根据上述资料,回答下列
下列属于会计报表的是()。
瓷器区别于陶器,是因为瓷器的主要原料是()。
Everynightshelistenedtoherfathergoingaroundthehouse,lockingthedoorsandwindows.Shelistened;thebackdoorclosed
最新回复
(
0
)