< previous page page_895 next page >

Page 895
Quick Check
1. The specification of an ADT describes only its properties (the domain and allowable operations). To implement the ADT, what two things must a programmer do? (pp.838840)
2. Write a C++ class declaration for the following Checkbook ADT. Do not implement the ADT other than to include in the private part a concrete data representation for the current balance. All monetary amounts are to be represented as floating point numbers.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
TYPE
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Checkbook
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
DOMAIN
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Each instance of the Checkbook type is a value representing one customer's current checking account balance.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
OPERATIONS
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Open the checking account, specifying an initial balance.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Write a check for a specified amount.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Deposit a specified amount into the checking account.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Return the current balance.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
(pp.842846)
3. Write a segment of client code that declares two Checkbook objects, one for a personal checkbook and one for a business account. (pp. 842846)
4. For the personal checkbook in Question 3, write a segment of client code that opens the account with an initial balance of $300.00, writes two checks for $50.25 and $150.00, deposits $87.34 into the account, and prints out the resulting balance. (pp. 846849)
5. Implement the following Checkbook member functions. (pp. 854858)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Open
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. WriteCheck
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. CurrentBalance
6. A compile-time error occurs if a client of Checkbook tries to access the private class members directly. Give an example of such a client statement. (pp. 850851)
7. In which filethe specification file or the implementation filewould the solution to Question 2 be located? In which file would the solution to Question 5 be located? (pp. 852858)
8. For the Checkbook class, replace the Open function with two C++ class constructors. One (the default constructor) initializes the account balance to zero. The other initializes the balance to an amount passed as a parameter. (pp. 863868)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Revise the class declaration.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Implement the two class constructors.
Answers 1. a. Choose a concrete data representation of the abstract data, using data types that already exist. b. Implement each of the allowable operations in terms of program instructions.
2. class Checkbook
   {
   public:
       void Open( /* in */ float initBalance );
       void WriteCheck( /* in */ float amount );

 
< previous page page_895 next page >