首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sonByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sonByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实
admin
2016-06-12
27
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sonByName和主函数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 t return day;}
};
class Person{//人员类
char name[14];//姓名
bool is male;//性别,为true时表示男性
Date birth date;//出生日期public:
Person(char*name,bool is—male,Date birth—date)
//**********found**********
{
strcpy(this一>name,name);
}
const char*getName()const{return name;}
bool isMale()const{return ismale;}
Date getBirthdate()const{ return birth date;}
//利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于
int compareName(const Person&p)
const{
//**********found***********
________}
void show(){
cout<
cout<
//**********found**********
_______//显示出生月
<
//显示出生日
}
};
void sortByName I 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(1 978,4,20)),
Person(“王五”,false,Date(1965,8,3)),
Person(“杨六”,false,Date(1965,9,5)),
Person(“李四”,true,Date(1 973,5,30))
};
const int size=sizeof(staff)/si—zeof(staff[0]);
int i;
cout<
cout<
for(i=0;i
.show();
sortByName(staff,size);
cout<
for(i=0;i
.show();
cout<
return 0;
}
选项
答案
(1)is—male(is—male),birth—date(birth—date) (2)return strcmp(nallle,p.getName()); (3)<
解析
本题考查Date类和Person类,其中涉及构造函数、const函数、bool型私有成员及成员函数,以及strcmp()函数。
解题思路】(1)主要考查考生对构造函数的掌握,由函数体内strcpy(this一>nalne,nan’le);可知,要使用成员列表初始化的成员为is—male和birth—date。
(2)主要考查考生对strcmp()函数的掌握,先看程序对该函数的功能要求:利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于。因为strcmp()函数的功能是比较字符串大小,因此可以直接被return语句调用:return strcmp(nallle,p.getName());。
(3)主要考查考生对成员函数的掌握,程序的注释为:显示出生月,由此可以知道这里要输出出生月份,直接调用函数getMonth()即可。
【解题宝典】strcmp()函数、strcpy()函数、strlen()函数等是经常会用到的系统函数,要了解各个函数的功能:strait(连接)、strcly(复制)、strump(比较)、strlen(求长度)。
转载请注明原文地址:https://jikaoti.com/ti/6jE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
与y=(x>0?1:x<0?-1:0);的功能相同的if语句是
t为int类型,进入下面的循环之前,t的值为0。while(t=1){...}则以下叙述中,正确的是()。
有如下程序: #include"iostream.h" voidmain() { intx=1,a=0,b=0; switch(x){ case0:b++; case1:a++; case2:a++;b++;
假设fin是一个文件流对象,则关闭文件的语句是【】。
下列有关算法的描述中,错误的是()。
下列叙述中,正确的是()。
在选择运算所得到的结果关系中,所含的元组数不合【】原关系中的元组数。
在C++语言中,函数形参的默认存储类型是()。
带一个long类型参数的流成员函数______按参数值设置flags状态变量,并返回以前设置的标志值。
对于switch(C)中的变量c不能定义为的类型是()。
随机试题
胃酸的生理作用不包括()。
某企业卖出的能有效对冲库存铝价格风险的铝期货合同属于【】
以下法律文书不具有强制执行力的是()。
净资产越大,说明个人拥有的财富越多,可以通过()方式来提高家庭的净资产。
移动平均线不具有()特点。
请用不超过150字的篇幅,概括出给定资料所反映的主要问题。用不超过350字的篇幅,提出解决给定资料所反映问题的方案。要有条理地说明,要体现针对性和可操作性。
【2013年第53题】专业人士预测:如果粮食价格保持稳定,那么蔬菜价格也将保持稳定,如果食用油价格不稳,那么蔬菜价格也将出现波动。老李由此断定:粮食价格将保持稳定,但是肉类食品价格将上涨。根据上述专业人士的预测,以下哪项如果为真,最能对老李的观点提出质疑?
2013年11月,党的十八届三中全会指出,全面深化改革的总目标是()
Aneweconomicspaperhassomeold-fashionedadviceforpeoplenavigatingthestressesoflife:Findaspousewhoisalsoyourb
题1:公钥密码是(46)。常用的公钥加密算法有(47),它可以实现加密和数字签名,它的一个比较知名的应用是(48),这种应用的协商层用公钥方式进行身份认证,记录层涉及到对应用程序提供的信息的分段、压缩、数据认证和加密。题2:CMM作为软件过程改进的一个指
最新回复
(
0
)