CPS 6, Ramm - Summer Semester I - 6/5/01 #13
- Announce
- Quiz Friday
- Lab #5 Today
- Individual Meetings Tomorrow (sign up)
7. Class Interfaces, Design, and Implementation
- Work on Class Design: The Quiz Class
-
First look at traditional style program
-
simpquiz2.cpp
- Consider a Class Design: Requirements
- More than one kind of question
- Several students share keyboard
- More than one chance to answer
- Class Design: Assigning Responsibilities
- Student
- Construct using name
- RespondTo a question
- GetScore
- GetName
- Quiz
- ChooseKindOfQuestion
- AskQuestion of/GiveQuestion to a student
- Question
- Create/Construct question type
- AskQuestion
- Get CorrectAnswer
- Implementing and Using Classes
- Iterative Enhancement
- Using Stubs
- Sometimes partial function
- Sometimes announce only
- Sometimes totally empty
teststudent.cpp
question.h
- Other Practical Issues
- Handling different kinds of questions
- String return type for answer
- string tostring(int)
- string tostring(double)
- Question Class
-
mathquest.h
-
mathquest.cpp
- Initializer Lists - Syntax
- ClassName::ClassName()
- :
- myVar1(argument),
- myVar2(argument),
- ...
- myVarN(argument)
- {// begin constructor body ...
- Quiz Program
- Includes Student and Quiz Classes
-
quiz.cpp
- Preprocessor
- #include files, missing?
- #ifndef, #define, #endif
- multiple copies of include files
- Compiler
- Linker
- Undefined symbols
- Missing modules
- Alternate Question Class (State Capitals)
- Includes Student and Quiz Classes
-
capquest.cpp,
capquest.h
- Frogs that can't make up their minds ...
- Random Walks (1-D)
- Physics
- Statistical
- Coin Toss
- Frog Example
- Gambling Example
- Random Walk Class
- Random Walks (2-D)
- Passing a Class by Value/Reference
- Done for strings many times...
-
scopedice.cpp
- Structs
- Similarity to Class
- All Public, No Private
- Can Have Member Functions
- An Aggregate of Dissimilar Types
- Example (without member functions)
- struct Student
- {
- string name;
- int height; // height in inches
- double weight; // weight in pounds
- string dob; // date of birth mm/dd/yy
- }
Chap 8. Arrays, Data, & Random Access
- Concepts
- Random Access
- Sequential Access
- Arrays, Vectors
- A Counting Problem
-
gradefreq1.cpp
-
gradefreq2.cpp
-
gradefreq3.cpp
- Vector Vocabulary
- Homogeneous Collection (Aggregate)
- N cells/elements
- index/subscript (0, 1, ..., N-1)
- always start at 0
- last always at N-1