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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 08/23/2011 for the course CSE 324 taught by Professor Soliman during the Spring '11 term at NMT.

Page1 / 2

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

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