[计算机类试卷]国家二级C++机试(操作题)模拟试卷304及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷304及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷304及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 304及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹 proj1下的工程 proj1,其中定义了一个 CD类。程序中位于每个 ERROR *found*下的语句行有错误,请加以更正,不得修改程序的其他部分。更正后程序的输出应该是: 歌唱祖国 30 义勇军进行曲 95 注意:只能修改每个 ERROR *found*下的那一行,不要改动程序中的其他内容。 #include iostream #include cstring using namespace std; C1ass CD char name20; int number; public:
2、 void init(char * aa, intbb) ERROR *found* name aa; number bb; char水 getName() ERROR *found* return * name; int getNumber()return number; void output() ERROR *found* cout name20 number end1; ; void main() CD dx, dy; dx init(“歌唱祖国 “, 30); dy init(“义勇军进行曲 “, 3*dx getNumber() 5); dx output(); dy output
3、(); 二、简单应用题 2 使用 VC6打开考生文件夹 proj2下的工程 proj2,其中有两个类:一是销售类(sale),用于表示按照一件商品的基本价格进行销售;另一个是打折销售类(DiscountSale),用于表示在基本价格基础上按一个折扣比例进行销售。DiscountSale类继承了 sale类。类的主要数据成员的含义和成员函数的功能要求在程序注释中有说明。请在程序中的横线处填写适当的代码,然后删除横线,完成程序的功能。此程序的正确输出结果应为: Discount item is cheaper Saving is 0 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。
4、 #include iostream using namespace std; class Sale public: Sale();默认构造函数,将 price初始化为 0 Sale(double the_price); 构造函数,用 the_price初始化 price virtual double bill()const; 返回当前商品的价格 (基本价 ) double savings(const Sale other)const;返回参数 other所引用的对象比当前对象便宜的差价 protected: double price;商品的基本价格 (不打折的价格 ) ; Sale Sale
5、(): price C0) Sale Sale(double the_price): price(the_price) double Sale bill()const return price; double Sale savings(const Sale other)const ERROR *found* _返回当前对象价格比 other贵多少的差价 class DiscountSale: public Sale打折销售类继承销售类 public: DiscountSale();默认构造函数,将 discount初始化为 0 DiScountSale(double the_price, do
6、uble the_discount); 构造函数, the_price是基本价格; the_discount是折扣百分比 virtual double bill()const;返回本商品销售价格 (即打折以后的实际售价,覆盖了基类的 bill函数 ) protected: double discount;折扣百分比。例如降价至原价的 70,此成员值应为 70 , DiscountSale DiscountSale(): discount(0 DiScountSale DiscountSale (double the_price, double the_diScount) : Sale(the_
7、price), discount (the_discount) double DiscOuntSale bill () const double fraction discount 100; *found* _;返回本对象打折以后的实际售价 bool operator (const Sale first, const Sale&Second) *found* _;判断是否 first价格低于 second价格 int main() Sale Simple(10 00); DiscountSale diScount(11 00, 90); if(discount simple) cout “Di
8、Scount item ischeaper n“; *found* 这里输出购买 discount比购买 simple节省多少钱 cout “Saving is“ _ end1; else cout “Discount item isnot cheaper n“; return 0; 三、综合应用题 3 使用 VC6打开考生文件夹 proj3下的工程 proj3,其中定义了一个字符串变量类StringVar。类成员的说明在程序注释中。请在 *333*和*666*之间填写 StringVar成员函 数和友元函数的实现代码。在main函数中给出了一组测试数据,运行时输入: Hello Kitty
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 304 答案 解析 DOC
