Programming Assignment #1: Spreadsheets with Formulas

Due 4/23 in class

Last quarter, students for their second programming assignment created spreadsheets that could:

Our user now knows more Smalltalk, and she needs more functionality. Now, instead of preset sum or average, the user wants to be able to define any formula she'd like -- at least, any formula that can be used with a inject:into: (p. 138 of Hopkins & Horan). The user still doesn't feel that they need more than single dimension spreadsheets, so cells are specified by integers. However, now a cell can either be (a) a value or (b) the value of another spreadsheet. The user would like to use these spreadsheets with Workspace code that looks like this:

| ss1 ss2 ss3 ss4|
ss1 := Spreadsheet startWith: 0 inFormula: [:total :i| total + i]
withLabel: '[:total :i| total + i]'.  "Sum the cells"
ss1 cell: 1 put: 15.     "Puts 15 into cell 1"
ss1 cell: 2 put: 30.
ss1 cell: 3 put: 75.2.
Transcript cr; show: ss1 value printstring.  "Prints the sum (120.2) to the Transcript"
Transcript cr; show: (ss1 cell: 1) printstring.	"Prints 15 to the Transcript"

ss2 := Spreadsheet startWith: 1 inFormula: [:total :i| total + 1]
withLabel: '[:total :i| total + 1]'.  "Count the cells
ss2 cells: #(24 76.4 19 37 89).  "Fill five cells of the spreadsheets with these values"
Transcript cr; show: ss2 value printstring. "Prints the number of cells (5) to the Transcript"

ss3 := Spreadsheet startWith: 0 inFormula: [:total :i| total + i]
withLabel: '[:total :i| total + i]'.  "Sum the cells"
ss3 cells: #(24 76.4 19 37 89).  "Fill five cells of the spreadsheets with these values"
Transcript cr; show: ss3 value printstring. "Prints the sum of cells to the Transcript"

ss4 := Spreadsheet startWith: 1 inFormula [:total :i| i / total]
withLabel: '[:total :i| i / total]'. "Divide the last number by the first number"
ss4 cell: 1 putRef: ss2.
ss4 cell: 2 putRef: ss3.
Transcript cr; show: ss4 value printstring. "Prints the average of cells #(24 76.4 19 37 89) to the Transcript"

Special notes to consider when designing and implementing the Spreadsheet class.

HIC for Spreadsheets

The user is pretty comfortable entering Smalltalk code, so it's okay to always use cell:put:, cell:putRef: and cells: messages for entering values into cells. However, the user does want to see:

In the above example, the user would expect to see a window for each of the four spreadsheets. The window should open with the same message that created the spreadsheet.

Resources

STABLE Projects on Program 2 from last quarter: Janak's and Salman's

Discussion from last quarter on Programming Assignment #2

Discussion for this quarter about Programming Assignment #1