c398s99t

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

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

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 that after the code is executed, evaluating the expression "W contents" returns a string with (only) the numbers appearing in T.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern