[计算机类试卷]国家二级C++机试(操作题)模拟试卷494及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷494及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷494及答案与解析.doc(10页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 494及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,其中有枚举 DOGCOLOR、狗类Dog和主函数 main的定义。程序中位于每个 “ ERROR*found*”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: There is a white dog named Hobo There is a black dog named Haha There is a morley dog named Hihi 注意: 只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include i
2、ostream using namespace std: 狗的颜色:黑、白、黄、褐、花、其他 enum DOGCOLORBLACK, WHITE, YELLOW, BROWN, PIEBALD,OTHER; class Dog狗类 DOGCOLOR color; char name20; staticint count; public: Dog(char name , DOGCOLORcolor) strcpy(this- name, name); ERROR*found* strcpy(this- color, color); DOGCOLOR getColor( )constreturn
3、color; ERROR*found* const char*get: Name( )constreturn*name; const char*getColorString( )const switch(color) case BLACK: return“black“; case WHITE: return“white“; case YELLOW: return“yellow“; case BROWN: return“brown“; case PTEBALD: return“piebald“; return“motley“; void show( )const cout “There is a
4、“ getColorString( ) “dog named“ name endl; ; int main( ) ERROR*found* Dog dog1(“Hoho“, NHTTE), dog2(“Haha“, BLACK); dog3(“Hihi“, OTHER); dog1 show( ); dog2 show( ); dog3 show( ); return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,其中有两个类:一是销售类 (sale),用于表示按照一件商品的基本价格进行销售;另一个是打折销售类 (DiscountSale),用于表示在基本价格基础上按一
5、个 折扣比例进行销售。 DiscountSale类继承了 sale类。类的主要数据成员的含义和成员函数的功能要求在程序注释中有说明。请在程序中的横线处填写适当的代码,然后删除横线,完成程序的功能。此程序的正确输出结果应为: Discount item is cheaper Saving is0 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。 #include iostream using namespace std; Class Sale public: Sale( );默认构造函数, 将 price初始化为 0 Sale(double the_price);构造函数,用 t
6、he_price初始化 price virtual double bill( )const;返回当前商品的价格 (基本价 ) 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: savi
7、ngs(constSale&other)const ERROR*found* _;返回当前对 象价格比 other贵多少的差价 class DiscountSale: publicSale打折销售类继承销售类 public: DiscountSale( );默认构 造函数,将 discount初始化为 0 miscountSale(double the_price, double the_discount;构造函数, theprice是基本价格; the_discount是折扣百分比 virtual double bill( )const;返回本商品销售价格 (即打折以后的实际售价,覆盖了基类
8、的 bill函数 ) protected: double discount;折扣百分比。例如降价至原价的 70,此成员值应为 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* _;返回本对象 打
9、折以后的实际售价 bool operator (const Sale&first, const Sale&Second) *found* _;判断是否 first价格低于 second价格 int main( ) Sale Simple(10 00); miScOuntSale discount(11 00, 90); if(discount simple) cout “Discount item is cheaper n“; *found* 这里输出购买 discount比购买 simple节省多少钱 cout “Saving is“ _ endl; else cout “DiScount
10、item isnot cheaper n“; return0; 三、综合应用题 3 请打开考生文件夹下的解决方案文件 proj3,此工程中包含一个源程序文件proj3 cpp,其功能是从文本文件 in dat中读取全部整数,将整数序列存放到intArray类的对象中,然后建立另一对象 myAay,将对象内容赋值给 myArray。类 intArray重载了 “=”运算符。程序中给出了一个测试数据文件 input,不超过 300个的整数。程序的输出是: 10 11 13 16 20 要求: 补充编制的内容写在 “ *333*”与 “*666*”之间。实现重载赋值运算符函数,并将赋值结果在屏幕输出
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 494 答案 解析 DOC
