Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Lecture 21 3/29/04 23:59
CS 100 1
3/29/04 CS 100 - Lecture 21 1
Lecture 21Lecture 21
Using & Managing Data:Using & Managing Data:SpreadsheetsSpreadsheets
(S&G, (S&G, §§§§11.111.1––11.2)11.2)
3/29/04 CS 100 - Lecture 21 2
Some Important Applications ofComputers
• Spreadsheets
• Databases
• Symbolic & numeric computation
• Networks
• Artificial Intelligence
Lecture 21 3/29/04 23:59
CS 100 2
3/29/04 CS 100 - Lecture 21 3
Relation to Algorithms
• Algorithmic problem solving is used inthese applications
• Algorithmic problem solving uses theseapplications
3/29/04 CS 100 - Lecture 21 4
Spreadsheet• Visual system for representing and
manipulating tabular data• Often used for:
– budgets & other financial data– grades
• Useful for keeping dependant dataconsistent
• Examples: Visicalc, Excel, Lotus 1-2-3
Lecture 21 3/29/04 23:59
CS 100 3
3/29/04 CS 100 - Lecture 21 5
Example Spreadsheet
RowCursor
Column Cells
3/29/04 CS 100 - Lecture 21 6
Cells• Each cell has a “name”
– e.g. “D2” is the cell in column D and row 2• Cells can contain character data
– e.g., names, column headings• Cells can contain numeric data in various
formats– e.g., integer, real, currency, date, time
• Cells can contain formulas– e.g., “D2*E2”
Lecture 21 3/29/04 23:59
CS 100 4
3/29/04 CS 100 - Lecture 21 7
Relative & Fixed Cell References• A name of the form “D2” is a relative
reference to the cell in column D and row 2• A name of the form “$D$2” is a fixed
reference to the cell in column D and row 2• When a formula is copied into another cell:
– the fixed references refer to the same cells asthey originally did
– the relative references refer to cells in the samerelative positions
3/29/04 CS 100 - Lecture 21 8
Example
• Suppose in G2 we have the formula:D2 * (1 + $C$8 / 100) * E2
• When we copy it to G3 it will be:D3 * (1 + $C$8 / 100) * E3
• When we copy it to G4 it will be:D4 * (1 + $C$8 / 100) * E4
• And so forth
Lecture 21 3/29/04 23:59
CS 100 5
3/29/04 CS 100 - Lecture 21 9
Run Excel Spreadsheet Example
3/29/04 CS 100 - Lecture 21 10
Beginning Spreadsheet
Lecture 21 3/29/04 23:59
CS 100 6
3/29/04 CS 100 - Lecture 21 11
Formula Entered in F2
3/29/04 CS 100 - Lecture 21 12
Result of Formula in F2
Lecture 21 3/29/04 23:59
CS 100 7
3/29/04 CS 100 - Lecture 21 13
Formula Copied into Rest ofColumn
3/29/04 CS 100 - Lecture 21 14
Result of Formulas in Column F
Lecture 21 3/29/04 23:59
CS 100 8
3/29/04 CS 100 - Lecture 21 15
Example Pie Chart of Column F
3/29/04 CS 100 - Lecture 21 16
Scatter Chart of Columns D vs. C
Lecture 21 3/29/04 23:59
CS 100 9
3/29/04 CS 100 - Lecture 21 17
Compute Sum of Column F
3/29/04 CS 100 - Lecture 21 18
Resulting Sum
Lecture 21 3/29/04 23:59
CS 100 10
3/29/04 CS 100 - Lecture 21 19
Formula for Projected Base PayIncrease
3/29/04 CS 100 - Lecture 21 20
Resulting New Pay
Lecture 21 3/29/04 23:59
CS 100 11
3/29/04 CS 100 - Lecture 21 21
Formula Relativized to Row 3
3/29/04 CS 100 - Lecture 21 22
Formula Relativized to Row 4
Lecture 21 3/29/04 23:59
CS 100 12
3/29/04 CS 100 - Lecture 21 23
Change Format of Column G
3/29/04 CS 100 - Lecture 21 24
Resulting Reformated Column G
Lecture 21 3/29/04 23:59
CS 100 13
3/29/04 CS 100 - Lecture 21 25
Insert Column for Merit Raises
3/29/04 CS 100 - Lecture 21 26
New Formula to Include MeritRaises
Lecture 21 3/29/04 23:59
CS 100 14
3/29/04 CS 100 - Lecture 21 27
Resulting Projected New Total
3/29/04 CS 100 - Lecture 21 28
Bar Chart of Old and New Pay
Lecture 21 3/29/04 23:59
CS 100 15
3/29/04 CS 100 - Lecture 21 29
Goal Seeking: Adjust Base Rateso Total = $12,000
3/29/04 CS 100 - Lecture 21 30
Calculated Base Rate to MeetGoal
Lecture 21 3/29/04 23:59
CS 100 16
3/29/04 CS 100 - Lecture 21 31
Computer Science Issues
3/29/04 CS 100 - Lecture 21 32
Update Strategies
• Reevaluate every cell• Reevaluate only those cells containing
formulas– works on small spreadsheets
• Reevaluate only those cells that depend onthe changed cell– problem: indirect dependencies (ripple effect)
Lecture 21 3/29/04 23:59
CS 100 17
3/29/04 CS 100 - Lecture 21 33
Indirect Dependency
3/29/04 CS 100 - Lecture 21 34
Result
Lecture 21 3/29/04 23:59
CS 100 18
3/29/04 CS 100 - Lecture 21 35
Problem of Indirect Dependencies• Suppose change D2
– Could look for all cells with a formula involving D2, andreevaluate those
– But suppose F9 depends on F2, and F2 depends on D2• Bad solution:
1. check all cells & update those directly dependant on D22. keep a list of them3. check all cells & update those directly dependent on those
in list4. keep a list of these, and return to (3)5. continue until there are no changes
3/29/04 CS 100 - Lecture 21 36
Better Solution• Keep with each cell a list of all other cells
directly dependant on it• Update this list whenever a formula is
changed• Whenever a cell’s value is changed:
– reevaluate all the cells that depend directly on it– reevaluate all the cells that depend directly on
those cells– and so forth
Lecture 21 3/29/04 23:59
CS 100 19
3/29/04 CS 100 - Lecture 21 37
Event-Driven Programming• Each cell contains either:
– data– or a formula, which is a little program– these formulas are interpreted directly (not compiled
into machine code)• Whenever a cell is modified:
– it creates an event– which may trigger other events– must end (no circular dependencies)
• There is no iteration except that provided throughthe built-in functions & tools