首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。此程
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。此程
admin
2021-05-06
37
问题
请打开考生文件夹下的解决方案文件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
using namespace std;
class Date{ //日期类
int year , month , day;//年、月、日
public:
Date(int year,int month,
int day):year(year),month
(month),day(day){}
int getYear()const{return year;}
int getMonth()const{return month;}
int getDay()const{return day;}
},
class Person{ //人员类
char name[14];//姓名
bool is male;//性别,为true时表示男性
Date birth date;//出生日期
public:
Person(char*name,bool ismale,Date birth date)
//********found********
:_____________
{
strcpy(this->name,name);
}
const char*getName()const{returnR name;}
bool isMale()conSt{return is_male;}
Date getBirthdate()conSt{return birth date ;}
//利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于
int compareName(const Person&p)const{
//********found********
_____________)
void Show(){
Cout<
cout<
//********found********
____________//显示出生月<
}
};
void sortByName(Person ps[], int size){
//将人员数组按姓名排列为升序
for(int i=0 ; i
//采用选择排序算法
int m=i;
for(int j=i+1;j
if(ps[j].compareName(ps[m])<0)
m=j;
if(m>i){
Person P=ps[m];
ps[m]=ps
;
ps
=p ;
}
}
}
int main(){
Person Staff[]={
Person("张三",true,Date(1978,4,20)),
Person("王五",false,Date(1965,8,3)),
Person("杨六",false,Date(1965,9,5)),
Person("李四",true,Date(1973,5,30))
};
const int size = siZeof
(staff)/sizeof(staff[0]);
int i;
cout<
cout<
for(i=0;i
staff
.show();
sortByName(staff,Size);
Cout<
for(i=0;i
staff
.show();
cout<
return 0;
}
选项
答案
(1)is_male(is_male),biah_date(biah_date) (2)return strcmp(name,P.getName()); (3)<
解析
(1)主要考查考生对构造函数的掌握,由函数体内strcpy(this->Name,name);可知,要使用成员列表初始化的成员为is_male和birth_date。
(2)主要考查考生对strcmp()函数的掌握,先看程序对该函数的功能要求:利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于。因为strcmp()函数的功能是比较字符串大小,因此可以直接被return语句调用:return strcmp(name,p.getName());。
(3)主要考查考生对成员函数的掌握,程序的注释为:显示出生月,由此可以知道这里要输出出生月份,直接调用函数getMonth()即可。
转载请注明原文地址:https://jikaoti.com/ti/Cmh0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列链表中,其逻辑结构属于非线性结构的是()。
生成派生类对象时,派生类构造函数调用基类构造函数的条件是()。
使用VC6打开考生文件夹下的源程序文件modi2.epp。阅读下列函数说明和代码,补充空出的代码。函数IsPalindromes(cha*string)实现的功能是判定给定的字符串是否构成回文字符串,如果是则返回1,否则返回0。如:1234554
下列关于类成员对象构造函数调用顺序的叙述中,正确的是()。
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是()。
下列选项中不属于结构化程序设计原则的是()。
设循环队列的存储空间为Q(1:35),初始状态为front=rear=35。现经过一系列入队与退队运算后,front=15,rear=15,则循环队列中的元素个数为()。
下列语句中,错误的是()。
下面属于应用软件的是()。
请打开考生文件夹下的解决方案文件proj2,此工程中含有一个源程序文件proj2.epp。函数char*GetNum(char*src,char*buf)从sre开始扫描下一个数字字符序列,并将其作为一个字符串取出放入字符串空间buf中。函数返回扫描的终止
随机试题
注水泥塞施工,水泥塞试压压降不超过()为合格。
甲公司2011年12月份发生与银行存款有关的业务如下:(1)①12月28日,甲公司收到A公司开出的480万元转账支票,交存银行。该笔款项系A公司违约支付的赔款,甲公司将其计入当期损益。②12月29日,甲公司开出转账支票支付B公司咨询费360万元,并于当
某企业在安全生产标准化建设过程中,开展了创建安全班组达标活动,旨在提升班组安全管理水平。张某担任该企业班组长多年,具有丰富的基层安全管理经验,张某发现在班组内可能造成较大事故的职工往往具有感情冲动等性格特征。根据事故频发理论,针对具有这种性格特征的人,可采
发包人应在合同工程完工证书颁发后()天内将履约担保退还给承包人。
电渣压力焊焊接完毕后,应停歇()方可卸下夹具回收焊剂,回收的焊剂内不得混入冰雪,接头渣壳应待冷却后清理。
素质教育的重点是培养学生的创新精神和()。
动物的冬眠,完全是一项对付不利环境的保护性行动,引起动物冬眠的主要因素,一是环境温度的降低,二是食物的缺乏。科学家们通过实验证明,动物冬眠会引起甲状腺素和肾上腺功能的降低,与此同时,生殖腺却发育正常,冬眠后的动物抗菌抗病能力反而比平时有所增加显然冬眠对它们
采用恒定法控制额外变量时
Atfirst,MaryfeelsthatwritinginEnglishisreallydifficult.Atfirst,Maryfinds______towriteinEnglish.
下面你将听到一段有关大数据带来的机遇与挑战的讲话。
最新回复
(
0
)