C++ Help. Please read and follow ALL directions. Please include Comments! Please
ID: 3747525 • Letter: C
Question
C++ Help. Please read and follow ALL directions. Please include Comments! Pleases include screenshots of how to set up in development environment. Please make sure code runs per given test driver. Thank you.
Solve problem 5 on page 891 using the following modifications:
Assume
SavingsAccount: Assume an Interest Rate of 0.03
HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500
NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000
ServiceChargeChecking – Assume account service charge = $10, Maximum number of checks = 5, Service Charge if customer exceeds the maximum number of checks = $5.
NoServicechargeChecking: Assume an interest rate = 0.02, Minimum Balance = $1000
HighInterestChecking: Assume an interest rate = 0.05, Minimum Balance = $5000
CertificateOfDepsit: Assume an interest rate = 0.05, Initial Number of Maturity Months = 6
Capitalize the first letter of the derived class names.
Use the following driver to validate your program:
#include <iostream>
#include <iomanip>
#include <vector>
#include "BankAccount.h"
#include "SavingsAccount.h"
#include "HighInterestSavings.h"
#include "NoServiceChargeChecking.h"
#include "ServiceChargeChecking.h"
#include "HighInterestChecking.h"
#include "CertificateOfDeposit.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
vector<BankAccount *> accountsList;
//SavingsAccount( Name, Account number, Balance ) - Assume an interest rate = 0.03
accountsList.push_back(new SavingsAccount("Bill", 10200, 2500));
//HighInterestSavings(Name, Account Number, Balance) -- Assume an interest rate = 0.05, Minimum balance = $2500
accountsList.push_back(new HighInterestSavings("Susan", 10210, 2000));
//NoServiceChargeChecking(Name, Account Number, Balance) -- Assume an interest rate = 0.02, Minimum balance = $1000
accountsList.push_back(new NoServiceChargeChecking("John", 20100,
3500));
//ServiceChargeChecking(Name, Account Number, Balance) -- Assume account service charge = $10, Maximum number of checks = 5, Service Charee Excess Number of Checks = $5
accountsList.push_back(new ServiceChargeChecking("Ravi", 30100, 1800));
//HighIntererestChecking(Name, Account Number, Balance) - Assume an inerest rate = 0.05, Minimum balance = $5000
accountsList.push_back(new HighInterestChecking("Sheila", 20200, 6000));
//Certificate(name, Account Number, Balance, Interest Rate, Number of Months) - Assume an initial interest rate = 0.05, Initial Number of Maturity Months = 6
accountsList.push_back(new CertificateOfDeposit("Hamid", 51001, 18000,
0.075, 18));
cout << "January: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << " February: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->withdraw(500);
}
cout << " March: -------------" << endl;
for (int i = 0; i < accountsList.size(); i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
System(“pause”);
return 0;
}
..............................................................................
Problem 5 on pg 891
In this programming exercise, you use abstract classes and pure virtual functions to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next.
Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate.
Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing, and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.
Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. The penalty for early withdrawal is stiff. Figure 12-22 shows the inheritance hierarchy of these bank accounts.
Figure 12-22
Inheritance hierarchy of banking accounts
Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in Figure 12-22 are not abstract.
bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, and balance should be declared in the abstract class bankAccount. Some operations common to all types of accounts are retrieve account owner’s name, account number, and account balance; make deposits; withdraw money; and create monthly statements. So include functions to implement these operations. Some of these functions will be pure virtual.
checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the pure virtual function writeCheck to write a check.
serviceChargeChecking: A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and functions in this class.
noServiceChargeChecking: A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance.
highInterestChecking: A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account.
savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest.
highInterestSavings: A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance.
certificateOfDeposit: A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month.
Write the definitions of the classes described in this programming exercise and a program to test your classes.
Explanation / Answer
ANSWER:
CODE:
#include <iostream>
#include <string>
using namespace std;
class bankAccount
{
private:
string accHolderName;
string accountType;
int accountNumber;
double accBalance;
public:
bankAccount(string fullName = "", string accType = "", int accNum = 0, double balance = 0.0);
string getAccHolderName() const;
string getAccountType() const;
int getAccountNumber() const;
double getAccBalance() const;
void deposit(double amount);
void withdrawl(double amount);
virtual void print() const = 0;
};
/*contructor*/
bankAccount::bankAccount(string fullName, string accType, int accNum, double balance) {
accHolderName = fullName;
accountType = accType;
accountNumber = accNum;
accBalance = balance;
}
string bankAccount::getAccHolderName() const{
return accHolderName;
}
string bankAccount::getAccountType() const{
return accountType;
}
int bankAccount::getAccountNumber() const{
return accountNumber;
}
double bankAccount::getAccBalance() const{
return accBalance;
}
void bankAccount::deposit(double amount) {
accBalance += amount;
}
void bankAccount::withdrawl(double amount) {
if (amount > accBalance) {
cout << "Insufficent Funds. Account balance: " << accBalance << endl;
} else {
accBalance -= amount;
}
}
class checkingAccount: public bankAccount
{
private:
int numOfChecks;
public:
checkingAccount(string fullName = "", string accType = "", int accNum = 0, double balance = 0.0, int numChecks = 10);
int getChecksAvailable() const;
/*pure virtual function*/
virtual void writeCheck() = 0;
};
/*constructor*/
checkingAccount::checkingAccount(string fullName, string accType, int accNum, double balance, int numChecks)
:bankAccount(fullName, accType, accNum, balance) {
numOfChecks = numChecks;
}
int checkingAccount::getChecksAvailable() const {
return numOfChecks;
}
class serviceChargeChecking: public checkingAccount
{
private:
double minBalance;
double intRate;
public:
serviceChargeChecking(string fullName = "", string accType = "Service Charge Checking", int accNum = 0, double balance = 0.0, int numChecks = 10, double mBalance = 10.0, double iRate = .01);
void writeCheck();
double getIntRate() const;
void print() const;
};
/*constructor*/
serviceChargeChecking::serviceChargeChecking(string fullName, string accType, int accNum, double balance, int numChecks, double mBalance, double iRate)
:checkingAccount(fullName, accType, accNum, balance, numChecks) {
minBalance = mBalance;
intRate = iRate;
}
void serviceChargeChecking::writeCheck() {
}
double serviceChargeChecking::getIntRate() const {
return intRate;
}
void serviceChargeChecking::print() const {
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Account Type: " << getAccountType() << endl;
cout << "Name: " << getAccHolderName() << endl;
cout << "Balance: " << getAccBalance() << endl;
cout << "Interest Rate: " << getIntRate() << endl;
cout << "Remaining Checks: " << getChecksAvailable() << endl;
}
class noServiceChargeChecking: public checkingAccount
{
private:
public:
};
class highInterestChecking: public checkingAccount
{
private:
public:
};
class savingsAccount: public bankAccount
{
private:
public:
};
class highInterestSavings: public savingsAccount
{
private:
public:
};
class certificateOfDeposit: public bankAccount
{
private:
public:
};
int main() {
/*testing*/
serviceChargeChecking myAccount("David Flores", "Service Charge Checking", 12, 1000.25, 10, 10.0, .01);
myAccount.print();
return 0;
}
bankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <string>
using namespace std;
class bankAccount
{
public:
//accessors
string getName(); //grabs first name, spaces will end the program
long getAccountNum(); //grabs account #
double getBalance(); //grabs balance
double getWithdraw(); //grabs withdrawal amount
//mutators
void setName(string newName); //sets up the name
void setAccountNum(long newAccountNum); //sets up the account #
void setBalance(double newBalance); //sets up the balance
void setDepositAmt(double newDepositAmt); //captures the deposit amt
void setWithdrawAmt(double newWithdrawAmt); //captures the w/drawal amt
//other functions
virtual void printStatement() = 0; //prints the monthly statement aka declared in later classes since each class's statements are different
void calcDepBal(); //calcs new balance after depositing
virtual void calcWithBal(); //calcs new balance after withdrawal but will be overwritten by derived classes for its specific purpose
virtual void withdrawing(); //does the process of withdrawing, all the w/drawing will be done here by derived classes for its specific purpose
void depositing(); //does the process of depositing, all the depositing will be done here
private:
string name; //ex: Maria
long accountNum; //ex: 100194 <-bad account num
double balance; //ex: 500.00
double deposit; //ex: 20 or 20.00
double withdraw; //ex: 20 or 20.00
};
#endif // !BANKACCOUNT_H
bankAccount.cpp
#include "bankAccount.h"
#include <iostream>
#include <string>
using namespace std;
//accessors
string bankAccount::getName() //grabs first name
{
return name; //this will grab the name and output it
} //end getName
long bankAccount::getAccountNum() //grabs account #
{
return accountNum; //this grabs the account # and outputs it
} //end accountNum
double bankAccount::getBalance() //grabs balance
{
return balance; //this grabs the balance amount and outputs it
} //end getBalance
double bankAccount::getWithdraw() //grabs withdrawal amount
{
return withdraw; //this grabs the amount the user decides to withdraw
} //end getWithdraw
//mutators
void bankAccount::setName(string newName) //sets up the name
{
name = newName; //the string in the setName will be assigned to the variable: name
} //end setName
void bankAccount::setAccountNum(long newAccountNum) //sets up the account #
{
accountNum = newAccountNum; //the long in setAccountNum will be assigned to the variable: accountNum
} //end setAccountNum
void bankAccount::setBalance(double newBalance) //sets up the balance
{
balance = newBalance; //the double variable in setBalance will be assigned to the variable: balance
} //end setBalance
void bankAccount::setDepositAmt(double newDepositAmt) //captures the deposit amt
{
deposit = newDepositAmt; //the double variable in the setDepositAmt will be assigned to the variable: deposit
} //setDepositAmt
void bankAccount::setWithdrawAmt(double newWithdrawAmt) //captures the w/drawal amt
{
withdraw = newWithdrawAmt; //the double variable in the setWithdrawAmt will be assigned to the variable: withdraw
} //end endWithdrawAmt
//other functions
void bankAccount::calcDepBal() //calcs new balance after depositing
{
bankAccount::setBalance(balance + deposit); //calcs the new balance by adding the deposit to the current balance
} //end calcDepBal
void bankAccount::calcWithBal() //calcs new balance after withdrawal
{
if (balance > withdraw)
bankAccount::setBalance(balance - withdraw); //calcs the new balance by subtracting the withrawal amt to the current balance
//only if the current balance is higher than the withdrawal amt since it the balance can't be a negative number
else
cout << "Withdrawal denied "; //if the withdrawal amt is higher than the current balance then it will not withdraw
} //end calcWithBal
void bankAccount::withdrawing() //does the process of withdrawing
{
cout << "How much would you like to withdraw?: ";
cin >> withdraw;
bankAccount::setWithdrawAmt(withdraw);
cout << "Withdrawing... ";
bankAccount::calcWithBal();
cout << "Balance: " << bankAccount::getBalance() << " ";
} //end withdrawing
void bankAccount::depositing() //does the process of depositing
{
cout << "How much would you like to deposit?: ";
cin >> deposit;
bankAccount::setDepositAmt(deposit);
bankAccount::calcDepBal();
cout << "Depositing... "
<< "Balance: " << bankAccount::getBalance() << " ";
} //end depositing
certificateOfDeposit.h
#ifndef CERTIFICATEOFDEPOSIT_H
#define CERTIFICATEOFDEPOSIT_H
#include "bankAccount.h"
#include <string>
using namespace std;
class certificateOfDeposit : public bankAccount
{
public:
//accessors
//remember: accessors from bankAccount will be accessed
//mutators
//remember: mutators from bankAccount will be accessed
//constructor with default parameters
//upon instatiating, these parameters will be created
certificateOfDeposit(string dName = "", long dAccountNumber = 0, double dBalance = 530.50, double dDepositAmt = 0, double dWithdrawAmt = 0);
//other functions
//remember: other fumctions from bankAccount will be accessed
void printStatement(); //prints the monthly statement for this specific class
private:
const double INTEREST = 0.021; //interest of CD is 2.1%
const int NUMOFMATMONTH = 24; //total number of maturity months are 24
int currentMonth = 3; //current month of CD is the 3rd
};
#endif // !CERTIFICATEOFDEPOSIT_H
certificateOfDeposit.cpp
#include "certificateOfDeposit.h"
#include <iostream>
#include <string>
using namespace std;
//constructor with default parameters
//upon instatiating, these parameters will be created
certificateOfDeposit::certificateOfDeposit(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
} //end certificateOfDeposit
//other functions
void certificateOfDeposit::printStatement() //prints the monthly statement for this specific class
{
cout << "------------------------------------------- "
<< " Certificate of Deposit "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "No minimum balance "
<< "Interest: " << INTEREST << " "
<< "Number of maturity months: " << NUMOFMATMONTH << " "
<< "Current maturity month: " << currentMonth << " "
<< "------------------------------------------- ";
} //end printStatement
checkingAccount.h
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include "bankAccount.h"
#include <string>
using namespace std;
class checkingAccount : public bankAccount
{
public:
//accessors
//remember: accessors from bankAccount will be accessed
double getCheck(); //gets the check total amt
string getCheckRec(); //gets the name of the check's recepient who the client wants to make the check to
//mutators
//remember: mutators from bankAccount will be accessed
void setCheck(double newCheckAmt); //sets up the check total
void setCheckRec(string newCheckRec); //sets the name of the check's recipient
//other functions
virtual void writeCheck() = 0; //prompts for recepient & total. creates new balance. declared in later classes since each class is different
private:
double checkAmt; //ex: 23.00 or 23
string checkRec; //ex: Rachel
};
#endif // !CHECKINGACCOUNT_H
checkingAccount.cpp
#include "checkingAccount.h"
#include <iostream>
#include <string>
using namespace std;
//accessors
//remember: accessors from bankAccount will be accessed
double checkingAccount::getCheck() //gets the check total
{
return checkAmt; //outputs the total amount of what the check is
} //end getCheck
string checkingAccount::getCheckRec() //gets the name of the check's recepient
{
return checkRec; //outputs the name of the person the client made the check to
} //end getCheckRec
//mutators
//remember: mutators from bankAccount will be accessed
void checkingAccount::setCheck(double newCheckAmt) //sets up the check total
{
checkAmt = newCheckAmt; //double variable in setCheck will be assigned to the variable: checkAmt
} //end setCheck
void checkingAccount::setCheckRec(string newCheckRec) //sets the name of the check's recipient
{
checkRec = newCheckRec; //double variable in setCheckRec will be assigned to the variable: checkRec
} //end setCheckRec
highInterestChecking.h
#ifndef HIGHINTERESTCHECKING_H
#define HIGHINTERESTCHECKING_H
#include "noServiceChargeChecking.h"
#include <string>
using namespace std;
class highInterestChecking : public noServiceChargeChecking
{
public:
highInterestChecking(string dName = "", long dAccountNumber = 0, double dBalance = 850.00, double dDepositAmt = 0, double dWithdrawAmt = 0, string dCheckRec = "", double dCheckAmt = 0);
//other functions
//remember: other functions from bankAccount, checkingAccount, and noServiceChargeChecking will be accessed
void printStatement(); //prints the monthly statement for this class specifically
void writeCheck(); //prompts for recepient & total. creates new balance. for this specific class
void calcWithBal(); //calcs new balance after withdrawal for this specific class
void withdrawing(); //does the process of withdrawing for this specific class
private:
const double MINIMUM_BALANCE = 550.00;
const double INTEREST = 0.10;
string newName; //ex: Maria
double newCheckAmt; //ex: 20 or 20.00
double withdraw; //ex: 20.00 or 20
};
#endif // !HIGHINTERESTCHECKING_H
highInterestChecking.cpp
#include "highInterestChecking.h"
#include <iostream>
#include <string>
using namespace std;
//constructor with default parameters
//upon instatiating, these parameters will be created
highInterestChecking::highInterestChecking(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt, string dCheckRec, double dCheckAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
checkingAccount::setCheckRec(dCheckRec);
checkingAccount::setCheck(dCheckAmt);
} //end highInterestChecking
//other functions
void highInterestChecking::printStatement() //prints the monthly statement for this specific class
{
cout << "------------------------------------------------------------------------------- "
<< " Checking account with no service charge and high interest "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "Total checks per month: unlimited "
<< "Interest: " << INTEREST << " "
<< "Minimum balance: " << MINIMUM_BALANCE << " "
<< "Monthly charge: no "
<< "------------------------------------------------------------------------------- ";
} //end printStatement
void highInterestChecking::writeCheck() //prompts for recepient & total. creates new balance. for this specific class
{
cout << "Name of the recepient: ";
cin >> newName;
checkingAccount::setCheckRec(newName);
cout << "Check total: ";
cin >> newCheckAmt;
checkingAccount::setCheck(newCheckAmt);
cout << "Creating check... ";
if (bankAccount::getBalance() > checkingAccount::getCheck())
{
bankAccount::setBalance(bankAccount::getBalance() - checkingAccount::getCheck()); //makes sure that the balance doesn't fall in the (-)s
if (bankAccount::getBalance() < MINIMUM_BALANCE) //makes sure that the balance doesn't full under mini balance
{
bankAccount::setBalance(bankAccount::getBalance() + checkingAccount::getCheck());
cout << "Check denied: passing minimal balance ";
} //end if
else
{
cout << "Success! "
<< "Recepient: " << checkingAccount::getCheckRec() << " "
<< "Check total: " << checkingAccount::getCheck() << " ";
} //end else
} //end if
else
cout << "Check denied ";
cout << "Balance: " << bankAccount::getBalance() << " ";
} //end writeCheck()
void highInterestChecking::calcWithBal() //calcs new balance after withdrawal for this specific class
{
if (bankAccount::getBalance() > bankAccount::getWithdraw()) //makes sure that the balance doesn't fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() - bankAccount::getWithdraw());
if (bankAccount::getBalance() < MINIMUM_BALANCE)//makes sure that the balance doesn't full under mini balance
{
bankAccount::setBalance(bankAccount::getBalance() + bankAccount::getWithdraw());
cout << "Withrawal denied: passing minimal balance of: " << MINIMUM_BALANCE << " ";
} //end if
} //end if
else
cout << "Withdrawal denied ";
}
void highInterestChecking::withdrawing() //does the process of withdrawing for this specific class
{
cout << "How much would you like to withdraw?: ";
cin >> withdraw;
bankAccount::setWithdrawAmt(withdraw);
cout << "Withdrawing... ";
highInterestChecking::calcWithBal();
cout << "Balance: " << bankAccount::getBalance() << " ";
}
highInterestSavings.h
#ifndef HIGHINTERESTSAVINGS_H
#define HIGHINTERESTSAVINGS_H
#include "savingsAccount.h"
#include <string>
using namespace std;
//minimum balance
class highInterestSavings : public savingsAccount
{
public:
//constructor with default parameters
//upon instatiating, these parameters will be created
highInterestSavings(string dName = "", long dAccountNumber = 0, double dBalance = 630.50, double dDepositAmt = 0, double dWithdrawAmt = 0);
//other functions
//remember: other functions from bankAccount and savingsAccount will be accessed
void printStatement(); //prints the monthly statement for this specific class
void calcWithBal(); //calcs new balance after withdrawal for this specific class
void withdrawing(); //does the process of withdrawing for this specific class
private:
const double MINIMUM_BALANCE = 300.00;
const double INTEREST = 0.20;
double withdraw; //ex: 20 or 20.00
};
#endif // !HIGHINTERESTSAVINGS_H
highInterestSavings.cpp
#include "highInterestSavings.h"
#include <iostream>
#include <string>
using namespace std;
//constructor with default parameters
//upon instatiating, these parameters will be created
highInterestSavings::highInterestSavings(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
}
//other functions
void highInterestSavings::printStatement() //prints the monthly statement for this specific class
{
cout << "---------------------------------------------------- "
<< " Savings account with high interest "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "Interest: " << INTEREST << " "
<< "Minimum balance: " << MINIMUM_BALANCE << " "
<< "---------------------------------------------------- ";
}
void highInterestSavings::calcWithBal() //calcs new balance after withdrawal for this specific class
{
if (bankAccount::getBalance() > bankAccount::getWithdraw()) //makes sure that the balance doesn't fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() - bankAccount::getWithdraw());
if (bankAccount::getBalance() < MINIMUM_BALANCE) //makes sure that the balance doesn't full under mini balance
{
bankAccount::setBalance(bankAccount::getBalance() + bankAccount::getWithdraw());
cout << "Withrawal denied: passing minimal balance of: " << MINIMUM_BALANCE << " ";
} //end if
} //end if
else
cout << "Withdrawal denied ";
}
void highInterestSavings::withdrawing() //does the process of withdrawing for this specific class
{
cout << "How much would you like to withdraw?: ";
cin >> withdraw;
bankAccount::setWithdrawAmt(withdraw);
cout << "Withdrawing... ";
highInterestSavings::calcWithBal();
cout << "Balance: " << bankAccount::getBalance() << " ";
}
noServiceChargeChecking.h
#ifndef NOSERVICECHARGECHECKING_H
#define NOSERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include <string>
class noServiceChargeChecking : public checkingAccount
{
public:
//accessors
//remember: accessors from checkingAccount and bankAccount are accessed
//mutators
//remember: mutators from checkingAccount and bankAccount are accessed
//constructor with default parameters
//upon instatiating, these parameters will be created
noServiceChargeChecking(string dName = "", long dAccountNumber = 0, double dBalance = 650.50, double dDepositAmt = 0, double dWithdrawAmt = 0, string dCheckRec = "", double dCheckAmt = 0);
//other functions
void printStatement(); //prints the monthly statement
void writeCheck(); //prompts for recepient & total. creates new balance. for this specific clas
void calcWithBal(); //calcs new balance after withdrawal for this specific clas
void withdrawing(); //does the process of withdrawing for this specific clas
private:
const double MINIMUM_BALANCE = 350.00;
const double INTEREST = 0.01;
string newName; //ex: Maria
double newCheckAmt; //ex: 60.00 or 60
double withdraw; //ex: 70 or 70.00
}; //end class
#endif // !NOSERVICECHARGECHECKING_H
noServiceChargeChecking.cpp
#include "noServiceChargeChecking.h"
#include <iostream>
#include <string>
using namespace std;
//constructor with default parameters
//upon instatiating, these parameters will be created
noServiceChargeChecking::noServiceChargeChecking(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt, string dCheckRec, double dCheckAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
checkingAccount::setCheckRec(dCheckRec);
checkingAccount::setCheck(dCheckAmt);
} //end noServiceChargeChecking
//other functions
void noServiceChargeChecking::printStatement() //prints the monthly statement for this specific class
{
cout << "---------------------------------------------------------- "
<< " Checking account with no service charge "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "Total checks per month: unlimited "
<< "Interest: " << INTEREST << " "
<< "Minimum balance: " << MINIMUM_BALANCE << " "
<< "Monthly charge: no "
<< "---------------------------------------------------------- ";
} //end printStatement
void noServiceChargeChecking::writeCheck() //prompts for recepient & total. creates new balance. for this class
{
cout << "Name of the recepient: ";
cin >> newName;
checkingAccount::setCheckRec(newName);
cout << "Check total: ";
cin >> newCheckAmt;
checkingAccount::setCheck(newCheckAmt);
cout << "Creating check... ";
if (bankAccount::getBalance() > checkingAccount::getCheck()) //makes sure that the balance doesn't fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() - checkingAccount::getCheck());
if (bankAccount::getBalance() < MINIMUM_BALANCE) //makes sure that the balance doesn't full under mini balance
{
bankAccount::setBalance(bankAccount::getBalance() + checkingAccount::getCheck());
cout << "Check denied: passing minimal balance ";
} //end if
else
{
cout << "Success! "
<< "Recepient: " << checkingAccount::getCheckRec() << " "
<< "Check total: " << checkingAccount::getCheck() << " ";
} //end else
} //end if
else
cout << "Check denied ";
cout << "Balance: " << bankAccount::getBalance() << " ";
} //end writeCheck()
void noServiceChargeChecking::calcWithBal() //calcs new balance after withdrawal
{
if (bankAccount::getBalance() > bankAccount::getWithdraw()) //makes sure that the balance doesn't fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() - bankAccount::getWithdraw());
if (bankAccount::getBalance() < MINIMUM_BALANCE) //makes sure that the balance doesn't full under mini balance
{
bankAccount::setBalance(bankAccount::getBalance() + bankAccount::getWithdraw());
cout << "Withrawal denied: passing minimal balance of: " << MINIMUM_BALANCE << " ";
} //end if
} //end if
else
cout << "Withdrawal denied ";
} //end calcWithBal
void noServiceChargeChecking::withdrawing() //does the process of withdrawing
{
cout << "How much would you like to withdraw?: ";
cin >> withdraw;
bankAccount::setWithdrawAmt(withdraw);
cout << "Withdrawing... ";
noServiceChargeChecking::calcWithBal(); //makes sures that a withdrawal won't take more than mini balance
cout << "Balance: " << bankAccount::getBalance() << " ";
} //end withdrawing
savingsAccount.h
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "bankAccount.h"
#include <string>
using namespace std;
//inherits from bankAccount
//pays interest
class savingsAccount : public bankAccount
{
public:
//accessors
//remember: accessors from bankAccount will be accessed
//mutators
//remember: mutators from bankAccount will be accessed
//constructor with default parameters
//upon instatiating, these parameters will be created
savingsAccount(string dName = "", long dAccountNumber = 0, double dBalance = 530.50, double dDepositAmt = 0, double dWithdrawAmt = 0);
//other functions
//remember: other functions from bankAccount will be accessed
virtual void printStatement(); //prints the monthly statement for this specific class
private:
const double INTEREST = 0.02;
};
#endif // !SAVINGSACCOUNT_H
savingsAccount.cpp
#include "savingsAccount.h"
#include <iostream>
#include <string>
using namespace std;
//constructor with default parameters
//upon instatiating, these parameters will be created
savingsAccount::savingsAccount(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
} //end savingsAccount
//other functions
void savingsAccount::printStatement() //prints the monthly statement for this specific class
{
cout << "------------------------------------------- "
<< " Savings account "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "Interest: " << INTEREST << " "
<< "Minimum balance: no "
<< "------------------------------------------- ";
} //end printStatement
serviceChargeChecking.h
#ifndef SERVICECHARGECHECKING_H
#define SERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include <string>
using namespace std;
class serviceChargeChecking : public checkingAccount
{
public:
//accessors
//remember: accessors from checkingAccount and bankAccount are accessed
int getTotalChecks(); //gets the amount of checks used
int getRemCheck(); //gets the remaining number of checks
//mutators
//remember: mutators from checkingAccount and bankAccount are accessed
//constructor with default parameters
//upon instatiating, these parameters will be created
serviceChargeChecking(string dName = "", long dAccountNumber = 0, double dBalance = 500.50, double dDepositAmt = 0, double dWithdrawAmt = 0, string dCheckRec = "", double dCheckAmt = 0);
//other functions
void printStatement(); //prints the monthly statement for this specific class
void writeCheck(); //prompts for recepient & total. creates new balance. for this specific class
private:
const int NUM_OF_CHECKS = 10; //only 10 checks can be written in a month
string newName; //ex: Maria
double newCheckAmt; //ex: 50.00 or 50
int totalChecks = 0; //amount of checks the user has used and will be increment after each usage
};
#endif // !SERVICECHARGECHECKING_H
serviceChargeChecking.cpp
#include "serviceChargeChecking.h"
#include <iostream>
#include <string>
using namespace std;
//accessors
int serviceChargeChecking::getTotalChecks() //gets the amount of checks used
{
return totalChecks; //outputs the total amount of checks that have been used
} //end getTotalChecks
int serviceChargeChecking::getRemCheck() //gets the remaining number of checks
{
return NUM_OF_CHECKS - serviceChargeChecking::getTotalChecks(); //outputs the total amount of checks client has
} //end getRemCheck
//constructor
//variables in the parameters can over write the defaults
serviceChargeChecking::serviceChargeChecking(string dName, long dAccountNumber, double dBalance, double dDepositAmt, double dWithdrawAmt, string dCheckRec, double dCheckAmt)
{
bankAccount::setName(dName);
bankAccount::setAccountNum(dAccountNumber);
bankAccount::setBalance(dBalance);
bankAccount::setDepositAmt(dDepositAmt);
bankAccount::setWithdrawAmt(dWithdrawAmt);
checkingAccount::setCheckRec(dCheckRec);
checkingAccount::setCheck(dCheckAmt);
} //end serviceChargeChecking
//other functions
void serviceChargeChecking::printStatement() //prints the monthly statement
{
cout << "------------------------------------------------------ "
<< " Checking account with service charge "
<< "Name: " << bankAccount::getName() << " "
<< "Account Number: " << bankAccount::getAccountNum() << " "
<< "Current Balance: " << bankAccount::getBalance() << " "
<< "Total checks per month: " << NUM_OF_CHECKS << " "
<< "Total checks left: " << serviceChargeChecking::getRemCheck() << " "
<< "No interest "
<< "No minimum balance "
<< "------------------------------------------------------ ";
} //end printStatement
void serviceChargeChecking::writeCheck() //prompts for recepient & total. creates new balance.
{
//this will determine if the user has checks left to create one else it will deny them to write a check
if (totalChecks <= NUM_OF_CHECKS)
{
cout << "Name of the recepient: ";
cin >> newName;
checkingAccount::setCheckRec(newName);
cout << "Check total: ";
cin >> newCheckAmt;
checkingAccount::setCheck(newCheckAmt);
cout << "Creating check... ";
if (bankAccount::getBalance() > checkingAccount::getCheck()) //makes sure that the balance doesn't fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() - checkingAccount::getCheck());
cout << "Success! "
<< "Recepient: " << checkingAccount::getCheckRec() << " "
<< "Check total: " << checkingAccount::getCheck() << " ";
} //end if
else
cout << "Check denied "; //if (-) will deny it
cout << "Balance: " << bankAccount::getBalance() << " ";
totalChecks++; //increments to keep track of the amount of checks used
} //end if
else
cout << "You no longer have checks ";
} //end writeCheck
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.