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

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

1、国家二级 C+机试(操作题)模拟试卷 226及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 prog1下的工程 progl,该工程中包含程序文件 main cpp,其中有 Salary(“工资 ”)类和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为: 应发合计: 3500应扣合计: 67 5实发工资: 3432 5 注意:只修改每个 “ ERROR*found*”下的那一行, 不要改动程序中的其他内容。 1 #include 2 using namespace std; 3 c

2、lass Salary 4 public: 5 Salary(const char*id, double the_base, double the_bonus, double the_tax) 6 ERROR *found* 7 : the_base(base), the_bonus(bo-nus), the_tax(tax) 8 9 staff_id=new charstrlen(id)+1; 10 strcpy(staff_id, id); 11 12 ERROR *found* 13 Salary()delete*staff_id; 14 double getGrossPay()cons

3、treturn base+bonus; 返回应发项合计 15 double getNetPay()constreturn get-GrossPay()-tax; 返回实发工资额private: 16 char*staff_id; 职工号 17 double base; 基本工资 18 double bonus; 奖金 19 double tax; 代扣个人所得税 20 ; 21 int main() 22 Salary pay(“888888“, 3000 0, 500 0, 67 50); 23 cout 3 using namespace std; 4 5 const int MAXNUM

4、=100; 6 class Set 7 private: 8 int num; |元素个数 9 char setdataMAXNUM;字符数组,用于存储集合元素 10 public: 11 Set(char*s); 构造函数,用字符串 s构造一个集合对象 12 bool InSet(char c); 判断一个字符 c是否在集合中,若在,返回 true,否则返 13 回 false 14 void Print()const; 输出集合中所有元素 15 ; 16 Set: Set(char*s) 17 18 num=0; 19 while(*s) 20 *found* 21 if(_) TODO:

5、添加代码,测试元素在集合中不存在 22 *found* 23 _; TODO:添加一条语句,加入元素至集合中 24 s+: 25 26 27 bool Set: InSet(char c) 28 29 for(int i=0; iA- # A- # A- # exiting inner block exiting outer block 注意:只在函数 Prepend的 “ *333*”和 “*666*”之间填入若干语句,不要改动程序中的其他内容。 1 SList h 2 Struct SLiStItem 3 char data; 4 sListItem*next; 5 ; 6 clasS s

6、List 7 public: 8 sList(): h(0) 9 0表示空链表 10 -sList(); ll void Prepend(char c); 12 在链表前端加入元素 13 VOid Del(); 14 删除链表首元素 15 SLiSt工 tem*Fimst()conStreturnh; 16 返回链表首元素 17 VOid Print()const; 18 打印链表内容 19 void Release(); 20 销毁链表 21 private: 22 sListItem*h; 23 链表头 24 ; 25 void writeToFile(const char*; 1 mai

7、n cpp 2 #include 3 #include“sList h“ 4 USing namespace std; 5 6 sList: sList() 7 8 Release(); 9 ) 10 void sList: Prepend(char C) 11 12 *333* 13 14 15 *666* 16 17 void sList: Del() 18 19 sListItem*temp=h; 20 h=h-next: 21 delete temp; 22 23 void sList: Print()const 24 25 sListItem*temp=h; 26 while(tem

8、p!=0)判断是否到达链表尾部 27 28 cout“; 29 temp=temp一 next; 30 31 cout Print(); 50 coutdata=c;把 c赋值于结构体 temp成员 data 3 temp-next=h;把 h赋值于结构 temp体成员 next 4 h=temp;把 temp赋值给 h,即 h指向 temp指向的空间 【试题解析】 主要考查考生对链表的掌握,成员函数 Prepend的功能是在链表头部加人一个新元素。形参 c是一个 char型变量,因此要定义一个新的结构体指针temp,并给它分配 sListhem类型空间,把形参 c中的值赋给 temp的数据域,并使 temp通过指针链接到链表上。

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

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

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