23.1 True. The minus sign (–
) indicates private visibility. We’ve mentioned “friendship” as an exception to private visibility. Friendship is discussed in Chapter 9.
23.2 b.
23.3 The design for class Account
yields the header file in Fig. 23.37.
1 // Fig. 23.37: Account.h
2 // Account class definition. Represents a bank account.
3 #ifndef ACCOUNT_H
4 #define ACCOUNT_H
5
6 class Account
7 {
8 public:
9 bool validatePIN( int ); // is user-specified PIN correct?
10 double getAvailableBalance(); // returns available balance
11 double getTotalBalance(); // returns total balance
12 void credit( double ); // adds an amount to the Account
13 void debit( double ); // subtracts an amount from the Account
14 private:
15 int accountNumber; // account number
16 int pin; // PIN for authentication
17 double availableBalance; // funds available for withdrawal
18 double totalBalance; // funds available + funds waiting to clear
19 }; // end class Account
20
21 #endif // ACCOUNT_H
23.4 b.
23.5 False. The UML requires that we italicize abstract class names and operation names.
23.6 The design for class Transaction
yields the header file in Fig. 23.38. In the implementation, a constructor initializes private
reference attributes screen
and bankDatabase
to actual objects, and member functions getScreen
and getBankDatabase
access these attributes. These member functions allow classes derived from Transaction
to access the ATM’s screen and interact with the bank’s database.
1 // Fig. 36.38: Transaction.h
2 // Transaction abstract base class definition.
3 #ifndef TRANSACTION_H
4 #define TRANSACTION_H
5
6 class Screen; // forward declaration of class Screen
7 class BankDatabase; // forward declaration of class BankDatabase
8
9 class Transaction
10 {
11 public:
12 int getAccountNumber(); // return account number
13 Screen &getScreen(); // return reference to screen
14 BankDatabase &getBankDatabase(); // return reference to bank database
15
16 // pure virtual function to perform the transaction
17 virtual void execute() = 0; // overridden in derived classes
18 private:
19 int accountNumber; // indicates account involved
20 Screen &screen; // reference to the screen of the ATM
21 BankDatabase &bankDatabase; // reference to the account info database
22 }; // end class Transaction
23
24 #endif // TRANSACTION_H
3.12.123.189