面向对象的程序设计_第1页
面向对象的程序设计_第2页
面向对象的程序设计_第3页
面向对象的程序设计_第4页
面向对象的程序设计_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、中国海洋大学 20072008学年 第2学期 期末考试试卷信息科学与工程学院面向对象的程序设计课程试题(A卷)优选专业年级 学号 姓名 授课教师 座号 -装-订-线- 共3页 第1页考试说明:本课程为闭卷考试,可携带 文具(或本课程为开卷考试,可携带 文具和 资料),满分为: 100分。 题号一二三四五六七总分得分一、(20 points)Multiple Choice1. is not a member function of a class.(A) Constructor (B) Destructor (C) Friend function2. is the earliest ancest

2、or of object-oriented programming languages.(A) C+ (B) Simula 67 (C) FORTRAN3. To assert that one class is a of another is to simply say it was built using inheritance. (A) subclass (B) subtype4. may be accessed directly through the instances of child class within the external function. (A) private

3、members in the parent class (B) protected members in the parent class (C) public members in the parent class5. To create an instance, the template argument must be associated with a . (A) type (B) number (C) character6. C+ has the space allocation strategy.(A) maximum static (B) minimum static (C) d

4、ynamic 7. In allocation, the amount of space required is determined at run-time .(A) stack-based (B) heap-based8. “<<” can be overloaded as function. (A) friend (B) member9. A is invoked automatically when an object is deleted.(A) constructor (B) destructor10. Overriding is resolved at time.(A

5、) run (B) compile 授课教师命题教师或命题负责人签字 年 月 日院系负责人签字年 月 日共3页 第2页二、(10 points)True/False( ) 1. Inheritance represents the has-a relationship. ( ) 2. All the member functions in the friend class are friend members for current class.( ) 3. Shadowing only occurs in the context of the parent/child relationshi

6、p.( ) 4. A type name can be used as an operator. ( ) 5. In object-oriented languages, the term polymorphism means there is one meaning and many different names.三、(16 points)Fill in the following blanks and write out the running results of function main.Suppose: (1) class Y is a private subclass of c

7、lass X;(2) class Z is a public subclass of class Y;(3) a, b and c are encapsulated data members.#include<iostream> class Xpublic: X(int x) a=x; void showX( )cout<<“a=”<<a<<endl; int a;class Y: private Xpublic: Y b=y;void showY( ) cout<<"a="<<a<<end

8、l; cout<<"b="<<b<<endl; X:showX( );private: int b;class Z: public Ypublic: Z c=z; void showZ( ) showY( ); cout<<"c="<<c<<endl;private: int c;int main( )Z obj(10, 20, 30); obj.showX( ); obj.showY( ); obj.showZ( ); return 0; 中国海洋大学 20072008学年 第2学

9、期 期末考试试卷信息科学与工程学院面向对象的程序设计课程试题(A卷)优选专业年级 学号 姓名 授课教师 座号 -装-订-线- 共3页 第3页四、(14 points)Please write out the class definitions of Student and GraduateStudent.五、(20 points) Please write out the class definitions of Shape, Cube, Sphere and draw the diagram of inheritance hierarchy.六、(20 points)Please imple

10、ment the addition of two matrices, which has 2 rows and 3 columns.中国海洋大学 20072008学年 第2学期 期末考试试卷信息科学与工程学院面向对象的程序设计课程试题(B卷)优选专业年级 学号 姓名 授课教师 座号 -装-订-线- 共3页 第1页考试说明:本课程为闭卷考试,可携带 文具(或本课程为开卷考试,可携带 文具和 资料),满分为: 100分。 题号一二三四五六七总分得分一、(12 points)Multiple Choice1. is not a member function of a class.(A) Const

11、ructor (B) Destructor (C) Friend function2. is the earliest ancestor of object-oriented programming languages.(A) C+ (B) Simula 67 (C) FORTRAN3. is a valid identifier in C+.(A) 2006Year (B) E-mail (C) idNumber# (D) _age4. Storage for variable is allocated at block entry and destroyed at block exit.(

12、A) global (B) static (C) automatic5. may be accessed directly through the instances of child class within the external function. (A) private members in the parent class (B) protected members in the parent class (C) public members in the parent class 6. is a manipulator used to determine the number o

13、f character positions in which to display a right-justified number.(A) setw (B) setprecision (C) fixed (D) endl 二、(12 points)True/False( ) 1. Composition represents the is-a relationship. ( ) 2. If the parent class is virtual , there is only one copy in the child classes.( ) 3. Destructors can be ov

14、erloaded. ( ) 4. Shadowing only occurs in the context of the parent/child relationship. ( ) 5. Overloading is resolved at run time.( ) 6. The implementation of dynamic polymorphism relies on virtual functions.授课教师命题教师或命题负责人签字 年 月 日院系负责人签字年 月 日共3页 第2页三、(16 points)Please fill in the following blanks a

15、nd write out the running results of function main:#include<iostream>using namespace std;class Basepublic: Base(int sa) a=sa; cout<<“Constructing Base, a=”<<a<<endl;private: int a;class Base1:virtual public Basepublic: Base1(int sa,int sb): b=sb; cout<<“Constructing Base

16、1, b=”<<b<<endl;private: int b;class Base2:virtual public Basepublic: Base2(int sa,int sc): c=sc; cout<<“Constructing Base2, c=”<<c<<endl;private: int c;class Derive: public Base1, public Base2public:Derive(int sa,int sb, int sc,int sd): d=sd;cout<<“Constructing D

17、erive, d=”<<d<<endl;private: int d;int main( )Derive obj(2, 4, 6, 8); return 0;中国海洋大学 20072008学年 第2学期 期末考试试卷信息科学与工程学院面向对象的程序设计课程试题(B卷)优选专业年级 学号 姓名 授课教师 座号 -装-订-线- 共3页 第3页四、(20 points)Please implement the addition of two fractional values.五、(20 points)Please write out the class definition of PartTime _Student and draw the diagram of inheritance hierarchy.六、(20 points)Class person h

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论