C面向对象程序设计期末考试试题Word版

上传人:M****1 文档编号:487597452 上传时间:2022-08-24 格式:DOC 页数:5 大小:69.50KB
返回 下载 相关 举报
C面向对象程序设计期末考试试题Word版_第1页
第1页 / 共5页
C面向对象程序设计期末考试试题Word版_第2页
第2页 / 共5页
C面向对象程序设计期末考试试题Word版_第3页
第3页 / 共5页
C面向对象程序设计期末考试试题Word版_第4页
第4页 / 共5页
C面向对象程序设计期末考试试题Word版_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《C面向对象程序设计期末考试试题Word版》由会员分享,可在线阅读,更多相关《C面向对象程序设计期末考试试题Word版(5页珍藏版)》请在金锄头文库上搜索。

1、杭州电子科技大学学生考试卷(A)卷考试课程面向对象程序设计考试日期06年6月 日成绩课 程 号B1002100教 师 号任课教师姓名楼永坚考生姓名学号(8位)年级05专业050511/2/3座位号一、 判断题(15分)(对的打,错的打)1. 友元函数用于允许一个函数访问不相关类的私有部分。2. 构造函数可以被继承。3. 动态绑定的多态性是通过虚函数实现的。4. 在c+中,传引用调用等同于传地址调用。5. 重载函数必须有不同的参数列表。6. 可以用delete释放不是用new运算符分配的内存。7. 类成员的默认访问模式是private。8. 在类Time中的析构函数可以声明为:void Time

2、(int);9. const对象必须初始化。10. 在c+中,只能重载已有的运算符。1) 2) 3) 4) 5) 6) 7) 8) 9) 10)二、选择题(20分)1) c 2)b 3) c 4)b 5)c 6) a 7)c 8)a 9)c 10)b11.二 、选择题(20分)1. 关键字 _ 说明对象或变量初始化后不会被修改。 a. static b. public c. const d. inline2. 如果调用带有默认参数的函数时缺少一个参数,则_参数就作为这一参数。 a. 第一个 b. 最后一个 c. 中间一个 d. 以上都不是3. 成员函数可声明为静态的,条件是它不访问 _类成员。

3、 a. 静态 b. 常数 c. 非静态 d. 公共4. 内联函数执行起来比标准函数_。a. 更慢 b. 更快 c. 次数更多 d. 以上都不是5. 默认参数的值由_提供。 a. 该函数 b. 调用程序 c. 上述二者 d. 以上都不是6. 在 C+ 中,混合类型表达式_。a. 允许存在 b. 为一错误 c. 从 int 到 float d. 从 float 到 int7. 表达式 long(intVar) 也可表示为 _。a. intvar = long; b. intVar(long) c. (long)intVar d. 以上都不是8. 静态数据成员的生存期_。a. 与整个程序相同 b.

4、不长于类的生存期 c. 取决于创建的对象数 d. 以上都不是9. 要让一个类中的所有对象具有共同的数据,请使用_。a. 常数成员变量 b. 私有数据成员 c. 静态数据成员 d. 以上都是10. 设置虚基类的目的是:a.简化程序 b.消除二义性 c.提高运行效率 d.减少目标代码三 、指出下列程序片段中的错误标号,写出正确语句或解释错在何处。(20分)int index=675; 1)*ptr=555; ptr是指向整数常量的指针ntptr=&another; ntptr是常量指针,不能指向别的的变量2)int arrp; 应改为:int *arrp;delete arrp; 应改为:dele

5、te arrp;3)return basedata;/ 在border_and_menu中引用basedata时产生二义性,应使用虚基类应改为:class border:virtual public window ;class menu: virtual public 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)下面程序为什

6、么会编译错误,并改正错误(提出解决办法)。 class window protected: int basedata;class border: public window ;class menu: public window ;class border_and_menu: public border, public menu public: int show() return basedata; 4)改正下面程序段中的错误,写出整个正确的程序段templatevoid print(T *a)coutan;void main( )const int x=0;coutyn;int y;x=5;i

7、nt* pp=&y;print(p);return 0;四 、写出下面程序的执行结果:(15分)1)#include using namespace std;class Afriend double count(A&);public:A(double t, double r):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);coutcount(x),count

8、(y)n;coutcount(x)n;return 0;执行结果:2)#include using namespace std;class Count private: static int counter; int obj_id; public: Count(); /constructor static void display_total(); /static function void display(); Count(); /destructor ; int Count:counter; /definition of static data member Count:Count() /

9、constructor counter+; obj_id = counter; Count:Count() /destructor counter-; coutObject number obj_id being destroyedn; void Count:display_total() /static function cout Number of objects created is = counterendl; void Count:display() cout Object ID is obj_idendl; int main(void) Count a1; Count:displa

10、y_total(); Count a2, a3,a4; Count:display_total(); a2.display(); a4.display(); return 0;3)#include using namespace std;class BASE char c; public: BASE(char n):c(n) virtual BASE()coutc; ; class DERIVED:public BASE char c; public: DERIVED(char n):BASE(n+1),c(n) DERIVED()coutc; ; int main(void) DERIVED

11、(X); return 0; 五、 程序填空:(10分)#include using namespace std;class A_(1)_char name80;public:A( _(2)_ ) _(3)_ ;class B_(4)_public:B(const char*n)_(5)_void PrintName( ) cout”name:”nameendl;void main( )B b1(“Ling Li”);b1.PrintName( ) ; /执行结果:name: Ling Li六、编程题(20分)1编写程序:定义抽象基类Shape,由它派生出五个派生类:Circle(圆形)、Sq

12、uare(正方形)、 Rectangle( 长方形)、Trapezoid (梯形)和Triangle (三角形),用虚函数分别计算各种图形的面积,并求出它们的和。要求用基类指针数组。使它的每一个元素指向一个派生类的对象。 注:主函数中定义如下对象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); 杭州电子科技大学学生考试卷(A)答案考试课程面向对象程序设计考试日期06年6月 日成绩课 程 号B1002100教 师 号任课教师

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

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