国家二级C++机试(操作题)模拟试卷372
基本操作题
1.请使用VC6或使用【答题】菜单打开考生文件夹prog1下的工程prog1,该工程中包含程序文件main.epp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为:
应发合计:3500 应扣合计:67.5 实发工资:3432.5
注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include
using namespace std;
class Salary{
public:
Salary(const char*id,double the
base,double the bonus,double the
tax)
//ERROR**********found**********
:the base(base),the bonus(bonus),the tax(tax)
{
staff id=new char[strlen(id)+
1];
strcpy(staff id,id);
}
//ERROR**********found**********
一Salary(){delete*staff_id;)
double getGrossPay()const{return
base+bonus;)//返回应发项合计
double getNetPay()const{return get
GrossPay()一tax;}//返回实发工资额
private:
char*staff id; //职工号
double base; /基本工资
double bonus; //奖金
double tax; //代扣个人所得税
};
int main(){
Salary pay(”888888”,3000.0,500.
0,67.50);
cout;<<”应发合计:”<<pay.get;GrossPay()<<””;
Gout<<”应扣合计:”<<pay.getGrossPay()一pay.getNetPay()<<””;
//ERROR**********found**********
cout:<<”实发工资:”<<pay::getNet
Pay()<<endl;
return 0;
}
(1):base(the_base),bonus(the_bonus),tax(the_tax)
(2)~Salary(){delete[]staff_id;}
(3)cout<<”实发工资:”<<pay.getNetPay()<<endl;
解析:(1)主要考查考生对构造函数的掌握情况,构造函数的成员初始列表要把形参放在括号内。
(2)主要考查考生对析构函数的掌握情况,析构函数使用delete释放指针,delete后要跟标识符“[]”。
(3)主要考查考生对成员函数调用的掌握情况,调用类的成员函数使用标识符“.!”,而不是作用域符“::”。
简单应用题
2.请使用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{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 is
male;}
Date getBirthdate()const{ return
birth date;)
//利用strcmp()函数比较姓名,返回一个
正数、0或负数,分别表示大于、等于、小于
int compareName(const Person&p)
const{
//**********found**********
____________}
void show(){
cout<<end1;
cout<<name<<\\
(1)is_male(is_male),birth_date(birth_date)
(2)retum strcmp(name,P.getName());
(3)<<birth_date
本文档预览:3600字符,共5970字符,源文件无水印,下载后包含无答案版和有答案版,查看完整word版点下载