// File: inclass17.cpp
// Driver program to demonstrate and test the BankAccount class.
//
// Input:  user choice
// Output: bank account balances and interest rates
// -----------------------------------------------------------------
// Class: CS 210                     Instructors: Drs. Hwang & Roberts
// Assignment: In-class Exercise     Date : March 14 & 15, 2007
// Programmer(s): <fill in your name(s)>

#include <iostream>    // cin, cout, endl, >>, <<
#include "account.h"   // BankAccount class definition
using namespace std;

// Function prototypes
char GetUserChoice();

int main( )
{
   BankAccount account1,                // Default construction
               account2 (100.0, 0.07);  // Explicit value construction
   double balance1, balance2,           // Account balances
          rate1, rate2;                 // Account interest rates
   char choice;                         // User menu choice
   
   // Set formatting
   cout.precision(2);
   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);

   do
   {
      // Read user choice
      choice = GetUserChoice();

      // Select on the transaction choice
      if ((choice == 'b') || (choice == 'B')) // Test GetBalance
      {
         balance1 = account1.GetBalance();
         balance2 = account2.GetBalance();
         cout << "\nAccount 1 balance: $" << balance1
              << "\nAccount 2 balance: $" << balance2 << endl;
      }  // end if choice is b
      if ((choice == 'r') || (choice == 'r')) // Test GetRate
      {
         rate1 = account1.GetRate()*100;
         rate2 = account2.GetRate()*100;
         cout << "\nAccount 1 interest rate: " << rate1
              << "%\nAccount 2 interest rate: " << rate2 << '%' << endl;
      }  // end if choice is r
      if ((choice == 'u') || (choice == 'U')) // Test Update
      {
         account1.Update();
         account2.Update();
         cout << "\nAccounts have been updated\n";
      }  // end if choice is u
      if ((choice == 'p') || (choice == 'P')) // Test Write
      {
         cout << "\nAccount 1\n";
         account1.Write(cout);
         cout << "\nAccount 2\n";
         account2.Write(cout);
      }  // end if choice is p
   }  while ((choice != 'Q') && (choice != 'q'));

   return 0;
}  // end main

// Function: GetUserChoice
// Prints a menu of transaction choices and returns the user's choice
char GetUserChoice ()
{
   char input;

   cout << "\nThe choices you have are:\n\n"
        << "   B - display current balances\n"
        << "   R - display current interest rates\n"
        << "   U - update the accounts\n"
        << "   P - display account information\n"
        << "   Q - exit the program\n\n"
        << "Please enter your choice: ";
   cin >> input;
   return input;
} // end GetUserChoice
