CPS 6, Ramm - Summer Semester I - 6/15/99 #18
- Announce
- Coin Toss for Random Quiz #8
- Hour Test Tomorrow, Review Today
Chap 8. Arrays, Data, & Random Access
- WordList Class
- List of Unique Words
- Update with next word
- Print Unique List
-
allword3.cc
- Binary Search
- Telephone Book Analogy
- Requires Sorted Lists
-
| list size | binary search | sequential search
|
| 1 | 1 | 1
|
| 10 | 4 | 10
|
| 1,000 | 11 | 1000
|
| 5,000 | 14 | 5000
|
| 100,000 | 18 | 100,000
|
| 1,000,000 | 21 | 1,000,000
|
-
binsearch
- Keeping a Sorted List
- WordList Class Improved
- Keep Track of:
- Unique Words AND
- Word Frequency
- Use Vector of Structs
- Incorporate Binary Search
- Deal with Case and Punctuation
-
allword4
- Two Dimensional Arrays
- Conceptually like vectors
- Behaves like vector of vectors
- Matrix Class Definition Syntax
- Matrix<type> name;
- Matrix<type> name(int rows, int cols);
- Matrix<type> name(int rows, int cols, type fill);
- Matrix Creation and Use
- Matrix<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
-
Matrix<int> data(4, 3, -1);
-
Matrix<string> words(2, 3, "yes");
- Use Fill Member Function
-
Matrix<int> data(4, 3);
-
data.Fill(-1);
-
Matrix<string> words(2, 3);
-
words.Fill("yes");
- Use Client Program
A Character Plotting Program
- Use matrix like a canvas
- "Plot" prints out matrix
-
charplot
Chap 9. Characters, Strings, & Streams: Abstraction
and Information Hiding
- Strings are Vectors of Characters
- Use indexing operator [] to get char
- Don't get out of range!
- Can both access and change characters
- Can also access characters (as strings) with .substr(pos,len)
- Reverse Order of Characters in a String
- Convert Characters to Strings
- Strings with one element are not characters.
- Can convert char to string using string(char)
-
capital.cc