home *** CD-ROM | disk | FTP | other *** search
/ C++ for Dummies (3rd Edition) / C_FD.iso / CHAP19 / CHAP19_3.CPP < prev   
C/C++ Source or Header  |  1996-09-02  |  1KB  |  55 lines

  1. // Chap19_3.cpp
  2. // This is not a complete program. Compare this solution with
  3. // Chap19_2 which uses RTTI.
  4. class Account
  5. {
  6.   public:
  7.     Account(int accNo, float initialBalance);
  8.  
  9.     virtual void deposit(float amount);
  10.     virtual void withdrawal(float amount);
  11.  
  12.     // addInterest - the default addInterest does nothing
  13.     virtual void addInterest()
  14.     {
  15.     }
  16.  
  17.     // addAccount - add current account to the account list
  18.     void addAccount();
  19.  
  20.     // getNext - get the next account from the account list;
  21.     //           if pPrev == 0, return first;
  22.     //           return 0 when no more left in list
  23.     static Account* getNext(Account *pPrev);
  24. };
  25.  
  26. class Checking : public Account
  27. {
  28.   public:
  29.     Checking(int accNo, float initialBalance = 0.0F) ;
  30. };
  31.  
  32. class Savings : public Account
  33. {
  34.   public:
  35.     Savings(int accNo, float initialBalance = 0.0F);
  36.  
  37.     // addInterest - calculate the interest for one time
  38.     //               period and add it back in
  39.     void addInterest();
  40. };
  41.  
  42. // accInterest - loop thru the accounts. For each Savings
  43. //               account you find, calculate the interest and
  44. //               it back in
  45. void accInterest()
  46. {
  47.     // loop thru the Accounts
  48.     Account* pA = (Account*)0;
  49.     while(pA = Account::getNext(pA))
  50.     {
  51.         // so add the interest in
  52.         pA->addInterest();
  53.     }
  54. }
  55.