smalltalk-project-sol

smalltalk-project-sol - OrderedCollection a2" s1 addAll...

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

View Full Document Right Arrow Icon
"------Part A-------" | a1 a2 s1 s2 s3 oddSum| oddSum := 0. "Initialize oddSum to zero" a1 := OrderedCollection new: 100. "Part i: declare a1 and a2 as ordered collections of size 100" a2 := OrderedCollection new: 100. s1 := SortedCollection new: 100. "part II: declare s1, s2, s3 as sorted collections of size 100" s2 := SortedCollection new: 100. s3 := SortedCollection new: 100. a1 := #(8 1 2 3 4 5 77 99 33 10 11 22 33 44 55 66 7 2 3 4 7 8 0). "part iii: Intialize a1 to the values indicated in the assignment" a1 size - 10 to: a1 size do: [:j| ( (a1 at: j) odd) ifTrue:[a2 add: (a1 at: j). oddSum := oddSum + (a1 at: j)]]. "part iv: take the last ten indexes of a1, and check to see if they are odd. If so, add their value to oddSum and put them in
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.

Unformatted text preview: OrderedCollection a2" s1 addAll: a1. "part v: Take all elements and put them in ascending order into s1" s2 := s1 reversed. "part vi: Take all elements in a1 and put them in descending order in s2" 1 to: s1 size do:[:i| s3 add: (s2 at: i) *(s1 at: i)]. "part vii: Sort in ascending order the ith component of s1 with the ith component of s2 and put in s3" "------Part B------" |A B C sum| A := Matrix new: n. "Declare Matrices A and B to be of size n X n" B := Matrix new: n. sum := 0. "Initialize sum to 0" "part i: Computer the matrix A X B" C := B preMultiplyByMatrix: A. "part ii: sum the elements of C, column order, and put them into sum" 1 to: C columnCount do:[:i| 1 to: C rowCount do:[:j| sum := sum + (C at:i at:j)]]....
View Full 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