=========================preview======================
(COMP151)[2009](s)final~tm_hky^_10140.pdf
Back to COMP151 Login to download
======================================================
COMP151: ObjectOrientedProgramming
SpringSemester2009
FinalExam
Instructor:Chi KeungTang
Thursday, May21,2009
4:30 C7:30pm
HALL

This is a CLOSED-BOOK-CLOSED-NOTES examconsisting of eight(8) problems. Followthein-structionscarefully.Pleasewritelegiblyinthespaceprovided. Keeptheexambooklet stapled.
KEY

Problem 1 MULTIPLE CHOICE 2 OBJECT CONSTRUCTION AND DESTRUCTION 3 INTERFACE VS IMPLEMENTATION 4 ABSTRACT BASE CLASS 5 STATIC CLASS 6 FUNCTION OBJECTS 7 CONTAINER CLASS 8 STL Total
Points your score
10
13
10
15
13
8
18
13
100
1 MultipleChoice
Selectthe answerby drawing a circle around theletter. (1pointfor eachcorrect answer; 0pointfor each empty orincorrect answer)
1. Youcanuseprivateinheritance
(a) tobeabletoinherit andthusaccessprivatevariablesinthebaseclass
(b) toprovideanewinterface,thushidingtheinterface of thebaseclass
(c)
tomakethecodemoreef.cient asall referencesarelocal

(d)
all of the above


2. Templatecodecanbeprecompiledlikeregularcodecan
(a) True

(b) False
3. Apurevirtualfunctionexistsifand onlyif thepertinent classisanabstractbaseclass

(a) True
(b) False
4. Inheritance usuallyrepresents
(a)
aggregation relationship

(b)
has-a relationship



(c) is-a relationship
(d) association relationship
5. Codereuseinobject-orientedprogrammingmeans
(a)
Copy/Pastecodefromapreviousproject/student.

(b)
Usingcodefound ontheweb, with slight modi.cations.

(c)
Usingcodefromabook, with slight modi.cations.



(d) Reusingfull classde.nitions without any modi.cation.
6. Slicinginobject-orientedprogrammingis
(a) whathappenswhenyouorderpizza

(b) whathappens whenyou assign an object of aderived type to a variable of thebase class
(c)
whathappenswhenyouassignanobject of abasetypetoavariableofthederived class.

(d)
none of the above.


7. TogettruepolymorphisminC++youneed
(a) object and virtualfunctions

(b) pointers to objects andvirtualfunctions
(c)
pointerstoobjectsbutnot virtualfunctions

(d)
none of the above


8. Apurevirtualfunction
(a)
amethodde.ned withbody of =0

(b)
away togetpolymorphisminC++

(c)
may makethecodelessef.cientinrun-time.



(d) all of the above
9. Anabstractbaseclassisaclassde.ned
(a) as class ClassName { ... } = 0;

(b) with atleast onepure virtualfunction
(c)
with atleast onemembervariabledeclaredpurevirtual

(d)
all of the above


10. Protectedmemberof abaseclassbecomes wheninherited viapublicinheritance.
(a) Public

(b) Protected
(c)
Private

(d)
all of the above




2 ObjectConstructionandDestruction

Write the outputof thefollowing shortprograms onpage7 of the exam.
//---------------------program 1 : begin-----------------------#include <iostream>

class Base {

public:
Base (): x(0), y(0) { cout << "Base" << endl; }
Base (int i): x(10), y(10)

{cout<<"Base"<<i<<""<<x<<"" <<y<<endl;}
.Base () { cout << "Destr