首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以
admin
2015-06-27
32
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为:
按姓名排序
排序前
张三男出生日期:1978年4月20日
王五女出生日期:1965年8月3日
杨六女出生日期:1965年9月5日
李四男出生日期:1973年5月30日
排序后:
李四男出生日期:1973年5月30日
王五女出生日期:1965年8月3日
杨六女出生日期:1965年9月5日
张三男出生日期:1978年4月20日
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
usingnamespacestd;
classDate{//日期类
intyear,month,day;//年、月、日public:
Date(intyear,intmonth,intday):
year(year),month(month),day(day){}
intgetYear()const{returnyear;}
intgetMonth()const{returnmonth;}
intgetDay()const{returnday;}
};
classPerson{//人员类
charname[14];//姓名
boolismale;//性别,为true时表示男性
Datebirthdate;//出生日期
public:
Person(char*name,booliSmale,
Datebirth_date)
//**********found**********
:________
{
strcpy(this->name,name);
}
constchar*getName()const{returnname;}
boolisMale()const{returnis
male;}
DategetBirthdate()const{return
birthdate;}
//利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于
intcompareName(constPerson&p)
const{
//**********found**********
________}
voidshow(){
cout<
cout<
:"女")<<¨<<"出生日期:"<
date.getYear()<<"年"//显示出生年
//**********found**********
________//显示出生月
<
//显示出生日
}
};
voidsortByName(Personps[],int
Size){
//将人员数组按姓名排列为升序
for(inti=0;i
//采用选择排序算法
intm=i;
for(intj=i+1;j
if(ps[j].compareName(ps[m])<0)
m=j;
if(m>i){
PersonP=ps[m];
ps[m]=ps
;
ps
=p;
}
}
}
intmain(){
Personstaff[]={
Person("张三",true,Date(1978,
4,20)),
Person("王五",false,Date(1965,
8,3)),
Person("杨六",false,Date(1965,
9,5)),
Person("李四",true,Date(1973,
5,30))
};
constintsize=sizeof(staff)/Si—
zeof(staff[0]);
inti;
cout<
cout<
for(i:0;i
.
show();
sortByName(staff,size);
cout<
for(i=0ji
.
show();
cout<
return0;
}
选项
答案
(1)is_male(is_male),birth_date(birth_date) (2)returnstrcmp(nallle,p.getName()); (3)<
解析
(1)主要考查考生对构造函数的掌握,由函数体内strcpy(this->name,name);可知,要使用成员列表初始化的成员为is_male和birth_date。
(2)主要考查考生对strcmp()函数的掌握,先看程序对该函数的功能要求:利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于。因为strcmp()函数的功能是比较字符串大小,因此可以直接被return语句调用:returnstrcmp(name,p.getName());。
(3)主要考查考生对成员函数的掌握,程序的注释为:显示出生月,由此可以知道这里要输出出生月份,直接调用函数getMonth()即可。
转载请注明原文地址:https://jikaoti.com/ti/fiE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面程序的输出结果是()。#include<iostream>usingnamespacestd;intmain(){intn=10;while(n>7){n--;cout<<
有如下程序:#include<iostream>usingnamespacestd;classBase{protected:inti;public:intj;};classDeri
下列数据结构中,能用二分法进行查找的是______。
排序是计算机程序设计中的一种重要操作,常见的排序方法有插入排序、【】和选择排序等。
在一个派生类中,对基类成员、类对象成员和非类对象成员的初始化次序是先【】,后【】,最后为【】。
在进行模块测试时,要为每个被测试的模块另外设计两类模块:驱动模块和承接模块(桩模块)。其中【】的作用是将测试数据传送给被测试的模块,并显示被测试模块所产生的结果。
当执行以下程序时,______是正确的k=1;do{k=k*k;}while(!k)
在表达式x-y中,“-”是作为非成员函数重载的运算符。若使用显式的函数调用代替直接使用运算符“-”,这个表达式还可表示为()。
类的说明如下,请指出错误的地方______。classMyclass{inta=111;public:Myclass(intx,inty);Myclass(i
在数据库模型中,通常把网状模型和()称为非关系模型。
随机试题
某肺炎患者,男性,74岁,在输液时突然呼吸困难、咳嗽、咳粉红色泡沫样痰,听诊肺部布满湿啰音。出现上述症状,我们应该立即采取的措施不包括
尸体护理时,其义齿的处理是
A.抑制血管紧张素Ⅱ生长B.选择性阻滞α1受体而扩张外周血管C.阻止钙离子进入心肌细胞及血管壁平滑肌细胞,使心肌收缩力降低、外周血管扩张D.抑制钠、水重吸收,减少血容量,降低心排血量E.减慢心率、降低心排血量,抑制肾素释放呋塞米作为降压药,其作
根据土地增值税法律制度的规定,下列各项中,不属于土地增值税征税范围的是()。
依据企业所得税法的规定,财务会计制度与税收法规的规定不同而产生的差异,在计算企业所得税应纳税所得额时应按照税收法规的规定进行调整。下列各项中,属于时间性差异的是()。
中国古典园林的成熟阶段是在()。
温度计:气温
(2010年联考.9月.12)下列成语全部蕴涵辩证思维的一组是()。
物质的唯一特性是()
Whathasrecentresearchfoundaboutdrinking?
最新回复
(
0
)