CPS 6, Ramm - Spring 2000 - 3/31/00 #27
- Announce
- Exam ...
- Makeup Class Tomorrow (Saturday) 2:10
Chap 10. Recursion, Lists, & Matrices
- Scope vs Lifetime (Finish Up)
- Lifetime
- Normal (automatic)
- Global
- Static
- Dynamic (new, delete)
- Related Issues
- Initialization
- Shadowing
- Nested Scope
- Scope Resolution Operator
- Two Dimensional Arrays
- Conceptually like vectors
- Behaves like vector of vectors
- Matrix Class Definition Syntax
- tmatrix<type> name;
- tmatrix<type> name(int rows, int cols);
- tmatrix<type> name(int rows, int cols, type fill);
- Matrix Creation and Use
- tmatrix<int> data(2,6);
- ....0..1..2..3..4..5.
- : +--+--+--+--+--+--+
- 0 | ?| ?| ?| ?| ?| ?|
- : +--+--+--+--+--+--+
- 1 | ?| ?| ?| ?| ?| ?|
- : +--+--+--+--+--+--+
-
- data[1][4] = 21; data[0][1] = 13;
- ....0..1..2..3..4..5.
- : +--+--+--+--+--+--+
- 0 | ?|13| ?| ?| ?| ?|
- : +--+--+--+--+--+--+
- 1 | ?| ?| ?| ?|21| ?|
- : +--+--+--+--+--+--+
-
- int j, k;
- for (j=0; j<2; j++)
- for (k=2; k<6; k++)
- { data[j][k] = j + k; }
- ....0..1..2..3..4..5.
- : +--+--+--+--+--+--+
- 0 | ?|13| 2| 3| 4| 5|
- : +--+--+--+--+--+--+
- 1 | ?| ?| 3| 4| 5| 6|
- : +--+--+--+--+--+--+
-
- int j, k;
- for (int j=0; j<2; j++)
- for (int k=0; k<6; k++)
- { cout << data[j][k] << " "; }
-
- ? 13 2 3 4 5 ? ? 3 4 5 6
Matrix Initialization
- Use Constructor
-
tmatrix<int> data(4, 3, -1);
-
tmatrix<string> words(2, 3, "yes");
- Use Client Program
A Character Plotting Program
- Use matrix like a canvas
- "Plot" prints out matrix
-
charplot
Designing a Character Plotting Class