【计算机类职业资格】二级C++-49及答案解析.doc
《【计算机类职业资格】二级C++-49及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-49及答案解析.doc(6页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-49及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 prog1下的工程 prog1。此工程中包含程序文件main.cpp,其中有类 Score(“成绩”)和主函数 main的定义。程序中位于每个“/ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号:12345678课程:英语总评成绩:85 注意:只修改每个“/ERROR*found*”下的一行,不要改动程序中的其他内容。 #include iostream using namespac
2、e std; class Score public: Score (const char * the_course,const char * the_id, int the_normal,int the_midterm, int the_end_of_term) : course (the_course), normal (the_normal), midterm (the_midterm), end_of_term(the_end_of_term) /ERROR *found* strcpy (the_id, student_id) ; const char * getCourse ()co
3、nst return course; /返回课程名称 /ERROR *found* const char * getID () const return /返回学号 int getNormal () const return normal; /返回平时成绩 int getMidterm()const return midterm; int getEndOfTerm () const returnend of term; /返回期末考试成绩 int getFinal ()const; /返回总评成绩 private : const char * course; /课程名称 char studen
4、t_id12; /学号 int normal; /平时成绩 int midterm; /期中考试成绩 int end of term; /期末考试成绩 ; /总评成绩中平时成绩占 20%,期中考试占 30%,期末考试占 50%,最后结果四舍五入为一个整数 / ERROR *found* int getFinal () const return normal* 0.2 +midterm* 0.3 +end_of_term* 0.5 +0.5; int main () char English =“英语“; Score score (English, “12345678“, 68, 83, 92)
5、; cout “学号:“ score. getID () “; cout “课程:“ score. getCourse()“; cout “总评成绩:“ score.getFihal () endl; return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 prog2下的工程 prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类 Class和“学生”类 Student的定义,还有主函数 main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的
6、教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:改换教室前: 学号:0789 姓名:张三 班级:062113 教室:521 学号:0513 姓名:李四 班级:062113 教室:521 改换教室后: 学号:0789 姓名:张三 班级:062113 教室:311 学号:0513 姓名:李四 班级:062113 教室:311 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。 #include iostream using namespace std; class Class /“班级“类 public: Class(const c
7、har * id, const char *room) strcpy (class_id, id); /* found* _ const char * getClassID()const return class id; /返回班号 /* found* const char * getClassroom ()const_ /返回所在教室房号 void changeRoomTo (const char * new_room /改换到另一个指定房号的教室 strcpy(classroom, new room); private: char class id20; /班号 char classroo
8、m20; /所在教室房号 ; class Student /“学生“类 char my_id 10; /学号 char my_name20 ; /姓名 Class /所在教室 public: /*found* Student (const char * the_id, constchar * the_name, Class strcpy (my_name, the_name ); const char * getID () const returnmy_id; const char * getName ()const return my_name ; Class getClass () con
9、st return my_class; ; void showStudent (Student * stu) cout “学号:“ stu-getID () “; cout “姓名:“ stu -getName () “; cout “班级:“ stu -getClass (). getClassID () “; cout “教室:“ stu -getClass (). getClassroom() endl; int main() Class cla (“062113“, “521“); Student Zhang (“0789“, “张三“, cla), Li (“0513“, “李四“,
10、 cla); cout “改换教室前:“ endl; showStudent (showStudent ( /062113班的教室由 521改换到 311 /*found* _ cout “改换教室后: “ endl; showStudent ( showStudent ( return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 prog3下的工程 prog3,其中包含了类 Polynomial(“多项式”)的定义。形如 5x4+3.4x2-7x+2的代数式称为多项式,其中的 5为 4次项系数,3.4 为 2
11、次项系数,-7 为 1次项系数,2 为 0次项(常数项)系数。此例缺 3次项,意味着 3次项系数为 0,即省略了 0x3。在 Polynomial中,多项式的各个系数存储在一个名为 coef的数组中。例如,对于上面的多项式,保存在 coef0、coef1coef4中的系数依次为:2.0、-7.0、3.4、0.0、5.0,也即对于 i次项,其系数就保存在coefi中。成员函数 getValue计算多项式的值,多项式中 x的值是由参数指定的。请补充完成文件 Polynomial.cpp中成员函数 getValue的定义。此程序的正确输出结果应为:Value of p1 when x=2.0:59.
12、8Value of p2 when x=3.0:226.8注意:只在函数 getValue的“/*333*”和“/*666*”之间填入若干语句,不要改动程序中的其他内容。/Polynomiac.h#include iostreamusing namespace std;class Polynomial /“多项式“类public:Polynomial (double coef , intnum): coef (new double num ), num_of_terms (num)for(int i=0; inum_of_terms; i+)this-coefi =coefi;Polynomi
13、al() delete coef;/返回指定次数项的系数double getCoefficient (int power)const return coefpower; /返回在 x等于指定值时多项式的值double getValue (double x) const ;private :/系数数组, coef0为 0次项(常数项)系数,coef1为 1次项系数, coef2为 2次项(平方项)系数, 余类推。double * coef;int num of terms;void writeToFile(const char * path);/Polymomial.cpp#include“Po
14、lynomial.h“double Polynomial:getValue (double x)const/多项式的值 value为各次项的累加和double value = coef0;/*333*/*666*return value;/main.cpp#include “Polynomial.h“int main() double p1 = 5.0, 3.4, -4.0, 8.0, p2 =0.0, -5.4, 0.0, 3.0, 2.0;Polynomial poly1 (p1, sizeof (p1)/sizeof (double), poly2 (p2, sizeof(p2)/siz
15、eof (double);cout “Value of p1 when x =2.0 : “poly1.getValue (2.0) endl;cout “Value of p2 when x =3.0 : “poly2.getValue (3.0) endl;writeToFile (“ “);return 0;(分数:40.00)_二级 C+-49答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 prog1下的工程 prog1。此工程中包含程序文件main.cpp,其中有类 Score(“
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C49 答案 解析 DOC
