|
|
|
|
|
|
|
An object is an instance of a data type called a class. During object-oriented design, classes can be designed from scratch, obtained from class libraries and used as-is, or customized from existing classes by using the technique of inheritance. The result of the design process is a program consisting of self-contained objects that manage their own data and communicate by invoking each other's operations. |
|
|
|
|
|
|
|
|
Careful attention to program design, program formatting, and documentation produces highly structured and readable programs. |
|
|
|
|
|
|
|
|
1. Write a C++ statement that inputs values from the standard input stream into two float variables, x and y. (pp. 133136) |
|
|
|
|
|
|
|
|
2. Your program is reading from the standard input stream. The next three characters waiting in the stream are a blank, a blank, and the letter A. Indicate what character is stored into the char variable ch by each of the following statements. (Assume the same initial stream contents for each.) |
|
|
|
 |
|
|
|
|
a. cin >> ch;
b. cin.get(ch);
(pp.136140) |
|
|
|
|
|
|
|
|
3. Input prompts should acknowledge the user's experience. |
|
|
|
 |
|
|
|
|
a. What sort of message would you have a program print to prompt a novice user to input a social security number? |
|
|
|
 |
|
|
|
|
b. How would you change the wording of the prompting message for an experienced user? (pp. 142144) |
|
|
|
|
|
|
|
|
4. If a program is going to input 1000 numbers, is interactive input appropriate? (pp.144145) |
|
|
|
|
|
|
|
|
5. What are the four things that you have to remember to do in order to use data files in a C++ program? (pp. 146149) |
|
|
|
|
|
|
|
|
6. How many levels of abstraction are there in a top-down design before you reach the point at which you can begin coding a program? (pp. 153160) |
|
|
|
|
|
|
|
|
7. When is a flat implementation of a top-down design appropriate? (pp. 157160) |
|
|
|
|
|
|
|
|
8. Modules are the building blocks of top-down design. What are the building blocks of object-oriented design? (pp. 161164) |
|
|
|
|
|
|
|
|
Answers 1. cin >> x >> y; 2. a. A b. (a blank) 3. a. Please type a nine-digit social security number, then press the key marked RETURN. b.Enter SSN. 4. No. Batch input is more appropriate for programs that input large amounts of data. 5. (1) Include the header file fstream.h. (2) Declare the file streams along with your other variable declarations. (3) Call the open function to prepare each file for reading or writing. (4) Specify the name of the file stream in each I/O statement that uses it. 6. There is no fixed number of levels of abstraction. You keep refining the solution through as many levels as necessary until the steps are all concrete. 7. A flat implementation is appropriate when a design is short and has just one or two levels of abstraction. 8. The building blocks are objects, each of which has associated operations. |
|
|
|
|
|