In: Computer Science
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. This class provides the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information.
b. The class checkingAccount from the class bankAccount (designed in part a). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. This class provides the following operations: set interest rate, retrieve interest rate, set minimum balance, retrieve minimum balance, set service charges, retrieve service charges, post interest, verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information.
c. Yours for definition and implementation :
Every bank offers a savings account. Derive the class savingsAccount from the class bankAccount (designed in part a). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
d. Write a program to test your classes designed in parts c.
the program that needs to be edited is below thanks someone help these are the files I was given have to make changes
//Class bankAccount
#ifndef H_bankAccount
#define H_bankAccount
class bankAccount
{
public:
void setAccountNumber(int acct);
int getAccountNumber() const;
double getBalance() const;
void withdraw(double amount);
void deposit(double amount);
void print() const;
bankAccount(int acctNumber = -1, double bal = 0);
protected:
int accountNumber;
double balance;
};
#endif
//Class checkingAccount
#ifndef H_checkingAccount
#define H_checkingAccount
#include "bankAccount.h"
const double DEFAULT_INTEREST_RATE_CHECKING = 0.04;
const double DEFAULT_MIN_BALANCE = 500.00;
const double DEFAULT_SERVICE_CHARGE = 20;
class checkingAccount : public bankAccount
{
public:
double getMinimumBalance() const;
void setMinimumBalance(double minBalance);
double getInterestRate() const;
void setInterestRate(double intRate);
double getServiceCharge() const;
void setServiceCharge(double intRate);
void postInterest();
bool verifyMinimumumBalance(double amount);
void writeCheck(double amount);
void withdraw(double amount);
void print() const;
checkingAccount(int acctNumber, double bal,
double minBal =
DEFAULT_MIN_BALANCE,
double intRate =
DEFAULT_INTEREST_RATE_CHECKING,
double servC =
DEFAULT_SERVICE_CHARGE);
protected:
double interestRate;
double minimumBalance;
double serviceCharge;
};
#endif
//Implementation file bankAccountImp.cpp
#include <iostream>
#include <iomanip>
#include "bankAccount.h"
using namespace std;
bankAccount::bankAccount(int acctNumber, double bal)
{
accountNumber = acctNumber;
balance = bal;
}
void bankAccount::setAccountNumber(int acct)
{
accountNumber = acct;
}
int bankAccount::getAccountNumber() const
{
return accountNumber;
}
double bankAccount::getBalance() const
{
return balance;
}
void bankAccount::withdraw(double amount)
{
balance = balance - amount;
}
void bankAccount::deposit(double amount)
{
balance = balance + amount;
}
void bankAccount::print() const
{
cout << fixed << setprecision(2);
cout << accountNumber << " balance :
$"
<< balance <<
endl;
}
//Implementation file checkingAccountImp.cpp
#include <iostream>
#include <iomanip>
#include "checkingAccount.h"
using namespace std;
checkingAccount::checkingAccount(int acctNumber, double
bal,
double minBal, double intRate, double servC)
: bankAccount(acctNumber, bal)
{
interestRate = intRate;
minimumBalance = minBal;
serviceCharge = servC;
}
double checkingAccount::getMinimumBalance() const
{
return minimumBalance;
}
void checkingAccount::setMinimumBalance(double minBalance)
{
minimumBalance = minBalance;
}
double checkingAccount::getInterestRate() const
{
return interestRate;
}
void checkingAccount::setInterestRate(double intRate)
{
interestRate = intRate;
}
double checkingAccount::getServiceCharge() const
{
return serviceCharge;
}
void checkingAccount::setServiceCharge(double servC)
{
serviceCharge = servC;
}
void checkingAccount::postInterest()
{
balance = balance + balance * interestRate;
}
bool checkingAccount::verifyMinimumumBalance(double
amount)
{
return (balance - amount >= minimumBalance);
}
void checkingAccount::writeCheck(double amount)
{
withdraw(amount);
}
void checkingAccount::withdraw(double amount)
{
if (balance - amount < 0)
cout << "Not enough money in
the account." << endl;
else if (balance - amount < minimumBalance)
{
if (balance - amount -
serviceCharge < minimumBalance)
{
cout <<
"After this transaction, the balanace will be "
<< "below the minimum balance." <<
endl
<< "However account does not have enough
money "
<< "to process the transaction and apply
service charge." << endl
<< "Transaction denied!" <<
endl;
}
else
{
cout <<
"After this transaction, the balanace will be "
<< "below the minimum balance." <<
endl
<< "Service charges will apply." <<
endl;
balance =
balance - amount - serviceCharge;
}
}
else
balance = balance - amount;
}
void checkingAccount::print() const
{
cout << fixed << setprecision(2);
cout << "Interest Checking ACCT#:\t" <<
getAccountNumber()
<< "\tBalance: $" <<
getBalance() << endl;
}
#include <iostream>
#include <iomanip>
//#include "savingsAccount.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
int accountNumber = 1000;
checkingAccount jackAccount(accountNumber++,
1000);
checkingAccount lisaAccount(accountNumber++,
450);
//savingsAccount samirAccount(accountNumber++,
9300);
//savingsAccount ritaAccount(accountNumber++, 32);
jackAccount.deposit(1000);
lisaAccount.deposit(2300);
//samirAccount.deposit(800);
//ritaAccount.deposit(500);
jackAccount.postInterest();
lisaAccount.postInterest();
//samirAccount.postInterest();
//ritaAccount.postInterest();
cout << "***********************************"
<< endl;
jackAccount.print();
lisaAccount.print();
//samirAccount.print();
//ritaAccount.print();
cout << "***********************************"
<< endl << endl;
jackAccount.writeCheck(250);
lisaAccount.writeCheck(350);
//samirAccount.withdraw(120);
//ritaAccount.withdraw(290);
cout << "********After withdrawals
***************" << endl;
jackAccount.print();
lisaAccount.print();
//samirAccount.print();
//ritaAccount.print();
cout << "***********************************"
<< endl << endl;
return 0;
}
********************************************Summary**********************************************
The program files for above question are given below with the essential comments and the output....
However in the savings Account class i have assigned the interest rate as 0.02 ..you can change it in the savingsAccount.h file if you want.......
I hope it works for you!!!!!!!!!!!!!!!!!!!!
********************************************Program**********************************************
#1.savingsAccount.h
//Class savingsAccount
#ifndef H_savingsAccount
#define H_savingsAccount
#include "bankAccount.h"
const double DEFAULT_INTEREST_RATE_SAVINGS = 0.02; //setting default interest rate value
class savingsAccount:public bankAccount //savingsAccount class inherting bankAccount class
{
public:
void setInterestRate(double intRate); //setInterest() function
double getInterestRate() const; //retieve Interest function
void postInterest(); //post Interest() function
void withdraw(double amount); //overriding withdraw function of bankAccount
void print() const; //printing account info
savingsAccount(int acctNumber, double bal, //appropriate constructor
double intRate = DEFAULT_INTEREST_RATE_SAVINGS);
protected:
double interestRate; //member variable for storing interest rate
};
#endif
#2.savingsAccountImp.cpp
//Implementation file savingAccountImp.cpp
#include <iostream>
#include <iomanip>
#include "savingsAccount.h"
using namespace std;
savingsAccount::savingsAccount(int acctNumber, double bal, double intRate)
: bankAccount(acctNumber, bal) //calling construcotr of super class and setting interestRate=default interestRate
{
interestRate = intRate;
}
void savingsAccount::setInterestRate(double intRate) //setting new interest rate
{
interestRate = intRate;
}
double savingsAccount::getInterestRate() const //retriving interest rate
{
return interestRate;
}
void savingsAccount::postInterest() //adding interest to the balance
{
balance = balance + balance * interestRate;
}
void savingsAccount::withdraw(double amount) //withdrawing money from the account balance
{
if (balance - amount < 0)
cout << "Not enough money in the account." << endl;
else
balance = balance - amount;
}
void savingsAccount::print() const //printing the account information
{
cout << fixed << setprecision(2);
cout << "Interest Checking ACCT#:\t" << getAccountNumber()
<< "\tBalance: $" << getBalance() << endl;
}
#3. main.cpp
#include <iostream>
#include <iomanip>
#include "savingsAccount.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
int accountNumber = 1000;
checkingAccount jackAccount(accountNumber++, 1000);
checkingAccount lisaAccount(accountNumber++, 450);
savingsAccount samirAccount(accountNumber++, 9300); //creating savingsaccount with balance 9300
savingsAccount ritaAccount(accountNumber++, 32); //creating savings account with balance 32
jackAccount.deposit(1000);
lisaAccount.deposit(2300);
samirAccount.deposit(800); //depositing amount in the account
ritaAccount.deposit(500);
jackAccount.postInterest();
lisaAccount.postInterest();
samirAccount.postInterest(); //adding the interest in the account balance
ritaAccount.postInterest();
cout << "***********************************" << endl;
jackAccount.print();
lisaAccount.print();
samirAccount.print(); //printing account info before withdrawl
ritaAccount.print();
cout << "***********************************" << endl << endl;
jackAccount.writeCheck(250);
lisaAccount.writeCheck(350);
samirAccount.withdraw(120); //withdrawing amount from the account balance
ritaAccount.withdraw(290);
cout << "********After withdrawals ***************" << endl;
jackAccount.print();
lisaAccount.print();
samirAccount.print(); //printing account info after withdrawl
ritaAccount.print();
cout << "***********************************" << endl << endl;
return 0;
}
********************************************Output**********************************************
Output with code screenshot