[计算机类试卷]国家二级C++机试(操作题)模拟试卷476及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷476及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷476及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 476及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 progl下的工程 progl。此工程中包含程序文件 main cpp,其中有类 Score(“成绩 ”)和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号: 12345678课程:英语总评成绩: 85 注意:只修改每个 “ ERROR*found*”下的一行,不要改动程 序中的其他内容。 #include using namespace std; class Score publi
2、c: 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()constreturn course; )返回课程名称 ERROR*fo
3、und* const char*getTD()constreturn&student id; 返回学号 int getNormal()constreturn normal; 返回平时成绩 int getMidterm()const return midterm; 返回期中考试成绩 int getEndOfTerm()constreturn end of term; 返回期末考试成绩 int getFinal()const;返回总评成绩 private: const char*course; 课程名称 char student id12;学号 int normal; 平时成绩 int midte
4、rm; 期中考试成绩 int end of term; 期末考试成绩 ; 总评成绩中平时成绩占 20,期中考试占 30,期末考试占 50,最后结果四舍五入为一个整数 ERROR*found* int getFinal()const return noEmal*0 2+midterm*0 3+end_of_term*0 5+0 5; int main() char English=“英语 “; Score score(English, “12345678“, 68, 83, 92), cout: using namespace std; class Base public: Base(int m
5、1, int m2) meta1=m1; mem2=m2; int sum()return mem1+mem2; private: int mem1, mem2;基类的数据成员 ; 派生类 Derived从基类 Base公有继承 *found* class Derired: public: 构造函数声明 Derived(int m1, int m2, int m3); sum函数定义,要求返回 mem1、 mem2和 mem3之和 *found* int sum() return_+mem3; private: int mere3; 派生类本身的数据成员 ; 构造函数的类外定义,要求由 m1和
6、 m2分别初始化 meta1和 mem2。由 m3初始化 mere3 *found* _Derived(int m1, int m2, int m3): *found* _, mem3(m3) int main() Base a(4, 6); Derived b(10, 15, 20); int sum=a sum()+b sum(); cout #include using namespace std; class MiniString public: friend ostream&operator( istream&input, MiniString&s) 重载流提取运算符 char te
7、mp100;用于输入的临时数细 temp0= 0;初始为空字符串 inputsetw(100)temp; int inLen=strlen(temp); 输入字符串长度 if(inLen!=0) s length=inLen;赋长度 if(s sPtr!=0)deletes sPtr;避免内存泄漏 s sPtr=new chars length+1; strcpy(s sPtr, temp); 如果 s不是空指针,则复制内容 else s sPtr0= 0; 如果 s是空指针,则为空字符串 return input; void modString(const char*string2)更改字符
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 476 答案 解析 DOC
