[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc

上传人:syndromehi216 文档编号:497549 上传时间:2018-11-28 格式:DOC 页数:8 大小:58.50KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc_第1页
第1页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc_第2页
第2页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc_第3页
第3页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc_第4页
第4页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷455及答案与解析.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 455及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value=63 number=1 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include using namespace std; class MyClass int*p; const int N; public: ERROR *found* MyClass(int val): N

2、=1 p=new int; *p=val; ERROR*found* MyClass()delete*p; ) friend void print(MyClass&obj); ; ERROR*found* void MyClass: print (MyClass&obj) cout using namespace std; class Sale public: Sale();默认构造函数,将 price初始化为 0 Sale(double the_price); 构造函数,用 the_price初始化 price virtual double bill() const;返回当前商品的价格 (基

3、本价 ) double savings(const Sale&other)const;返回参数 other所引用的对象比当前对象便宜的差价 protected: double price;商品的基本价格 (不打折的价格 ) ; Sale: Sale(): price(0) Sale: Sale(double the price): price(the price) double Sale: bill()const return price; double Sale: savings(const Sale&other)const ERROR*found* _;返回当前对象价格比 other贵多少

4、的差价 class DiscountSale: public Sale打折销售类继承销售类 public: DiscountSale();默认构造函数,将 discount初始化为 0 DiscountSale(double the_price, double the discount);构造函数, the_price是基本价格; the discount是折扣百分比 virtual double bill()const;返回本商品销售价格 (即打折以后的实际售价,覆盖了基类的 bill函数 ) protected: double discount;折扣百分比。例如降价至原价的 70,此成员值

5、应为 70 ; DiscountSale: DiscountSale(): discount (0) DiscountSale: DiscountSale (double the price, double the discount) : Sale(the price), discount (the discount) double DiscountSale: bill () const double fraction=discount 100; *found* _;返回本对象打折以后的实际售价 bool operatorbill()-other bill() (2)return fracti

6、on*price (3)return first bill()bill()-other bill() 同样, this指针引用当前对象, other是引用对象,所以可以与 bill()虚函数一起使用多态机制,获 得当前对象和 other对象的实际价格,再进行差值计算 (4)main()函数中,程序判断 discount小于 sire-ple后,输出提示信息,再调用savings()函数输出 discount和 simple的差值,这里需要计算 discount比 simple节省多少钱,所以需要将 simple当做当前对象, discount当做参数传人 savings()函数,所以补充语句如

7、下: simple savings(discount) 三、综合应用题 3 【正确答案】 1f(1ncomelower_limitsi) 如果 taxable(收入超出起征额的部分 )大于 lower limitsi阶段最低限额 tax payable += (taxable-lower_limitsi)*ratesi; 把起过阶段最低限额的部分乘以该阶段的税率后,加到 tax_payable(个人所得税 ) taxable=lower_limitsi; 把 fower limitsi赋值于 taxable 【试题解析】 主要考查考生对成员函数的掌握情况,根据题目要求可知,完成计算应纳个人所得税额的成员函数 getTaxPayable,其中参数 income为月收入。同时题目还表明:不超过 2000元的所得不征收个人所得税。因此先用 if语句判断是否要征收个人所得税。然后根据题目所给表格,来判断收入多少及应该收多少个人所得税。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1