【计算机类职业资格】二级C++-48及答案解析.doc
《【计算机类职业资格】二级C++-48及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-48及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-48及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中在编辑窗口内显示的主程序文件中定义有类 ABC和主函数 main。程序文本中位于每行“/ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 21 23 注意:只修改每个“/ERROR*found*”下面的一行,不要改动程序中的其他任何内容。 #include iostream using namespace std; class ABC public:
2、/ERROR *found* ABC() a=0; b=0; c=0; ABC(int aa, int bb, int cc); void Setab() +a, +b; int Sum() return a+b+c; private: int a,b; const int c; ; ABC:ABC (int aa, int bb, int cc):c(cc) a=aa; b=bb; int main () ABC x(1, 2, 3), y(4, 5, 6); ABC z, *w= w-Setab(); / ERROR *found* int s1=x. Sum()+y-Sum(); cou
3、t s1“; / ERROR *found* int s2 =s1 +w.Sum(); cout s2 endl; return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,其中在编辑窗口内显示的主程序文件中定义有类 Base和 Derived,以及主函数 main。程序文本中位于每行“/*found*”下面的一行内有一处或多处下画线标记,请在每个下画线标记处填写合适的内容,并删除下画线标记。经修改后运行程序,得到的输出应为: sum=55。 注意:只在横线处填写适当的代码,不要
4、改动程序中的其他内容。 #include iostream using namespace std; class Base public: Base(int m1, int m2) mem1 =m1; mem2=m2; int sum () return mem1 +mere2; private : int mem1, mem2; /基类的数据成员 ; /派生类 Derived从基类 Base公有继承 /*found* class Derived: _ public: /构造函数声明 Derived (int m1, int m2, int m3); /sum 函数定义,要求返回mem1、me
5、m2 和 mem3之和 /*found* int sum() return_+mere3; private : int mem3; /派生类本身的数据成员 ; /构造函数的类外定义,要求 m1和 m2分别初始化mem1和 mem2, 由 m3初始化 mem3 /*found* _Derived(int m1, int m2, intm3): /*found* _, mem3 (m3) int main() Base a(4, 6); Derived b (10, 15, 20); int sum=a.sum() +b.sum(); cout “sum = “ sum endl; return
6、0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 pmj3下的工程 proj3,其中包含主程序文件 main.cpp和用户定义的头文件 Array.h,整个程序包含有类 Array的定义和主函数 main的定义。请把主程序文件中的 Array类的成员函数 Contrary()的定义补充完整,经补充后运行程序,得到的输出结果应该是: 58 5, 4, 3, 2, 1 0, 0, 8.4, 5.6, 4.5, 3.4, 2.3, 1.2 注意:只允许在“/*333*”和“/*666*”之间填写内容,不允许修改其他任何地方
7、的内容。 /Array.h #include iostream using namespace std; templateclass Type, int m class Array /数组类 public: Array(Type b, int mm) /构造函数 for(int i=0; im; i+) if(i mm) ai =bi; else ai =0; void Contrary(); /交换数组 a中前后位置对称的元素的值 int Length() const return m; /返回数组长度 Type operator (int i)const /下标运算符重载为成员函数 if(
8、i0 |i=m) cout“下标越界“endl; exit(1);) return ai; private: Type am; ; void writeToFile(const char * ); /不用考虑此语句的作用 /main.cpp #include“Array.h“ /交换数组 a中前后位置对称的元素的值 template class Type, int m void Array Type, m :Contrary () /补充函数体 /*333* /*666* int main() int sl5 =1, 2, 3, 4, 5; double s216 = 1.2, 2.3, 3.
9、4, 4.5, 5.6, 8.4; Arrayint, 5 d1(s1,5); Arraydouble, 8 d2(s2,6); int i; d1.Contrary(); d2.Contrary(); cout d1.Length () “ d2. Length ()endl; for(i=0; i4; i+) cout d1i “,“; cout d14 endl; for(i=0; i7; i+) cout d2i “,“; cout d2 7 endl; writeToFile (“); /不用考虑此语句的作用 return 0; (分数:40.00)_二级 C+-48答案解析(总分:
10、100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中在编辑窗口内显示的主程序文件中定义有类 ABC和主函数 main。程序文本中位于每行“/ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 21 23 注意:只修改每个“/ERROR*found*”下面的一行,不要改动程序中的其他任何内容。 #include iostream using namespace std; class ABC public: /ERROR *found* AB
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C48 答案 解析 DOC
