C++ I have the code, but need comments added please. //main// //Accounts.cpp #in
ID: 666360 • Letter: C
Question
C++
I have the code, but need comments added please.
//main//
//Accounts.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include "certificateOfDeposit.h"
#include "highInterestChecking.h"
#include "highInterestSavings.h"
#include "serviceChargeChecking.h"
using namespace std;
void TestCheckingWithService()
{
serviceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing 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 Test Suite" << 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 << " Testing 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 Test Suite" << 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 << " Testing 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 Test Suite" << 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 << " Testing 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 Test Suite" << 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 << " Testing 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 Test Suite" << 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 << " Testing 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 Test Suite" << 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;
cout << " Welcome to the Bank Account Test Suite" << endl << endl;
cout << "What type of account do you want to test?" << 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;
}
}
//bankAccount.h
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class bankAccount
{
public:
bankAccount(int acctNum, string name, double initialBalance)
{
m_AcctNumber = acctNum;
m_Name = name;
m_Balance = initialBalance;
}
~bankAccount(void){}
string get_Name()
{
return m_Name;
}
int get_AcctNumber()
{
return m_AcctNumber;
}
double get_Balance()
{
return m_Balance;
}
void deposit(double amount)
{
m_Balance += amount;
cout << "$" << amount << " has been deposited to your account" << endl;
}
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;
};
//certificateOfDeposit.h
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class certificateOfDeposit :
public bankAccount
{
public:
certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)
: bankAccount(acctNum, name, initialBalance)
{
m_MaturityMonths = matMon;
m_CurrentMonth = 1;
m_InterestRate = 4.75;
}
~certificateOfDeposit(void){}
void withdraw(double amount)
{
if (m_Balance-amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}
void printSummary()
{
// Use the root base class to print common info
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 printStatement()
{
printSummary();
cout << "A full implementation would also print a Certificate of Deposite Account Statement here." << endl;
}
private:
double m_InterestRate;
int m_MaturityMonths;
int m_CurrentMonth;
};
//checkingAccount.h
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class checkingAccount :
public bankAccount
{
public:
checkingAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
}
~checkingAccount(void){}
virtual void writeCheck(double amount) = 0;
void 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 printStatement()
{
printSummary();
cout << endl << "A full implementation would also print details of a Checking Account Statement here." << endl << endl;
}
protected:
double m_InterestRate;
int m_ChecksRemaining;
double m_MinimumBalance;
};
//highInterestChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "noServiceChargeChecking.h"
using namespace std;
class highInterestChecking :
public noServiceChargeChecking
{
public:
highInterestChecking(int acctNum, string name, double initialBalance)
: noServiceChargeChecking(acctNum, name, initialBalance)
{
// The only difference between the base class noServiceChargeChecking
// is the values of interest and minimum balance.
// So no additional functionality needed for this one.
m_InterestRate = 5.0; // Higher interest rate
m_ChecksRemaining = -1; // -1 indicates no limit
m_MinimumBalance = 1000; // Minimum balance
}
~highInterestChecking(void){}
};
//highInterestSavings.h
#include <iostream>
#include <iomanip>
#include <string>
#include "savingsAccount.h"
using namespace std;
class highInterestSavings :
public savingsAccount
{
public:
highInterestSavings(int acctNum, string name, double initialBalance)
: savingsAccount(acctNum, name, initialBalance)
{
m_MinimumBalance = 5000;
}
~highInterestSavings(void){}
void 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 printSummary()
{
// Use the root base class to print common info
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;
}
protected:
double m_MinimumBalance;
};
//noServiceChargeChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"
using namespace std;
class noServiceChargeChecking :
public checkingAccount
{
public:
noServiceChargeChecking(int acctNum, string name, double initialBalance)
: checkingAccount(acctNum, name, initialBalance)
{
m_InterestRate = 2.5; // Some interest rate
m_ChecksRemaining = -1; // -1 indicates no limit
m_MinimumBalance = 500; // Minimum balance
}
~noServiceChargeChecking(void){}
void writeCheck(double amount)
{
if (m_Balance - amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount; // Assume check is cashed immediately...
}
void printSummary()
{
// Use the root base class to print common info
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
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class savingsAccount :
public bankAccount
{
public:
savingsAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
m_InterestRate = 3.99;
}
~savingsAccount(void)
{
}
void withdraw(double amount)
{
if (m_Balance-amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}
void printSummary()
{
// Use the root base class to print common info
bankAccount::printSummary();
cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl << endl;
cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}
void printStatement()
{
printSummary();
cout << "A full implementation would also print a Savings Account Statement here." << endl;
}
protected:
double m_InterestRate;
};
//serviceChargeChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"
using namespace std;
const int MAX_CHECKS=5;
const double SVC_CHARGE=10.0l;
class serviceChargeChecking :
public checkingAccount
{
public:
serviceChargeChecking(int acctNum, string name, double initialBalance)
: checkingAccount(acctNum, name, initialBalance)
{
m_InterestRate = 0; // No interest
m_ChecksRemaining = MAX_CHECKS; // Limit of 5 checks
m_MinimumBalance = 0; // No minimum balance
}
~serviceChargeChecking(void){}
void 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; // Assume check is cashed immediately...
}
void printSummary()
{
// Use the root base class to print common info
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;
}
};
//arrayListType.h//
#ifndef H_arrayListType
#define H_arrayListType
#include <iostream>
using namespace std;
class arrayListType
{
public:
bool isEmpty() const;
bool isFull() const;
int listSize() const;
int maxListSize() const;
void print() const;
bool isItemAtEqual(int,int) const;
virtual void insertAt(int,int) = 0;
virtual void insertEnd(int) = 0;
void removeAt(int);
void retrieveAt(int,int&) const;
virtual void replaceAt(int,int) = 0;
void clearList();
virtual int seqSearch(int) const = 0;
virtual void remove(int) = 0;
arrayListType(int size = 100);
arrayListType(const arrayListType & otherList);
virtual ~arrayListType();
protected:
int *list;
int length;
int maxSize;
};
bool arrayListType::isEmpty() const
{
return (length == 0);
}
bool arrayListType::isFull() const
{
return (length == maxSize);
}
int arrayListType::listSize() const
{
return length;
}
int arrayListType::maxListSize() const
{
return maxSize;
}
void arrayListType::print() const
{
for(int i = 0; i < length; i++)
cout << list[i] << " ";
cout << endl;
}
bool arrayListType::isItemAtEqual(int location, int item) const
{
if(location < 0 || location >= length)
{
cout << "The location is out of range." << "This is an error, you shouldn't be here!" << endl;
return false;
}
else
return (list[location] == item);
}
void arrayListType::removeAt(int location)
{
if(location < 0 || location >= length)
cout << "The location is out of range."
<< "This is an error, you shouldn't be here!" << endl;
else
{
for(int i = location; i < length - 1; i++)
list[i] = list[i + 1];
length--;
}
}
void arrayListType::retrieveAt(int location, int &retItem) const
{
if(location < 0 || location >= length)
cout << "The location is out of range."
<< "This is an error, you shouldn't be here!" << endl;
else
retItem = list[location];
}
void arrayListType::clearList()
{
length = 0;
}
arrayListType::arrayListType(int size)
{
if(size <= 0)
{
cout << "The array size must be positive. Creating "
<< "an array with default size of 100." << endl;
maxSize = 100;
}
else
maxSize = size;
length = 0;
list = new int[maxSize];
}
arrayListType::~arrayListType()
{
delete [] list;
}
arrayListType::arrayListType(const arrayListType &otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;
list = new int[maxSize];
for(int j = 0; j < length; j++)
list[j] = otherList.list[j];
}
#endif
//unorderedListType.h//
#ifndef H_unorderedListType
#define H_unorderedListType
#include <iostream>
#include "arrayListType.h"
using namespace std;
class unorderedListType: public arrayListType
{
public:
void insertAt(int, int);
void insertEnd(int);
void replaceAt(int, int);
int seqSearch(int) const;
void remove(int);
unorderedListType(int size = 100);
};
void unorderedListType::insertAt(int location, int item)
{
if(location < 0 || location >= maxSize)
cout << "The index is out of range." << endl;
else if(length >= maxSize)
cout << "The list is full." << endl;
else
{
for(int i = length; i > location; i--)
list[i] = list[i - 1];
list[location] = item;
length++;
}
}
void unorderedListType::insertEnd(int item)
{
if(length >= maxSize)
cout << "The list is full." << endl;
else
{
list[length] = item;
length++;
}
}
int unorderedListType::seqSearch(int item) const
{
int loc = 0;
bool found = false;
for(loc = 0; loc < length; loc++)
if(list[loc] == item)
{
found = true;
break;
}
if(found)
return loc;
else
return -1;
}
void unorderedListType::remove(int item)
{
int loc;
if(length == 0)
cout << "The list is empty." << endl;
else
{
loc = seqSearch(item);
if(loc != -1)
removeAt(loc);
else
cout << "The item is not in the list." << endl;
}
}
void unorderedListType::replaceAt(int location, int item)
{
if(location < 0 || location >= length)
cout << "The location is out of range." << endl;
else
list[location] = item;
}
unorderedListType::unorderedListType(int size):arrayListType(size)
{
}
#endif
Explanation / Answer
#include <iostream>
#include <iomanip> //including necessary header files
#include <string>
#include "certificateOfDeposit.h"
#include "highInterestChecking.h"
#include "highInterestSavings.h"
#include "serviceChargeChecking.h"
using namespace std;
void TestCheckingWithService() //method to test account checking with service charge
{
serviceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Checking with Service Charge" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //loop to provide user with various options related to the type of his account
{
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 Test Suite" << endl;
cout << "Enter choice: ";
cin >> input; //read user input
switch (input) //switch-case block to implement the correct method based on the input entered by the user
{
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() //method to test account checking without service charge
{
noServiceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Checking without Service Charge" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //providing user with available options related to his account
{
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 Test Suite" << endl;
cout << "Enter choice: ";
cin >> input; //read user input
switch (input) //switch-case block to implement the correct method based on the input entered by the user
{
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() //method to test account checking With high interest rate
{
highInterestChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Checking with High Interest" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //providing user with available options related to his account
{
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 Test Suite" << endl;
cout << "Enter choice: ";
cin >> input; //read user input
switch (input) //switch-case block to implement the correct method based on the input entered by the user
{
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(); //call to print method to print the account summary of the account holder
cout << endl;
}
}
void TestSavings() //method to test a savings account
{
savingsAccount acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Regular Savings" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //providing user with available options related to his account
{
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 Test Suite" << 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(); //call to print method to print the account summary of the account holder
cout << endl;
}
}
void TestSavingsHighInterest()
{
highInterestSavings acct(123,"John Doe", 8000);
char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //providing user with available options related to his account
{
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 Test Suite" << 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(); //call to print method to print the account summary of the account holder
cout << endl;
}
}
void TestCertificateOfDeposit()
{
certificateOfDeposit acct(123,"John Doe", 10000, 6);
char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;
cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;
while (input != 'x') //providing user with available options related to his account
{
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 Test Suite" << endl;
cout << "Enter choice: ";
cin >> input;
switch (input) //switch-case block to implement the correct method based on the input entered by the user
{
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(); //call to print method to print the account summary of the account holder
cout << endl;
}
}
int main() //start of main
{
char input;
cout << " Welcome to the Bank Account Test Suite" << endl << endl; //providing user with the different types of bank accounts
cout << "What type of account do you want to test?" << endl; //and asking him to select the type of his/her account by entering
cout << "1 - Checking with Service Charge" << endl; //the appropriate number associated to it
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; //read user input
switch (input) //switch case to match user's input value and evaluate the case accordingly
{
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;
}
} //end of main of accounts.cpp
//bankAccount.h
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class bankAccount
{
public:
bankAccount(int acctNum, string name, double initialBalance) //constructor to initialize variable values
{
m_AcctNumber = acctNum;
m_Name = name;
m_Balance = initialBalance;
}
~bankAccount(void){}
string get_Name()
{
return m_Name;
}
int get_AcctNumber()
{
return m_AcctNumber;
}
double get_Balance()
{
return m_Balance;
}
void deposit(double amount) //metheod to update account balance on deposit transaction
{
m_Balance += amount;
cout << "$" << amount << " has been deposited to your account" << endl;
}
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;
};
//certificateOfDeposit.h
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class certificateOfDeposit :
public bankAccount
{
public:
certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)
: bankAccount(acctNum, name, initialBalance)
{
m_MaturityMonths = matMon;
m_CurrentMonth = 1;
m_InterestRate = 4.75;
}
~certificateOfDeposit(void){}
void withdraw(double amount) //metheod to update account balance on withdrawal transaction
{
if (m_Balance-amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}
void printSummary() //method to print account summary
{
// Use the root base class to print common info
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 printStatement()
{
printSummary();
cout << "A full implementation would also print a Certificate of Deposite Account Statement here." << endl;
}
private:
double m_InterestRate;
int m_MaturityMonths;
int m_CurrentMonth;
};
//checkingAccount.h
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class checkingAccount :
public bankAccount
{
public:
checkingAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
}
~checkingAccount(void){}
virtual void writeCheck(double amount) = 0;
void withdraw(double amount)
{
if (m_Balance-amount < 0) //if statement to print error if withdrawal transaction is carried out on an account with
{ //balance is less than zero
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 printStatement()
{
printSummary();
cout << endl << "A full implementation would also print details of a Checking Account Statement here." << endl << endl;
}
protected:
double m_InterestRate;
int m_ChecksRemaining;
double m_MinimumBalance;
};
//highInterestChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "noServiceChargeChecking.h"
using namespace std;
class highInterestChecking :
public noServiceChargeChecking
{
public:
highInterestChecking(int acctNum, string name, double initialBalance)
: noServiceChargeChecking(acctNum, name, initialBalance)
{
// The only difference between the base class noServiceChargeChecking
// is the values of interest and minimum balance.
// So no additional functionality needed for this one.
m_InterestRate = 5.0; // Higher interest rate
m_ChecksRemaining = -1; // -1 indicates no limit
m_MinimumBalance = 1000; // Minimum balance
}
~highInterestChecking(void){}
};
//highInterestSavings.h
#include <iostream>
#include <iomanip>
#include <string>
#include "savingsAccount.h"
using namespace std;
class highInterestSavings :
public savingsAccount
{
public:
highInterestSavings(int acctNum, string name, double initialBalance)
: savingsAccount(acctNum, name, initialBalance)
{
m_MinimumBalance = 5000;
}
~highInterestSavings(void){}
void withdraw(double amount)
{
if (m_Balance-amount < 0) //if statement to print error if withdrawal transaction is carried out on an account with
{ //balance is less than zero
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 printSummary()
{
// Use the root base class to print common info
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;
}
protected:
double m_MinimumBalance;
};
//noServiceChargeChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"
using namespace std;
class noServiceChargeChecking :
public checkingAccount
{
public:
noServiceChargeChecking(int acctNum, string name, double initialBalance)
: checkingAccount(acctNum, name, initialBalance)
{
m_InterestRate = 2.5; // Some interest rate
m_ChecksRemaining = -1; // -1 indicates no limit
m_MinimumBalance = 500; // Minimum balance
}
~noServiceChargeChecking(void){}
void writeCheck(double amount)
{
if (m_Balance - amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount; // Assume check is cashed immediately...
}
void printSummary()
{
// Use the root base class to print common info
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
#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"
using namespace std;
class savingsAccount :
public bankAccount
{
public:
savingsAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
m_InterestRate = 3.99;
}
~savingsAccount(void)
{
}
void withdraw(double amount)
{
if (m_Balance-amount < 0) //if statement to print error if withdrawal transaction is carried out on an account with
{ //balance less than zero
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}
void printSummary()
{
// Use the root base class to print common info
bankAccount::printSummary();
cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl << endl;
cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}
void printStatement()
{
printSummary();
cout << "A full implementation would also print a Savings Account Statement here." << endl;
}
protected:
double m_InterestRate;
};
//serviceChargeChecking.h
#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"
using namespace std;
const int MAX_CHECKS=5;
const double SVC_CHARGE=10.0l;
class serviceChargeChecking :
public checkingAccount
{
public:
serviceChargeChecking(int acctNum, string name, double initialBalance)
: checkingAccount(acctNum, name, initialBalance)
{
m_InterestRate = 0; // No interest
m_ChecksRemaining = MAX_CHECKS; // Limit of 5 checks
m_MinimumBalance = 0; // No minimum balance
}
~serviceChargeChecking(void){}
void 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; // Assume check is cashed immediately...
}
void printSummary()
{
// Use the root base class to print common info
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;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.