In: Computer Science
Banks offer various types of accounts, such as savings, checking, certificate
of deposits, and money market, to attract customers as well as meet their
specific needs. Two of the most commonly used accounts are savings and
checking. Each of these accounts has various options. For example, you may
have a savings account that requires no minimum balance but has a lower
interest rate. Similarly, you may have a checking account that limits the
number of checks you may write. Another type of account that is used to
save money for the long term is certificate of deposit (CD).
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-25 shows the inheritance hierarchy of these bank 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-25 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 nomonthly 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.
Answer :
#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
\n\n"; //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... \n";
bankAccount::calcWithBal();
cout << "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
} //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... \n"
<< "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
} //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 <<
"------------------------------------------- \n"
<< "\t Certificate of Deposit
\n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "No minimum balance
\n"
<< "Interest: \t\t\t"
<< INTEREST << "\n"
<< "Number of maturity
months: \t" << NUMOFMATMONTH << "\n"
<< "Current maturity month:
\t" << currentMonth << "\n"
<<
"------------------------------------------- \n\n";
} //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 <<
"-------------------------------------------------------------------------------
\n"
<< "\t Checking account with
no service charge and high interest \n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "Total checks per month:
\tunlimited \n"
<< "Interest: \t\t\t"
<< INTEREST << "\n"
<< "Minimum balance: \t\t"
<< MINIMUM_BALANCE << "\n"
<< "Monthly charge: \t\tno
\n"
<<
"-------------------------------------------------------------------------------
\n\n";
} //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... \n";
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 \n\n";
} //end if
else
{
cout <<
"Success! \n"
<< "Recepient: \t" <<
checkingAccount::getCheckRec() << "\n"
<< "Check total: \t" <<
checkingAccount::getCheck() << "\n";
} //end else
} //end if
else
cout << "Check denied
\n\n";
cout << "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
} //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 << "\n\n";
} //end if
} //end if
else
cout << "Withdrawal denied
\n\n";
}
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... \n";
highInterestChecking::calcWithBal();
cout << "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
}
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 <<
"---------------------------------------------------- \n"
<< "\t Savings account with
high interest \n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "Interest: \t\t\t"
<< INTEREST << "\n"
<< "Minimum balance: \t\t"
<< MINIMUM_BALANCE << "\n"
<<
"---------------------------------------------------- \n\n";
}
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 << "\n\n";
} //end if
} //end if
else
cout << "Withdrawal denied
\n\n";
}
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... \n";
highInterestSavings::calcWithBal();
cout << "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
}
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 <<
"----------------------------------------------------------
\n"
<< "\t Checking account with
no service charge \n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "Total checks per month:
\tunlimited \n"
<< "Interest: \t\t\t"
<< INTEREST << "\n"
<< "Minimum balance: \t\t"
<< MINIMUM_BALANCE << "\n"
<< "Monthly charge: \t\tno
\n"
<<
"----------------------------------------------------------
\n\n";
} //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...
\n";
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 \n\n";
} //end if
else
{
cout << "Success! \n"
<< "Recepient: \t"
<< checkingAccount::getCheckRec() << "\n"
<< "Check total: \t"
<< checkingAccount::getCheck() << "\n";
} //end
else
} //end if
else
cout <<
"Check denied \n\n";
cout << "Balance: \t"
<< bankAccount::getBalance() << "\n\n";
} //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 << "\n\n";
} //end if
} //end if
else
cout << "Withdrawal denied
\n\n";
} //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... \n";
noServiceChargeChecking::calcWithBal(); //makes sures
that a withdrawal won't take more than mini balance
cout << "Balance: \t" <<
bankAccount::getBalance() << "\n\n";
} //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 <<
"------------------------------------------- \n"
<< "\t Savings account
\n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "Interest: \t\t\t"
<< INTEREST << "\n"
<< "Minimum balance: \t\tno
\n"
<<
"------------------------------------------- \n\n";
} //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 <<
"------------------------------------------------------ \n"
<< "\t Checking account with
service charge \n\n"
<< "Name: \t\t\t\t" <<
bankAccount::getName() << "\n"
<< "Account Number: \t\t"
<< bankAccount::getAccountNum() << "\n"
<< "Current Balance: \t\t"
<< bankAccount::getBalance() << "\n"
<< "Total checks per month:
\t" << NUM_OF_CHECKS << "\n"
<< "Total checks left: \t\t"
<< serviceChargeChecking::getRemCheck() << "\n"
<< "No interest \n"
<< "No minimum balance
\n"
<<
"------------------------------------------------------
\n\n";
} //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...
\n";
if (bankAccount::getBalance() >
checkingAccount::getCheck()) //makes sure that the balance doesn't
fall in the (-)s
{
bankAccount::setBalance(bankAccount::getBalance() -
checkingAccount::getCheck());
cout <<
"Success! \n"
<< "Recepient: \t" <<
checkingAccount::getCheckRec() << "\n"
<< "Check total: \t" <<
checkingAccount::getCheck() << "\n";
} //end if
else
cout <<
"Check denied \n\n"; //if (-) will deny it
cout << "Balance: \t"
<< bankAccount::getBalance() << "\n\n";
totalChecks++; //increments to keep
track of the amount of checks used
} //end if
else
cout << "You no longer have
checks \n\n";
} //end writeCheck