Lecture 21 Some Important Applications of Computers 3/29/04 23:58

advertisement
Lecture 21
3/29/04 23:58
Some Important Applications of
Computers
Lecture 21
• Spreadsheets
• Databases
Using & Managing Data:
Spreadsheets
(S&G, §§11.1
–11.2)
§§11.1–
• Symbolic & numeric computation
• Networks
• Artificial Intelligence
3/29/04
CS 100 - Lecture 21
1
2
• Visual system for representing and
manipulating tabular data
• Often used for:
• Algorithmic problem solving is used in
these applications
– budgets & other financial data
– grades
• Algorithmic problem solving uses these
applications
CS 100 - Lecture 21
CS 100 - Lecture 21
Spreadsheet
Relation to Algorithms
3/29/04
3/29/04
• Useful for keeping dependant data
consistent
• Examples: Visicalc, Excel, Lotus 1-2-3
3
3/29/04
CS 100 - Lecture 21
4
Cells
Example Spreadsheet
• 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
Column
CS 100
• Cells can contain formulas
Row
Cursor
3/29/04
– e.g., integer, real, currency, date, time
Cells
– e.g., “D2*E2”
CS 100 - Lecture 21
5
3/29/04
CS 100 - Lecture 21
6
1
Lecture 21
3/29/04 23:58
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:
• 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
– the fixed references refer to the same cells as
they originally did
– the relative references refer to cells in the same
relative positions
3/29/04
CS 100 - Lecture 21
Example
7
3/29/04
CS 100 - Lecture 21
8
Beginning Spreadsheet
Run Excel Spreadsheet Example
3/29/04
CS 100 - Lecture 21
9
3/29/04
Formula Entered in F2
3/29/04
CS 100
CS 100 - Lecture 21
CS 100 - Lecture 21
10
Result of Formula in F2
11
3/29/04
CS 100 - Lecture 21
12
2
Lecture 21
3/29/04 23:58
Formula Copied into Rest of
Column
3/29/04
CS 100 - Lecture 21
Result of Formulas in Column F
13
Example Pie Chart of Column F
3/29/04
CS 100 - Lecture 21
3/29/04
CS 100
CS 100 - Lecture 21
14
Scatter Chart of Columns D vs. C
15
3/29/04
Compute Sum of Column F
3/29/04
CS 100 - Lecture 21
CS 100 - Lecture 21
16
Resulting Sum
17
3/29/04
CS 100 - Lecture 21
18
3
Lecture 21
3/29/04 23:58
Formula for Projected Base Pay
Increase
3/29/04
CS 100 - Lecture 21
Resulting New Pay
19
Formula Relativized to Row 3
3/29/04
CS 100 - Lecture 21
CS 100
CS 100 - Lecture 21
CS 100 - Lecture 21
20
Formula Relativized to Row 4
21
Change Format of Column G
3/29/04
3/29/04
3/29/04
CS 100 - Lecture 21
22
Resulting Reformated Column G
23
3/29/04
CS 100 - Lecture 21
24
4
Lecture 21
3/29/04 23:58
New Formula to Include Merit
Raises
Insert Column for Merit Raises
3/29/04
CS 100 - Lecture 21
25
Resulting Projected New Total
3/29/04
CS 100 - Lecture 21
CS 100
CS 100 - Lecture 21
CS 100 - Lecture 21
26
Bar Chart of Old and New Pay
27
Goal Seeking: Adjust Base Rate
so Total = $12,000
3/29/04
3/29/04
3/29/04
CS 100 - Lecture 21
28
Calculated Base Rate to Meet
Goal
29
3/29/04
CS 100 - Lecture 21
30
5
Lecture 21
3/29/04 23:58
Update Strategies
• Reevaluate every cell
• Reevaluate only those cells containing
formulas
Computer Science Issues
– works on small spreadsheets
• Reevaluate only those cells that depend on
the changed cell
– problem: indirect dependencies (ripple effect)
3/29/04
CS 100 - Lecture 21
31
3/29/04
Indirect Dependency
3/29/04
CS 100 - Lecture 21
33
Suppose change D2
–
–
•
Could look for all cells with a formula involving D2, and
reevaluate those
But suppose F9 depends on F2, and F2 depends on D2
Bad solution:
1. check all cells & update those directly dependant on D2
2. keep a list of them
3. check all cells & update those directly dependent on those
in list
4. keep a list of these, and return to (3)
5. continue until there are no changes
3/29/04
CS 100
CS 100 - Lecture 21
32
Result
3/29/04
35
CS 100 - Lecture 21
34
Better Solution
Problem of Indirect Dependencies
•
CS 100 - Lecture 21
• 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
3/29/04
CS 100 - Lecture 21
36
6
Lecture 21
3/29/04 23:58
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 through
the built-in functions & tools
3/29/04
CS 100
CS 100 - Lecture 21
37
7
Download