View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Fall 2004 Quiz 1 Solutions

direct any questions to ellie@cc

Recalling that all computations in Squeak are defined as a series of messages sent to objects, explain each of the following statements. In each case, list the messages sent in the order that they are sent and provide the information about each message requested in the table. Don't forget that the result of one message can be used as the receiving object of a subsequent message

grading: 1 point each line, for correctness and ordering. so 3 points for #1 and 4 points for #2


-20abs 20

Transcript show: 'The next value is: ', (x+1)printString "assume x=5"

6printString '6'
'The next value is: ','6''The next value is: 6'
Transcriptshow'The next value is: 6''The next value is: 6' is displayed on the transcript

Write two different versions of Smalltalk code to create a 4 element array containing the values 10, 20, 30 and 40.

grading: 3 points total: 1 point for each of the 2 ways. 1 point split between the two ways for syntax. e.g. #(10,20,30,40) counts 1 point for a way to create an array, but looses 1/2 point for syntax (no commas).

anArray := #(10 20 30 40).

anArray := Array new: 4.
anArray at: 1 put: 10.
anArray at: 2 put: 20.
anArray at: 3 put: 30.
anArray at: 4 put: 40.

anArray := Array with: 10 with: 20 with: 30 with: 40.

anArray := Array new: 4.
1 to: 4 do: [:index|anArray at: index put (index 10).].

Link to this Page