[计算机类试卷]国家二级C++机试(操作题)模拟试卷337及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷337及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷337及答案与解析.doc(12页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 337及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 pmjl下的工程 projl,此工程中含有一个源程序文件 pmjl cpp。其中位于每个注释 “ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The vahe is 10 Copy constructor called The value is 10 Destructor called Destructor called 注意:只修改注释 “ ERROR *found*”的下一行语句,不
2、要改动程序中的其他内容。 projl cpp #include using namespace std; class MyClass public: ERROR*found* MyClass(int i) value=i; cout using namespace std; class MyClass int i; friend void Increment(MyClas S f); public: const int NUM; ERROR*found* MyClass(int i=0)NUM=0; i=i; int GetValue()constreturn i; ) ; ERROR*fou
3、nd* VOid Increment()f i+; ) int main() MyClass obj; ERROR*found* MyClass: Increment(obj); cout using namespace std; class VectorBase 向量基类,一个抽象类 int len; public: VectorBase(int len): len(1en) int length()constreturn len; ) 向量长度,即向量中元素的个数 virtual double getElement(int i) const: 0;取第 i个元素的值 virtual dou
4、ble sum()const=0; /求所有元素的和 void show()const显示向量中所有元素 coutshow(); delete V; v=new ZeroVector(6); v一 show(); delete V; return 0; 三、综合应用题 4 请使用【答题】菜单命令或直接用 VC6打开考生文件夹下的工程 proj3,其中声明的是一个人员信息类,补充编制程序,使其功能完整。在 main函数中给出了一组测试数据,此种情况下程序的输出应该是: Zhang 20 TsinghHa。 注意:只能在函数 address_change的 “ *333* *”和 “ *666*”
5、之间填入若干语句,不要改动程序中的其他内容。 程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 proj3 h #include #include using namespace std; class Person char name20; int age; char* address; public: Person()age=0; address=0; ) void name_change(char*_name); /名字修改函数 void age_change(int_age); 年龄修改函数 void address
6、_change(char*_add); 地址修改函数 void info_display(); 人员信息显示 一 Person(); /析构函数 ; void writeToFile(const char*path); proj3 cpp #include #include #include”proj 3 h” using namespace std; void Person: name change(char* _name) strcpy(name, _name); void Person: age_change(int_age) age=_age; void Person: address
7、_change(char*_ add) if(address!=NULL)deletead- dress; *333* *666* void Person: info_display() cout #include #include using namespace std; class doc private: char/str;文本字符串首地址 int length; /文本字符个数 public: 构造函数,读取文件内容,用于初始化新对象, filename是文件名字符串首地址 doc(char*filename); void reverse();将字符序列反转 一 doc(); void
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 337 答案 解析 DOC
