杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷

上传人:飞*** 文档编号:3829052 上传时间:2017-08-12 格式:DOC 页数:5 大小:78.20KB
返回 下载 相关 举报
杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷_第1页
第1页 / 共5页
杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷_第2页
第2页 / 共5页
杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷_第3页
第3页 / 共5页
杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷_第4页
第4页 / 共5页
杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷》由会员分享,可在线阅读,更多相关《杭州电子科技大学C++面向对象程序设计_期末考试试题(A)卷(5页珍藏版)》请在金锄头文库上搜索。

1、第 0 页 共 5 页 杭州电子科技大学学生考试卷(A)卷一、判断题(15 分) (对的打,错的打)1. 友元函数用于允许一个函数访问不相关类的私有部分。2. 构造函数可以被继承。3. 动态绑定的多态性是通过虚函数实现的。4. 在 c+中,传引用调用等同于传地址调用。5. 重载函数必须有不同的参数列表。6. 可以用 delete 释放不是用 new 运算符分配的内存。7. 类成员的默认访问模式是 private。8. 在类 Time 中的析构函数可以声明为:void Time(int);9. const 对象必须初始化。10. 在 c+中,只能重载已有的运算符。二 、选择题(20 分)1. 关

2、键字 _ 说明对象或变量初始化后不会被修改。 a. static b. public c. const d. inline2. 如果调用带有默认参数的函数时缺少一个参数,则_参数就作为这一参数。 a. 第一个 b. 最后一个 c. 中间一个 d. 以上都不是3. 成员函数可声明为静态的,条件是它不访问 _类成员。 a. 静态 b. 常数 c. 非静态 d. 公共4. 内联函数执行起来比标准函数_。a. 更慢 b. 更快 c. 次数更多 d. 以上都不是5. 默认参数的值由_提供。 a. 该函数 b. 调用程序 c. 上述二者 d. 以上都不是6. 在 C+ 中,混合类型表达式_。a. 允许存在

3、 b. 为一错误 c. 从 int 到 float d. 从 float 到 int7. 表达式 long(intVar) 也可表示为 _。a. intvar = long; b. intVar(long) c. (long)intVar d. 以上都不是8. 静态数据成员的生存期_。a. 与整个程序相同 b. 不长于类的生存期 c. 取决于创建的对象数 d. 以上都不是9. 要让一个类中的所有对象具有共同的数据,请使用_。a. 常数成员变量 b. 私有数据成员 c. 静态数据成员 d. 以上都是10. 设置虚基类的目的是:a.简化程序 b.消除二义性 c.提高运行效率 d.减少目标代码三 、

4、指出下列程序片段中的错误标号,写出正确语句或解释错在何处。 (20 分)int index=675; 1)*ptr=555; ptr 是指向整数常量的指针ntptr=&another; ntptr 是常量指针,不能指向别的的变量2)int arrp; 应改为:int *arrp;delete arrp; 应改为:delete arrp;3)return basedata;/ 在 border_and_menu 中引用 basedata 时产生二义性,应使用虚基类应改为:class border:virtual public window ;class menu: virtual public

5、window ;1)const int *ptr=&index;int *const ntptr=&index;*ptr=555;*ntptr=666;int another=8;ptr=&another;ntptr=&another;2) int arrp;arrp=new int15;delete arrp;3)下面程序为什么会编译错误,并改正错误(提出解决办法) 。class windowprotected: int basedata;考试课程 面向对象程序设计考试日期 06 年 6 月 日 成绩课 程 号 B1002100 教 师 号 任课教师姓名 楼永坚考生姓名学号(8位) 年级 0

6、5 专业050511/2/3座位号第 1 页 共 5 页 ;class border: public window ;class menu: public window ;class border_and_menu: public border, public menupublic:int show() return basedata;4)改正下面程序段中的错误,写出整个正确的程序段templatevoid print(T *a) coutusing namespace std;class Afriend double count(A&);public:A(double t, double r

7、):total(t),rate(r)private:double total;double rate;double count(A& a)a.total+=a.rate*a.total;return a.total;int main(void)A x(80,0.5),y(100,0.2);cout using namespace std;class Count private: static int counter; int obj_id; public: Count(); /constructor static void display_total(); /static function v

8、oid display(); Count(); /destructor ; int Count:counter; /definition of static data member Count:Count() /constructor counter+; obj_id = counter; Count:Count() /destructor 第 2 页 共 5 页 counter-; cout using namespace std;class BASE char c; public: BASE(char n):c(n) virtual BASE()coutusing namespace st

9、d;class A_(1)_char name80;public:A( _(2)_ ) _(3)_ ;class B_(4)_public:B(const char*n)_(5)_void PrintName( ) cout /加本句template /加 typenamevoid print(T *a) coutusing namespace std;考试课程 面向对象程序设计考试日期 06 年 6 月 日 成绩课 程 号 B1002100 教 师 号 任课教师姓名 楼永坚考生姓名学号(8位) 年级 05 专业050511/2/3座位号第 4 页 共 5 页 class Shapepubli

10、c:virtual double area() const =0; ;class Circle:public Shapepublic:Circle(double r):radius(r) virtual double area() const return 3.14159*radius*radius; protected:double radius; ;class Square:public Shapepublic:Square(double s):side(s) virtual double area() const return side*side; protected:double si

11、de;class Rectangle:public Shapepublic:Rectangle(double w,double h):width(w),height(h) virtual double area() const return width*height; protected:double width,height; ;class Trapezoid:public Shapepublic:Trapezoid(double t,double b,double h):top(t),bottom(t),height(h)virtual double area() const return

12、 0.5*(top+bottom)*height; protected:double top,bottom,height; ;class Triangle:public Shapepublic:Triangle(double w,double h):width(w),height(h) virtual double area() const return 0.5*width*height; protected:double width,height; ;int main()Circle circle(12.6); Square square(3.5); Rectangle rectangle(4.5,8.4); Trapezoid trapezoid(2.0,4.5,3.2); Triangle triangle(4.5,8.4); Shape *pt5=&circle,&square,&rectangle,&trapezoid,▵ double areas=0.0; for(int i=0;iarea();couttotol of all areas=areasendl; return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 其它考试类文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号