Im looking for a solution to a programming exercise in my te

I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5.

https://www.chegg.com/homework-help/C-Programming-7th-edition-chapter-12-problem-5PE-solution-9781285852744

Solution

bankAccount.h

#ifndef H_bankAccount

#define H_bankAccount

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

class bankAccount

{

public:

      

       bankAccount(int acctNum, string name, double initialBalance);

       string get_Name();

       int get_AcctNumber();

       double get_Balance();

       void deposit(double amount);

       virtual void withdraw(double amount) = 0;

       virtual void printStatement() = 0;

       virtual void printSummary()

       {

              cout << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

              cout << endl << setw(25) << \"\" << \"Account Summary\" << endl << endl;

              cout << setw(25) << \"Name: \" << m_Name << endl;

              cout << setw(25) << \"Account #: \" << m_AcctNumber << endl;

              cout << setw(25) << \"Current Balance: $\" << m_Balance << endl;

       }

protected:

       string m_Name;

       int m_AcctNumber;

       double m_Balance;

};

#endif

bankAccount.cpp

#include \"bankAccount.h\"

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

bankAccount::bankAccount(int acctNum, string name, double initialBalance) // constructor

{

       m_AcctNumber = acctNum;

       m_Name = name;

       m_Balance = initialBalance;

}

string bankAccount::get_Name()

{

       return m_Name;

}

int bankAccount::get_AcctNumber()

{

       return m_AcctNumber;

}

double bankAccount::get_Balance()

{

       return m_Balance;

}

void bankAccount::deposit(double amount)

{

       m_Balance += amount;

       cout << \"$\" << amount << \" has been deposited to your account\" << endl;

}

certificateOfDeposit.h

#ifndef H_certificateOfDeposit

#define H_certificateOfDeposit

#include \"bankAccount.h\"

class certificateOfDeposit : public bankAccount

{

public:

      

       certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon);

       void withdraw(double amount);

       void printSummary();

       void printStatement();

private:

      

       double m_InterestRate;

       int m_MaturityMonths;

       int m_CurrentMonth;

};

#endif

certificateOfDepoist.cpp

#include \"certificateOfDeposit.h\"

certificateOfDeposit::certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)

       : bankAccount(acctNum, name, initialBalance)

{

       // variables

       m_MaturityMonths = matMon;

       m_CurrentMonth = 1;

       m_InterestRate = 4.75;

}

void certificateOfDeposit::withdraw(double amount)

{

       if (m_Balance - amount < 0)

       {

              cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

              return;

       }

       m_Balance -= amount;

}

void certificateOfDeposit::printSummary()

{

      

       bankAccount::printSummary();

                                               

       cout << setw(25) << \"Interest rate: \" << m_InterestRate << \"%\" << endl;

       cout << setw(25) << \"Maturity Months: \" << m_MaturityMonths << endl;

       cout << setw(25) << \"Current Month: \" << m_CurrentMonth << endl;

       cout << endl << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

}

void certificateOfDeposit::printStatement()

{

       printSummary();

       cout << \"printStatement is not implemented in the program\" << endl;

}

checkingAccount.h

#ifndef H_checkingAccount

#define H_checkingAccount

#include \"bankAccount.h\"

class checkingAccount :

       public bankAccount

{

public:

       checkingAccount(int acctNum, string name, double initialBalance);

      

       void withdraw(double amount);

       void printStatement();

      

       virtual void writeCheck(double amount) = 0;

protected:

      

       double m_InterestRate;

       int m_ChecksRemaining;

       double m_MinimumBalance;

};

#endif

checkingAccount.cpp

#include \"checkingAccount.h\"

checkingAccount::checkingAccount(int acctNum, string name, double initialBalance)

    : bankAccount(acctNum, name, initialBalance)

{

}

void checkingAccount::withdraw(double amount)

{

    if (m_Balance - amount < 0)

    {

        cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

        return;

    }

   if (m_Balance - amount < m_MinimumBalance)

    {

        cout << \"Declined: Minimum balance requirement prohibits this withdrawal\" << endl;

        return;

    }

    m_Balance -= amount;

}

void checkingAccount::printStatement()

{

    printSummary();

    cout << endl << \"printStatement is not implemented in the program\" << endl << endl;

}

highInterestChecking.h

#ifndef H_highInterestChecking

#define H_highInterestChecking

#include \"noServiceChargeChecking.h\"

class highInterestChecking :

       public noServiceChargeChecking

{

public:

      

       highInterestChecking(int acctNum, string name, double initialBalance);

};

#endif

highInterestCheckingImp.cpp

#include \"highInterestChecking.h\"

highInterestChecking::highInterestChecking(int acctNum, string name, double initialBalance)

       : noServiceChargeChecking(acctNum, name, initialBalance)

{

       // variables

       m_InterestRate = 5.0;

       m_ChecksRemaining = -1;

       m_MinimumBalance = 1000;

}

highInterestSavings.h

#ifndef H_highInterestSavings

#define H_highInterestSavings

#include \"savingsAccount.h\"

class highInterestSavings :

       public savingsAccount // inheriting savingsAccount as public

{

public:

      

       highInterestSavings(int acctNum, string name, double initialBalance);

      

       void withdraw(double amount);

       void printSummary();

protected:

      

       double m_MinimumBalance;

};

#endif

highInterestSavings.cpp

#include \"highInterestSavings.h\"

highInterestSavings::highInterestSavings(int acctNum, string name, double initialBalance)

       : savingsAccount(acctNum, name, initialBalance)

{

       m_MinimumBalance = 5000;

}

void highInterestSavings::withdraw(double amount)

{

       if (m_Balance - amount < 0)

       {

              cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

              return;

       }

       if (m_Balance - amount < m_MinimumBalance)

       {

              cout << \"Declined: Minimum balance requirement prohibits this withdrawal\" << endl;

              return;

       }

       m_Balance -= amount;

}

void highInterestSavings::printSummary()

{

      

       bankAccount::printSummary();

                                                      

       cout << setw(25) << \"Interest rate: \" << m_InterestRate << \"%\" << endl;

       cout << setw(25) << \"Minimum Balance: $\" << m_MinimumBalance << endl << endl;

       cout << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

}

noServiceChargeChecking.h

#ifndef H_noServiceChargeChecking

#define H_noServiceChargeChecking

#include \"checkingAccount.h\"

class noServiceChargeChecking :

       public checkingAccount

{

public:

      

       noServiceChargeChecking(int acctNum, string name, double initialBalance);

      

       void writeCheck(double amount);

       void printSummary();

};

#endif

notServiceChargeChecking.cpp

#include \"noServiceChargeChecking.h\"

noServiceChargeChecking::noServiceChargeChecking(int acctNum, string name, double initialBalance)

       : checkingAccount(acctNum, name, initialBalance)

{

       m_InterestRate = 2.5;

       m_ChecksRemaining = -1;

       m_MinimumBalance = 500;

}

void noServiceChargeChecking::writeCheck(double amount)

{

       if (m_Balance - amount < 0)

       {

              cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

              return;

       }

       m_Balance -= amount;

}

void noServiceChargeChecking::printSummary()

{

       bankAccount::printSummary();

                                                      

       cout << setw(25) << \"Interest rate: \" << m_InterestRate << \"%\" << endl;

       cout << setw(25) << \"Minimum Balance: $\" << m_MinimumBalance << endl;

       cout << setw(25) << \"Unlimited checks   \" << endl;

       cout << setw(25) << \"No monthly service fee   \" << endl;

       cout << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

}

savingsAccount.h

#ifndef H_savingsAccount

#define H_savingsAccount

#include \"bankAccount.h\"

class savingsAccount :

       public bankAccount

{

public:

      

       savingsAccount(int acctNum, string name, double initialBalance);

      

       void withdraw(double amount);

       void printSummary();

       void printStatement();

protected:

       double m_InterestRate;

};

#endif

SavingsAccount.cpp

#include \"savingsAccount.h\"

savingsAccount::savingsAccount(int acctNum, string name, double initialBalance)

       : bankAccount(acctNum, name, initialBalance)

{

       m_InterestRate = 3.99;

}

void savingsAccount::withdraw(double amount)

{

       if (m_Balance - amount < 0)

       {

              cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

              return;

       }

       m_Balance -= amount;

}

void savingsAccount::printSummary()

{

      

       bankAccount::printSummary();

                                                      

       cout << setw(25) << \"Interest rate: \" << m_InterestRate << \"%\" << endl << endl;

       cout << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

}

void savingsAccount::printStatement() // prints the monthly statement

{

       printSummary();

       cout << \"printStatement is not implemented\" << endl;

}

serviceChargeChecking.h

#ifndef H_serviceChargeChecking

#define H_serviceChargeChecking

#include \"checkingAccount.h\"

class serviceChargeChecking :

public checkingAccount

{

public:

serviceChargeChecking(int acctNum, string name, double initialBalance);

void writeCheck(double amount);

void printSummary();

};

#endif

serviceChargeChecking.cpp

#include \"serviceChargeChecking.h\"

const int MAX_CHECKS = 5;

const double SVC_CHARGE = 10.0l;

serviceChargeChecking::serviceChargeChecking(int acctNum, string name, double initialBalance)

       : checkingAccount(acctNum, name, initialBalance)

{

       m_InterestRate = 0;

       m_ChecksRemaining = MAX_CHECKS;

       m_MinimumBalance = 0;

}

void serviceChargeChecking::writeCheck(double amount)

{

       if (m_ChecksRemaining == 0)

       {

              cout << \"Declined: No more checks remaining this month\" << endl;

              return;

       }

       if (m_Balance - amount < 0)

       {

              cout << \"Declined: Insufficient funds remain to withdraw that amount\" << endl;

              return;

       }

       m_ChecksRemaining--;

       m_Balance -= amount;

}

void serviceChargeChecking::printSummary()

{

      

       bankAccount::printSummary();

                                               

       cout << setw(25) << \"Checks remaining: \" << m_ChecksRemaining << endl;

       cout << setw(25) << \"Monthly service fee: $\" << SVC_CHARGE << endl;

       cout << setw(25) << \"No interest \" << endl;

       cout << setw(25) << \"No Minimum Balance \" << endl;

       cout << setw(60) << setfill(\'-\') << \"\" << setfill(\' \') << endl;

}

testAccounts.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include \"bankAccount.h\"

#include \"checkingAccount.h\"

#include \"serviceChargeChecking.h\"

#include \"noServiceChargeChecking.h\"

#include \"highInterestChecking.h\"

#include \"savingsAccount.h\"

#include \"highInterestSavings.h\"

#include \"certificateOfDeposit.h\"

using namespace std;

void TestCheckingWithService()

{

       serviceChargeChecking acct(123, \"John Doe\", 1000);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting Checking with Service Charge\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"5 - Write a check\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'5\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.writeCheck(amount);

                     break;

              case \'6\':

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

void TestCheckingNoService()

{

       noServiceChargeChecking acct(123, \"John Doe\", 1000);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting Checking without Service Charge\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"5 - Write a check\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'5\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.writeCheck(amount);

                     break;

              case \'6\':

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

void TestCheckingHighInterest()

{

       highInterestChecking acct(123, \"John Doe\", 1000);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting Checking with High Interest\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"5 - Write a check\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'5\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.writeCheck(amount);

                     break;

              case \'6\':

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

void TestSavings()

{

       savingsAccount acct(123, \"John Doe\", 1000);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting Regular Savings\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

void TestSavingsHighInterest()

{

       highInterestSavings acct(123, \"John Doe\", 8000);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting High Interest Savings\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

void TestCertificateOfDeposit()

{

       certificateOfDeposit acct(123, \"John Doe\", 10000, 6);

       char input = 0;

       double amount;

       cout << \"\\t\\tTesting High Interest Savings\" << endl << endl;

       cout << \"Current account overview:\" << endl;

       acct.printSummary();

       cout << endl;

       while (input != \'x\')

       {

              cout << \"Select a transaction:\" << endl;

              cout << \"1 - Make a Withdrawal\" << endl;

              cout << \"2 - Make a Deposit\" << endl;

              cout << \"3 - Print Summary\" << endl;

              cout << \"4 - Print Monthly Statement\" << endl;

              cout << \"x - Exit Program\" << endl;

              cout << \"Enter choice: \";

              cin >> input;

              switch (input)

              {

              case \'1\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.withdraw(amount);

                     break;

              case \'2\':

                     cout << \"Enter amount: \";

                     cin >> amount;

                     acct.deposit(amount);

                     break;

              case \'3\':

                     acct.printSummary();

                     break;

              case \'4\':

                     acct.printStatement();

                     break;

              case \'x\':

                     break;

              default:

                     cout << \"Invalid choice\" << endl;

                     break;

              }

              acct.printSummary();

              cout << endl;

       }

}

int main()

{

       char input; // user\'s input

       cout << \"\\t\\tWelcome to the testing Bank\" << endl << endl;

       cout << \"WWhich account do you want?\" << endl;

       cout << \"1 - Checking with Service Charge\" << endl;

       cout << \"2 - Checking without Service Charge\" << endl;

       cout << \"3 - Checking with High Interest\" << endl;

       cout << \"4 - Savings\" << endl;

       cout << \"5 - Savings with High Interest\" << endl;

       cout << \"6 - Certificate of Deposit\" << endl;

       cout << \"Enter choice: \";

       cin >> input;

       switch (input)

       {

       case \'1\':

              TestCheckingWithService();

              break;

       case \'2\':

              TestCheckingNoService();

              break;

       case \'3\':

              TestCheckingHighInterest();

              break;

       case \'4\':

              TestSavings();

              break;

       case \'5\':

              TestSavingsHighInterest();

              break;

       case \'6\':

              TestCertificateOfDeposit();

              break;

       default:

              cout << \"Invalid choice\" << endl;

              break;

       }

}

I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th
I\'m looking for a solution to a programming exercise in my text book. Chapter 12, Programming Exercise 5. https://www.chegg.com/homework-help/C-Programming-7th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site