c398s99t

c398s99t - CSc 398 Mid-Term Test 19 March 1999 Page 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 398 Mid-Term Test 19 March 1999 Page 1 >>>>>>>>>>>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. (15 points) Assume that T is an array of numbers. Write three different code fragments, each using a different collection method, to find the sum of the squares of the numbers in T. T:=0. S do:[:each| T:=T+each squared] T:=0. S with:S do:[:i :j|T:=i*j+T] S inject:0 into:[:tot :each| tot+each squared] 2. (10 points) Assume that T is an array of points. Write code which returns the points in an array sorted by the squared Euclidean distance of the points from the origin. (The squared Euclidean distance of (x,y) from the origin is x*x + (y*y). Thus, the squared Euclidean distance of (2,3) is 13, the squared Euclidean distance of (3,3) is 18, etc.) (T asSortedCollection sortBlock:[:a :b| a x squared + a y squared < (b x squared + b y squared)]) asArray 3. (15 points) Assume that T is an array with a variety of entries (e.g., strings, points, numbers, characters, etc.). Let R:=ReadStream on:T and W:=WriteStream on:String new. Write code such
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

c398s99t - CSc 398 Mid-Term Test 19 March 1999 Page 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online