Create a menu that allows you to select the account type and then gives you opti
ID: 3866840 • Letter: C
Question
Create a menu that allows you to select the account type and then gives you option:
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
Use BankAccount pointers and polymorphism.
#include <iostream>
#include <stdbool.h>
#include "BankAccount.h"
using namespace std;
class SavingAccount : public BankAccount
{
private:
bool status;
public:
SavingAccount(double balace, double rate): BankAccount(balace,rate)
{
}
bool checkStatus()
{
if (BankAccount::balance < 25.0)
return false;
else
return true;
}
void withdraw(double amount)
{
if (checkStatus())
{
BankAccount::withdraw(amount);
}
}
void deposit(double amount)
{
if (checkStatus() == false)
{
if (BankAccount::balance + amount > 25)
status = true;
}
BankAccount::deposit(amount);
}
void monthlyProc()
{
if (BankAccount::noOfWithdrawl > 4)
{
BankAccount::monthlyServiceCharge += 1;
BankAccount::balance -= 1;
if (BankAccount::balance < 25)
status = false;
}
}
};
class CheckingAccount :public BankAccount
{
public:
CheckingAccount(double balace, double rate) : BankAccount(balace, rate)
{
}
void withdraw(double amount)
{
if (balance - amount < 0)
{
monthlyServiceCharge += 15;
balance -= 15;
}
else
BankAccount::withdraw(amount);
}
void monthlyProc()
{
monthlyServiceCharge += 5;
monthlyServiceCharge += 0.10*noOfWithdrawl;
}
};
int main()
{
BankAccount *saving = new SavingAccount(100,15);
cout << "please enter amount to deposit in saving account: ";
double depositAmount, withdrawAmount;
cin >> depositAmount;
saving->deposit(depositAmount);
double monthStartBalance = depositAmount;
cout << "please enter amount to withdraw from saving account: ";
cin >> withdrawAmount;
saving->withdraw(withdrawAmount);
cout << "Month start balance: " << monthStartBalance << endl;
cout << "Total No of depost: " << saving->getNoOfDeposit() << endl;
cout << "Total no of withdrawl: " << saving->getNoOfWithdrawl() << endl;
cout << "Monthly service charge: " << saving->getMonthleServiceCharge() << endl;
cout << "Month Ending balance: " << saving->getbalance() << endl;
//Checkingaccount
BankAccount *checking = new CheckingAccount(500, 10);
cout << "please enter amount to deposit in checking account: ";
cin >> depositAmount;
checking->deposit(depositAmount);
monthStartBalance = depositAmount;
cout << "please enter amount to withdraw from checking account: ";
cin >> withdrawAmount;
checking->withdraw(withdrawAmount);
cout << "Month start balance: " << monthStartBalance << endl;
cout << "Total No of depost: " << checking->getNoOfDeposit() << endl;
cout << "Total no of withdrawl: " << checking->getNoOfWithdrawl() << endl;
cout << "Monthly service charge: " << checking->getMonthleServiceCharge() << endl;
cout << "Month Ending balance: " << checking->getbalance() << endl;
getchar();
return 0;
}
//BankAccount.h
#pragma once
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
class BankAccount
{
protected:
double balance;
int noOfDeposit;
int noOfWithdrawl;
double AnnualInterestRate;
double monthlyServiceCharge;
public:
BankAccount(double bal, double interestRate)
{
balance = bal;
AnnualInterestRate = interestRate;
noOfDeposit = 0;
noOfWithdrawl = 0;
monthlyServiceCharge = 0;
}
virtual void deposit(double amount)
{
balance += amount;
noOfDeposit++;
}
virtual void withdraw(double amount)
{
balance -= amount;
noOfWithdrawl++;
}
virtual void calcint()
{
double MonthlyInterestRate = (AnnualInterestRate / 12);
double MonthlyInterest = balance * MonthlyInterestRate;
balance = balance + MonthlyInterest;
}
virtual void monthlyProc()
{
balance -= monthlyServiceCharge;
calcint();
noOfDeposit = 0;
noOfWithdrawl = 0;
monthlyServiceCharge = 0;
}
double getbalance()
{
return balance;
}
int getNoOfDeposit()
{
return noOfDeposit;
}
int getNoOfWithdrawl()
{
return noOfWithdrawl;
}
double getMonthleServiceCharge()
{
return monthlyServiceCharge;
}
};
#endif
Explanation / Answer
Here is your code: -
BankAccount.h
#pragma once
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
class BankAccount
{
protected:
double balance;
int noOfDeposit;
int noOfWithdrawl;
double AnnualInterestRate;
double monthlyServiceCharge;
public:
BankAccount(double bal, double interestRate)
{
balance = bal;
AnnualInterestRate = interestRate;
noOfDeposit = 0;
noOfWithdrawl = 0;
monthlyServiceCharge = 0;
}
virtual void deposit(double amount)
{
balance += amount;
noOfDeposit++;
}
virtual void withdraw(double amount)
{
balance -= amount;
noOfWithdrawl++;
}
virtual void calcint()
{
double MonthlyInterestRate = (AnnualInterestRate / 12);
double MonthlyInterest = balance * MonthlyInterestRate;
balance = balance + MonthlyInterest;
}
virtual void monthlyProc()
{
balance -= monthlyServiceCharge;
calcint();
noOfDeposit = 0;
noOfWithdrawl = 0;
monthlyServiceCharge = 0;
}
double getbalance()
{
return balance;
}
int getNoOfDeposit()
{
return noOfDeposit;
}
int getNoOfWithdrawl()
{
return noOfWithdrawl;
}
double getMonthleServiceCharge()
{
return monthlyServiceCharge;
}
};
#endif
accountDriver.cpp
#include <iostream>
#include <stdbool.h>
#include "BankAccount.h"
using namespace std;
class SavingAccount : public BankAccount
{
private:
bool status;
public:
SavingAccount(double balace, double rate): BankAccount(balace,rate)
{
}
bool checkStatus()
{
if (BankAccount::balance < 25.0)
return false;
else
return true;
}
void withdraw(double amount)
{
if (checkStatus())
{
BankAccount::withdraw(amount);
}
}
void deposit(double amount)
{
if (checkStatus() == false)
{
if (BankAccount::balance + amount > 25)
status = true;
}
BankAccount::deposit(amount);
}
void monthlyProc()
{
if (BankAccount::noOfWithdrawl > 4)
{
BankAccount::monthlyServiceCharge += 1;
BankAccount::balance -= 1;
if (BankAccount::balance < 25)
status = false;
}
}
};
class CheckingAccount :public BankAccount
{
public:
CheckingAccount(double balace, double rate) : BankAccount(balace, rate)
{
}
void withdraw(double amount)
{
if (balance - amount < 0)
{
monthlyServiceCharge += 15;
balance -= 15;
}
else
BankAccount::withdraw(amount);
}
void monthlyProc()
{
monthlyServiceCharge += 5;
monthlyServiceCharge += 0.10*noOfWithdrawl;
}
};
int main()
{
BankAccount *saving = new SavingAccount(100,15);
/*
cout << "please enter amount to deposit in saving account: ";
double depositAmount, withdrawAmount;
cin >> depositAmount;
saving->deposit(depositAmount);
double monthStartBalance = depositAmount;
cout << "please enter amount to withdraw from saving account: ";
cin >> withdrawAmount;
saving->withdraw(withdrawAmount);
cout << "Month start balance: " << monthStartBalance << endl;
cout << "Total No of depost: " << saving->getNoOfDeposit() << endl;
cout << "Total no of withdrawl: " << saving->getNoOfWithdrawl() << endl;
cout << "Monthly service charge: " << saving->getMonthleServiceCharge() << endl;
cout << "Month Ending balance: " << saving->getbalance() << endl;
*/
cout<<"This is for your savings account "<<endl;
//Menu
int option = 0;
while(option != 5) {
cout<<" Menu: - 1) deposit 2) withdraw 3) check balance 4) monthly processing 5) exit ";
cin>>option;
switch(option) {
case 1:
cout << " please enter amount to deposit in saving account: ";
double depositAmount;
cin >> depositAmount;
saving->deposit(depositAmount);
cout<<" Your amount is deposited. Thank you.";
break;
case 2:
cout << " please enter amount to withdraw from saving account: ";
double withdrawAmount;
cin>> withdrawAmount;
saving->withdraw(withdrawAmount);
cout<<" You have withrawn your amount successfully.";
break;
case 3:
cout<<" Your balance is : "<<saving->getbalance();
break;
case 4:
saving->monthlyProc();
cout << " Total No of depost: " << saving->getNoOfDeposit() << endl;
cout << " Total no of withdrawl: " << saving->getNoOfWithdrawl() << endl;
cout << " Monthly service charge: " << saving->getMonthleServiceCharge() << endl;
cout << " Month Ending balance: " << saving->getbalance() << endl;
break;
case 5:
cout<<" Thank you.";
break;
default:
cout<<"Please select a correct option.";
break;
}
}
//Checkingaccount
BankAccount *checking = new CheckingAccount(500, 10);
/*
cout << "please enter amount to deposit in checking account: ";
cin >> depositAmount;
checking->deposit(depositAmount);
monthStartBalance = depositAmount;
cout << "please enter amount to withdraw from checking account: ";
cin >> withdrawAmount;
checking->withdraw(withdrawAmount);
cout << "Month start balance: " << monthStartBalance << endl;
cout << "Total No of depost: " << checking->getNoOfDeposit() << endl;
cout << "Total no of withdrawl: " << checking->getNoOfWithdrawl() << endl;
cout << "Monthly service charge: " << checking->getMonthleServiceCharge() << endl;
cout << "Month Ending balance: " << checking->getbalance() << endl;
*/
cout<<"This is for your savings account "<<endl;
//Menu
int option1 = 0;
while(option1 != 5) {
cout<<" Menu: - 1) deposit 2) withdraw 3) check balance 4) monthly processing 5) exit ";
cin>>option1;
switch(option1) {
case 1:
cout << " please enter amount to deposit in checking account: ";
double depositAmount;
cin >> depositAmount;
checking->deposit(depositAmount);
cout<<" Your amount is deposited. Thank you.";
break;
case 2:
cout << " please enter amount to withdraw from checking account: ";
double withdrawAmount;
cin>> withdrawAmount;
checking->withdraw(withdrawAmount);
cout<<" You have withrawn your amount successfully.";
break;
case 3:
cout<<" Your balance is : "<<checking->getbalance();
break;
case 4:
checking->monthlyProc();
cout << " Total No of depost: " << checking->getNoOfDeposit() << endl;
cout << " Total no of withdrawl: " << checking->getNoOfWithdrawl() << endl;
cout << " Monthly service charge: " << checking->getMonthleServiceCharge() << endl;
cout << " Month Ending balance: " << checking->getbalance() << endl;
break;
case 5:
cout<<" Thank you.";
break;
default:
cout<<"Please select a correct option.";
break;
}
}
getchar();
return 0;
}
Sample Output:
This is for your savings account
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 1000
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 500
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
3
Your balance is : 1600
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from saving account: 1020
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
3
Your balance is : 580
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
4
Total No of depost: 2
Total no of withdrawl: 1
Monthly service charge: 0
Month Ending balance: 580
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 102
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 203
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 20302
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in saving account: 101
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
102
Please select a correct option.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
3
Your balance is : 21288
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
4
Total No of depost: 6
Total no of withdrawl: 1
Monthly service charge: 0
Month Ending balance: 21288
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from saving account: 100
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from saving account: 100
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from saving account: 100
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from saving account: 100
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
4
Total No of depost: 6
Total no of withdrawl: 5
Monthly service charge: 1
Month Ending balance: 20887
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
5
Thank you.This is for your savings account
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in checking account: 1000
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
1
please enter amount to deposit in checking account: 1000
Your amount is deposited. Thank you.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
2
please enter amount to withdraw from checking account: 200
You have withrawn your amount successfully.
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
3
Your balance is : 2300
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
4
Total No of depost: 2
Total no of withdrawl: 1
Monthly service charge: 5.1
Month Ending balance: 2300
Menu: -
1) deposit
2) withdraw
3) check balance
4) monthly processing
5) exit
5
Thank you.
--------------------------------
Process exited after 131.4 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.