首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示人基本信息的类CHumanlnfo,但类CHumanlnfo的定义并不完整。请按要求完成下列操作,将类CHumanlnfo的定义补充完成: (1)定义私有数据成员blood
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示人基本信息的类CHumanlnfo,但类CHumanlnfo的定义并不完整。请按要求完成下列操作,将类CHumanlnfo的定义补充完成: (1)定义私有数据成员blood
admin
2020-10-21
43
问题
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示人基本信息的类CHumanlnfo,但类CHumanlnfo的定义并不完整。请按要求完成下列操作,将类CHumanlnfo的定义补充完成:
(1)定义私有数据成员bloodType用于表示血型,血型为char型的数据。请在注释“//********1********”之后添加适当的语句。
(2)完成构造函数的定义,要求具有缺省值,缺省值为身高175,体重70,血型A。请在注释“//********2********”之后添加适当的语句。
(3)完成类外CHumanInfo成员函数Setlnfo的定义。请在注释“//********3********”之后添加适当的语句。
(4)在主函数中调用成员函数Setlnfo,把对象d2的三个私有数据成员分别设定为身高170,体重64,血型为B。请在注释“//********4********”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include
Class CHumanInfo
{
private:
int height;
int weight;
//********1********
public:
//********2********
:height(ht),weight(wt),
bloodType(bt){);
CHumanInfo(CHumanInfo &h1):
height(h1.height),
weight(h1.weight),
bloodType(h1.bloodType){};
int GetHeight()
{
return height;
}
int GetWeight()
{
return welght;
}
int GetBloodType()
{
return bloodType;
}
void SetInfo(int ht,int
wt,char bt);
void Display();
};
//********3********
{
height=ht;
weight=wt;
bloodType=bt;
}
void CHumanInfo::Display()
{
cout<<"HumanInfo:";
cout<
weight<<"Kg,BloodType"<<
bloodType<
}
Void main()
{
CHumanInfo hl(169,61,’A’);
CHumanInfo h2;
CHumanInfo h3(h1);
CHumanInfo h4(h2);
//********4********
h1.Display();
h2.Display();
h3.misplay();
h4.misplay();
}
选项
答案
(1)添加语句:char bloodType; (2)添加语句:CHumanlnfo(int ht=175,int wt=70,char bt=’A’) (3)添加语句: Void CHumanInfo::SetInfo(int ht,int wt,char bt) (4)添加语句:h2.Setlnfo(170,64,’B’);
解析
(1)第1个标识下定义私有数据成员char型的bloodType,故第1个标识下应添加“charbloodType;”。
(2)构造CHumanlnf00完成三个成员的初始化,并且带有缺省值参数,缺省值为身高175,体重70,血型A,由函数体语句可知参数名分别为ht、wt和bt,因此第2个标识下应添加“CHumanlnfo(int ht=175.int wt=70,char bt=’A’)”。
(3)第3个标识下在类外完成成员函数Setlnfo的定义,在类外定义成员函数的格式为:<返回值类型><类名>::<成员函数>(<参数表>),故第3个标识下应添加“void CHumanInfo::Setlnfo(int ht,int wt,char bt)”。
(4)调用函数Setlnfo()需要3个参数,程序要求把对象d2的三个私有数据成员分别设定为身高170,体重64,血型为B,即把这三个值传入函数Setlnfo(),因此第4个标识下应添加“h2.Setlnfo(170,64,’B’);”。
转载请注明原文地址:https://kaotiyun.com/show/4Vyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每
有如下类定义:classBag{public:Bag(intp=200,chars=’M’):price(P),size(s){eout
有如下程序:#includeusingnamespaeestd;ela$8Sample{friendlongfun(Samples);public:Sample(10nga){x=a;}
若有如下类声明:classMyClass{public:MyClass(){cout<<1;}};执行下列语句MyClassa,b[2],*p[2];程序的输出结果是()。
下列叙述中正确的是()。
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正程序中的错误。本题的功能是:从键盘输入字符串S,然后输出字符串s,中的字符个数。注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//***
使用VC6打开考生文件夹下的源程序文件modi1.cpp,使它能得出正确的结果。本程序要求屏幕输出:n=99注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//********error********的下面。#inc
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:i=5i=10i=15i=20注意:错误的语句在//******error******的下面,修改该语句即可。#include
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:TestClass1TestClass2注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句
随机试题
意义学习需要具备哪些条件?
下列关于甲状腺激素对物质代谢影响的叙述,正确的是
A.膀胱俞、中极、行间、内庭B.阴谷、肾俞、三焦俞、气海、委阳C.脾俞、胃俞、足三里、血海D.三阴交、阴陵泉、膀胱俞、中极E.关元、中极、足三里、肾俞治疗癃闭湿热下注证,应首选()
下列主体中,不能作为票据保证人的有()。
一位教师讲“生物与环境”一节时,结合教学讲解了我国目前需要解决的环境保护和生态平衡等有关的知识,激发了学生的学习兴趣。这体现了生物学的()教学原则。
教育与生产相脱离,教育具有阶级性、道统性、专制性、刻板性和象征性等。这些属于()的特征。
对文艺复兴、宗教改革、天主教改革三者关系表述正确的一项是()
根据《宪法》和《民族区域自治法》的规定,下列既有权制定自治条例,也有权制定地方性法规的是()。
MakingYourselfaGoodRecordIfyouareanAmericanandyouthinkyoumightneedtoborrowmoneysomeday,thebestthingtodo
A、Hecan’thelpthewoman,becauseit’stoodarktosee.B、Hecan’tmeetthewoman,becausehegoestotheinterview.C、Hecan’t
最新回复
(
0
)