Você está na página 1de 16

FINAL EXAMINATION

First Semester

Course No. M206

Course Name: Computing: An Object-Oriented Approach

Date: 15 / 1 / 2007

Time: 6 - 9 hrs. 3 hours

Section Number:

Question Question's Mark Student's Mark Tutor's Signature


No.
Part 1-A 10
Part 1-B 50
Part 2 48
Part 3 42
Total 150
FORM A

General Instructions

The exam consists of three parts. The first part consists two sections. Section A
consists of 10 True/False questions. Each question is worth 1 mark. Section B
consists of 25 multiple choice questions. Each question is worth 2 marks. You should
answer all questions of part 1. You must answer this question in the answer sheet
given in page 8.

The second part consists of 8 short questions. Each question is worth 6 marks. You
should answer all questions of part 2.

The third part consists of 3 long questions. Each question is worth 21 marks. You
should select two of the three questions. Read the three questions first before
deciding which ones to answer.

This Exam is consists of a total of 150 Marks

2
FORM A
Part 1
A) Instructions: Answer the following 10 True/False questions and fill your answers in
the table of the Answers Sheet given at the end of Part 1. [10 marks]

1. When a method is defined for a subclass, it immediately becomes available to all instances
of that class as well as all instances of its superclass.

2. The messages left and right in the Frog and Toad classes are examples of
polymorphic messages.

3- In OOP superclass has more attributes than subclass.

4. A user interface designer should ignore the age and the cultural background of likely users.

5. String literals are considered to be references to objects.

6. Encapsulation provides protection for the integrity of the objects.

7- The protocol consists only from the messages that change the object state.

8. Character objects are specified in the Smalltalk system by prefixing the character with the $
(dollar sign) symbol.

9. The message ( frog1 sameColourAs: frog2 ) is an example of objects collaborating.

10. As with all other concrete classes, instances of Fraction class can be created using the
new class message.

B) Instructions: Answer the following 25 multiple choice questions and fill your answers
in the table of the Answers Sheet given at the end of Part 1. [50 Marks]

1- A piece of information or property needed by the object to define its state, is called:
a. Attribute
b. Class
b. Behavior
c. Object

2. "The provision of a barrier protecting the information owned by an object". This refers to
which object oriented concept?
a. Polymorphism
b. Inheritance
c. Protection
d. Encapsulation

3
3- The answer message for the following expression series:
5 + 4.
6/2
is:
a. 3
9
b. 9
3
c. 3
d. 9

4- The message answer for the following expression:


( toto position:3 ) colour:purple
is:
a. toto
b. purble
c. 3
d. Error : message not understand #colour

5. Consider the following method:

height
"Answer the height of the receiver."

^height

In the expression ^height, height is:


a. Message selector
b. Instance variable
c. Local variable
d. Temporary variable

6.Which of the following expressions will answer '20'?


a. 3 + 2 * 4 printString
b. (3 + 2 * 4)printString
c. (3 plus: 2 * 4)printString
d. All of the above

4
7.What is the expected answer of the following method which is added to the Account class
protocol?
aMethod
"Comment omitted"

self balance:500;overLimit:3000;holder:'Rami'.
self holder:(self holder, ' Ahmad')

a. The overLimit attribute value.


b. The balance attribute value.
c. 'Rami Ahmad'
d. The receiver object.

8- In the message myCar drive:80 over:100


drive: over: is considered as:
a. Keyword
b. Message selector
c. Message
d. a+b

9. In the message expression turtle crawl:Left by:3 , the message selector is:
a. crawl:Left by:3
b. crawl:by:
c. crawl:,by:
d. Left,3

10. The message answer of the following expression series is:


toad1 := Toad new.
taod1 position:1
a. toad1
b. An instance of class Toad (position 1, colour Brown)
c. 1
d. nil

11. Which part of the system remains unchanged irrespective of whatever user interface we
use?
a. Graphical Interface
b. Textual Interface
c. Domain model
d. All the above

5
12. What type of error is present in the following fragment of code:

checkPosition
"If the current position of the receiver is equal to its maxPosition, answer true, else
answer false."
(self position = self maxPosition)
ifTrue: [^false]
ifFalse: [^true]

a. Syntax
b. Semantics
c. Logical
d. There is no error in the code

13. Which of the following methods is not in the protocol of class Set?
a. size
b. remove:
c. add:
d. at:put:

14. If a = #red, b = #red, c = ‘red’, d = ‘red’, which of the following statements is false?
a. a = b
b. a = = b
c. c = d
d. c = = d

15- The message:


myCar model:2006
is considered as:
a. Getter message
b. Setter message
c. Wrong message
d. Non of the above

16. The message answer of confirm: is a ...................


a. ByteString
b. nil
c. Boolean
d. SmalInteger

17. What is the drawback of compiling the source code into a machine code directly?
a. The compiled code is harder to debug.
b. The compiled code cannot be translated back again.
c. The compiled code is not portable to other machine architectures.
d. The virtual machine can't read the compiled code.

6
18. The scope of a class variable is:
a. The class and instance methods of the class
b. The class and instance methods of the subclasses
c. Instances of the class and instances of any subclasses
d. All the above

19. The message answer of printHierarchy is a ................


a. OrderedCollection
b. List
c. Set
d. ByteString

20. A collection where all additions to the collection are made at the end, but
all deletions are made at the beginning is called:
a. Queue.
b. Stack.
c. Array.
d. Sorted Collection.

21. Which of the following will be included in the ordered collection returned from evaluating the
expression: LimitedPrecisionReal allSubclasses
a. SmallInteger
b. LargeInteger
c. Integer
d. Float

22.To evaluate an expression or expression series a fixed number of times you should use:
a. timesRepeat:
b. whileTrue: or whileFalse:
c. ifTrue:ifFalse:
d. Do:

23 n instances of OrderedCollection class, the order is determined by


The sequence in which the objects are added to the collection.
The messages used to add the objects to the collection.
Both “a” and “b” above.
None of the above

24. Consider a set with 4 elements: 3, 5, 7, 8. If we add two elements: 4 and 8 then the set:
a. gets a new size of 5 elements: 3, 5, 7, 8, 4.
b. gets a new size of 6 elements: 3, 5, 7, 8, 4, 8.
c. gets a new size of 2 elements: 4, 8.
d. will not be changed since you can't add elements to sets.

25. The type of software testing that depends only on the specification of the software is called:
a. Black-box testing
b. Implementation-based testing
c. White-box testing
d. Gray-box testing

7
FORM A

Answer Sheet of Part 1

‫لن يصحح هذا الجزء من المتحان ما لم تمل هذه الصفحة‬

Part (1) A Part (1) B


Question Question Answer
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

8
FORM A
Part 2(8 questions) [48 marks]
Instructions: Answer the following 8 short questions. Each question is worth 6 marks.
You should answer all questions of Part 2.

Q1) Define the following terms


User interface:

Affordance:

Internet:

Domain model:

Q2) Consider the following object-interaction diagram where the variables toad1 and toad2 both
reference instances of the Toad class.

9
a. Extract the expression series for the object-interaction diagram above.

.........................................................................................................................................

.........................................................................................................................................

.........................................................................................................................................

.........................................................................................................................................

b. Write the following expression series as a single nested expression.


var1 := account1 balance.
var2 := var1+500.
account2 balance: var2
.........................................................................................................................................
.........................................................................................................................................
.........................................................................................................................................

Q3) For each of the following message expressions, write down the required information. Note that
frog1 is in its initial state.(position -->1, colour -->Green)

a. frog1 position

Receiver: ........................................................................................................................
Message: ........................................................................................................................
Message selector: ............................................................................................................
Argument: .......................................................................................................................
Message answer: .............................................................................................................
Textual representation of the message answer: ...................................................................
.......................................................................................................................................

b. ((frog1 home position)~=1) ifFalse:[frog1 brown. frog1 left]


The receiver object evaluated to: .....................................................................................
Message: .......................................................................................................................
Message selector: ..........................................................................................................
Argument: .....................................................................................................................
Message answer: ...........................................................................................................
Textual representation of the message answer: .................................................................
......................................................................................................................................

10
c. Dialog warn:'Good luck'

Receiver: ....................................................................................................................

Message: ....................................................................................................................

Message selector: ........................................................................................................

Argument(s): ...............................................................................................................

Message answer: .........................................................................................................

Textual representation of the message answer: ...............................................................

...................................................................................................................................

Q4) Given the following expression series:


| x y |
x := 1.
y := 9.
[y >= 3] whileTrue:[x := x + y.
y := y - 3]

(a) What are the values of x and y at the end of the first iteration?

x has the value:

y has the value:

(b) What are the values of x and y at the end of the last iteration?

x has the value:

y has the value:

Q5) Draw the class hierarchy diagram that represents the relation between the Shape,
Rectangle, Circle, Square, Four_edged_shape. The Four_edged_shape is a template class
for objects of shapes that have four edges.

11
Q6) (a) Define the following terms:

.....................................................................................................................
Affordance:
.....................................................................................................................

.....................................................................................................................
Usability:
.....................................................................................................................

(b) Name two requirements of the user needs analysis:

1. ......................................................................................................................................

2. ......................................................................................................................................

Q7) (a) Briefly explain the difference between abstract class and concrete class giving one example on
each one.

.............................................................................................................
Abstract class:
.............................................................................................................

Example: .............................................................................................................

.............................................................................................................
Concrete class:
.............................................................................................................

Example: .............................................................................................................

(b) How many concrete classes are there to represent integer numbers? Briefly explain why?

..........................................................................................................................................

..........................................................................................................................................

12
Q8) (a) Briefly explain the difference between abstract methods and base methods giving one example
on each one.

.............................................................................................................
Abstract method:
.............................................................................................................

.............................................................................................................

.............................................................................................................

Example: .............................................................................................................

.............................................................................................................
Base method:
.............................................................................................................

.............................................................................................................

.............................................................................................................

Example: .............................................................................................................

(b) Briefly explain the difference between instance variables and class variables in terms of
scope.

............................................................................................................
Instance variable:
............................................................................................................

............................................................................................................

Class variable: ............................................................................................................

............................................................................................................

............................................................................................................

13
FORM A

Part 3(Answer two long questions) [42 marks]


Instructions: Select two of the following three long questions. Read the three
questions first before deciding which ones to answer. Each question is worth 21
marks.

Question 1: (a) For the sentences in the table below, write down the most appropriate message
selector from the protocol of the Dialog class to be used.

Sentences Appropriate message selector


1. A student is to be prompted via a dialogue box to
input the code of the course they are studying. The most ....................................................
likely response is M206, so this is provided as the
default.
2. A user has selected a file copy command on their
computer, but the system discovers that a file with that
name already exists in the destination folder. A ....................................................
dialogue box is to be used to ask the user whether they
wish to overwrite that file.
3. A dialogue box is required to inform a user that some
operation has been successfully completed. ....................................................

(b) Write expression series to calculate the average temperature for a week (7 days) according to
the following specifications:
1. Prompt the user to enter each day temperature, one at a time, in a dialog box.
2. Check that the temperature entered by the user is between 0 and 50 inclusive, otherwise,
display a dialogue box with the message 'Invalid temperature', and exit.
3. Calculate the average temperature for the week and display it in a dialogue box.

..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................

14
Question 2: (a) Quizzes grades for three students are to be stored in arrays of numbers. Write an
expression series to create three arrays: student1Quizzes, student2Quizzes &
student3Quizzes), each consists of three elements. Then use at:put: (or any other way
you've learned) to add the data of the 3 quizzes in the corresponding array according to the table
below:

Array Quiz1 Quiz2 Quiz3


student1Quizzes 80 90 77
student2Quizzes 95 95 99
student3Quizzes 72 60 55

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

(b) Write expression series to create a dictionary studentDictionary using students' names
as keys and the quizzes arrays as the values according to the table below:

Key Value
'Ahamd' student1Quizzes
'Omar' student2Quizzes
'Sami' student3Quizzes

..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................

Question 3:

15
1. Suppose that ‘foo’ is an instance of class ‘Aliens’ as indicated in the following
variable reference diagram. Debug the following piece of code, find the four
errors and correct them without deletion.

Class: Aliens

colour Black
foo height 10
weapon ‘bombs’

Protocol: colour, colour:, height, height:,


weapon, weapon:

Zoo: = new aliens.


Zoo colour: foo colour.
Zoo height: 15
Zoo weapon: (‘bazooka ’ concatenate ‘and ’ concatenate foo weapon).

..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................

2. Write a piece of code that will assign a grade to a student, based on his final
score. The code reads the score from a dialog and returns the grade. Assume the
following grade distribution table:

Grade Score range


A 90-100
B 80-89
C 70-79
D 60-69
F 0-59
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................

16

Você também pode gostar