Quiz11

Quiz11 - greater than zero numbers found in A into a variable S(i.e S will equal 212(10 pts |A S| A:= OrderedCollection new:5 A:=(21-4-11 10 191

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE324 Quiz #11 (30 pts) Name:_____ KEY ____ 1) Given the following Smalltalk code: |o a b v quad| quad := [v := 0.]. o := SortedCollection new:30. b := OrderedCollection new:100. a :=#(-10 -20 10 -3 5 -9 -1 -100 34 190 -105 33 -30 -310 444). quad value. a collect: [:j| (j < 10 negated) ifTrue:[ b add:j. v := v + j]] from:2 to:12. o addAll: b. o sortBlock:[:x :y| y <= x]. What is the value of : a) v:_____ -225 _______________________________________ (2 pts) redundant b) a: #(-10 -20 10 -3 5 -9 -1 -100 34 190 -105 33 -30 -310 444) __ (2 pts) c) b: an OrderedCollection(-20 -100 -105) ______________ (3 pts) d) o: a SortedCollection(-20 -100 -105) ________________ (3 pts) 2) Write a Smalltalk code that initializes an ordered collection variable A to have the value (21 -4 -11 10 191); then sum all odd and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: greater than zero numbers found in A into a variable S . (i.e., S will equal 212) (10 pts) |A S| A := OrderedCollection new:5. A:= #(21 -4 -11 10 191). S:= 0. A do:[:i| (i odd) & (i >0 ) ifTrue: [S := S + i]]. S. 212 A collect :[:i| (i odd) & (i >0 ) ifTrue: [S := S + i]]. “will also wor” Extra Credit: (10 pts extra, no deduction for a wrong answer, but it must be complete answer no partial credits!). 3)Write a Smalltalk code that defines a (4 by 4) matrix A and initializes all of its elements to the value of 2; then multiplies A by itself and stores the results back in A. (10 pts) |A| A:= Matrix new:4 element:2. “create A 4X4 matrix with all elements of 4.” Also correct to write” A;= Matrix rows:4 columns:4 element:2. A := A preMultiplyByMatrix: A. “multiply A by itself”...
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.

Ask a homework question - tutors are online