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

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

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern