




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
共 10 页,第 页 河北师范大学考试命题专用纸 | | | | | | | | 密 | | | | | | | | | 封 | | | | | | | | | 线 | | | | | | | | | |3. 阅读程序,根据提示完成程序。(5分) #include using namespace std; int x = 3; /定义全局变量x namespace ns1 /写出名字空间定义的关键字 int x = 4; ; int main(void) int x = 5; cout :x endl; /打印出全局变量x中的值 cout ns1:x endl; /打印出名字空间ns1中x的值 return 0; 4. 分析程序中定义的各指针的特点,并指出错误的语句。(10分) #inclue using namespace std; int main(void) int x = 3; int y = 4; int z = 5; int * px = &x; int * py = &y; int *const pz = &z; /*声明的同时必须初始化*/ int *const *const_p2x = &px; /*声明的同时可以不初始化*/ int *const _const_p2x = &px; /*声明的同时必须初始化*/ int *const *const const_const_p2x = &px; /*声明时必须初始化*/pz = &y; const_p2x = &py; *const_p2x = &y; *const_p2x = 5;_const_p2x = &py; *_const_p2x = &y; *_const_p2x = 5; 面向对象程序设计期中考试试题一二三四五六七八九十总分代号 A 学院软件学院 专业 年级 08 学号 姓名 备注: 试卷首页必须用统一的考试命题专用纸,第二页以后用专用纸续页。 试卷必须打印成卷字迹要工整、清楚。 各题留出答案空白。 试卷打印后应认真校对,避免卷面错误。 得分阅卷人一、 程序分析题(共11题, 70分)1. 阅读程序,指出错误。(3分) #include int main(void) cout Hello world! n; return 0; 答:_using namespace std; 或 std:cout 或use std:cout;_2. 阅读程序,指出错误。(5分) #include void foo(int x, int y = 3) /TODO int main(void) int x = 3; int *p = 3; int &q; q = x; return 0;答:_*p不可直接赋数值。q = x;应该删除, int &q;改成int &q = x;_共 10 页,第 1 页河北师范大学考试命题专用纸试卷代号 A 学院 软件学院 专业 年级 08 姓名 学号 |6. 阅读程序,给出执行结果。(10分)#include using namespace std;class Student float score;public: Student() cout Student:Student() is called. score = score; cout Student:Student(float) is called. endl; Student() cout Student:Student() is called. endl; int main(void) Student student0; Student *student1 = new Student; Student *student2 = new Student(3.0); cout Hello world! endl; delete student2; delete student1; return 0;答:_ Student:Student() is called._ Student:Student() is called._ Student:Student(float) is called._Hello world!_ Student:Student() is called._ Student:Student() is called. Student:Student() is called._ const_const_p2x = &py; *const_const_p2x = &y; *const_const_p2x = 5; system(PAUSE); return 0;答:_5. 阅读程序,指出错误。(7分)#include using namespace std;class Person int age = 3; /int age; public: void setAge(int age = 0) this.age = age; /this-age = age; public: int getAge() return this.age; /this-age; int main(void) Person person0; person0.setAge(); cout person0.getAge() setAge(4); delete person1; return 0;答:_ | | | | | | | | 密 | | | | | | | | | 封 | | | | | | | | | 线 线 | | | | | | | |共 10 页,第 4 页共 10 页,第 3 页 | | 河北师范大学考试命题专用纸试卷代号 A 学院 软件学院 专业 年级 08 姓名 学号 |9. 阅读程序,指出错误并改正。(10分)#include using namespace std;class Person const int age = 0;/改成const int age; float score;public: void Person():age(0) / 构造函数没有返回值 this-age = 0; /删除 void setScore(float score) const /删除const this-score = score; ;int main() Person person0; return 0;答:_7. 请问下面两个函数定义是否算重载?为什么?(5分)int foo() /TODOdouble foo() /TODO答:不算。因为返回值不能作为重载的依据。_8. 阅读程序,根据提示完成程序。(5分)#include using namespace std;class Personpublic: Person(const Person &person); /请写出拷贝构造函数的函数原型声明; | | | | | | | | 密 | | | | | | | | | 封 | | | | | | | | | 线 线 | | | | | | | |共 10 页,第 6 页共 10 页,第 5 页 | | 河北师范大学考试命题专用纸试卷代号 A 学院 软件学院 专业 年级 姓名 学号 |得分阅卷人二、 判断题(共10题, 15分)1. 静态成员变量的存储空间被同类对象共享。(对)2. 成员方法(函数)的存储空间不被同类对象共享。(错)3. const成员变量的存储空间被同类对象共享。(错)4. 静态成员变量只能被静态成员方法所访问。(错)5. 静态成员方法不能访问非静态成员变量。(对)6. 对一个拥有静态成员变量的类而言,每实例化一次,都将为该静态成员变量分配一次存储空间。(错)7. 程序员使用new申请的空间,必须用delete释放。(对)8. 同类对象所具有的成员变量和成员函数一样。(对)9. 用户可以在堆区、栈区、全局区实例化对象。(对)10. 顶层函数可以作为某个类的友元,但一个类的成员函数不可以作为另一个类的友元。(错)得分阅卷人三、 程序题(共1题, 15分)有如下类: 课程类(Course):课程编号(私有成员)、课程名称(私有成员)。 学生类(Student):学生姓名(私有成员)、5门课程编号(私有成员)、5门课程的成绩(私有成员)。根据main函数的提示,编写学生成绩管理系统。10. 阅读程序,一方面根据提示完成程序,一方面给出其输出结果。(5分)#include class A static int x;public: A() x+; ;int A:x = 0; /对A:x进行初始化,将其初值设置为0;int main() cout A:x endl; A a0; cout A:x endl; A a1; cout A:x endl; return 0;结果:_0 1_2_11. 根据提示完成程序. (5分)#include using namespace std;class A int x;public: friend bool foo(A a); /声明foo函数是A的友元.;bool foo(A a) a.x = 3;int main(void) A a; return 0; | | | | | | | | 密 | | | | | | | | | 封 | | | | | | | | | 线 线 | | | | | | | |共 10 页,第 8 页共 10 页,第 7 页 | | 河北师范大学考试命题专用纸试卷代号 A 学院 软件学院 专业 年级 姓名 学号 |class Coursepublic:void setNo(int no);int getNo() const;void setName(string name);string getName() const;private:int m_No;string m_Name;class Studentpublic:void setName(name);string getName() const;void addCourse(int no, float score);float getScore(int no) const;private:string m_Name;int m_cNo5;float m_cScore5;#define MAX_COURSE_COUNT 10#define MAX_STUDENT_COUNT 10int main(void) Course *coursesMAX_COURSE_COUNT;/指向堆中课程对象,课程信息从键盘上接收Student *studentsMAX_STUDENT_COUNT;/指向堆中学生对象,信息从键盘上接收 for(int i = 1; i= 5; +i) /从键盘上接收5课程的信息,每门课程的编号及名称具有唯一性 coursei=mew Course; int no; string name;scanf(“%d &s”, &no,&name) coursei.setName(name);coursei.setNo(no);for(int j = 1; j = 10; +j) /从键盘上接收10名学生的姓名、课程编号及成绩studentj=new Student;string name;int no;float score;scanf(“%s %d &f”,&name,&no
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 经济法律基础试题及答案
- 柜员现金管理题库及答案
- 打铁专业知识培训课件
- 2025年威海公务员考试试题及答案
- 2025年北京电工考试题目及答案
- 懒字汉字演变课件
- 2025年胎心监护考试试题及答案
- 情绪小屋课件
- 情景导入课件
- 韩语四十音考试题及答案
- 2025年公证处聘用制书记员招聘考试要点及面试模拟题解析
- 2025江西吉安庐陵新区招聘社区工作者(专职网格员)招聘22人考试参考试题及答案解析
- 2025-2026学年广美版(2024)小学美术二年级上册教学计划及进度表
- 2025年手电筒行业研究报告及未来行业发展趋势预测
- 设备使用与保养培训课件
- 酒店客户服务质量提升培训课件
- GB/T 9258.2-2025涂附磨具用磨料粒度组成的检测和标记第2部分:粗磨粒P12~P220
- 2025山西太原西山生态文旅投资建设有限公司及子公司招聘13人笔试参考题库附带答案详解
- 2025 年小升初吕梁市初一新生分班考试语文试卷(带答案解析)-(部编版)
- 2025秋全体教师大会上,德育副校长讲话:德为根,安为本,心为灯,家为桥-这场开学讲话,句句都是育人的方向
- 2025年政工师考试试题及参考答案
评论
0/150
提交评论