In this lab assignment, using polymorphism. Starting with create a class Bank ,
ID: 3696371 • Letter: I
Question
In this lab assignment, using polymorphism. Starting with create a class Bank , this
will be the base class in this project. The private data of this class will be vector of bank
accounts. Each bank account will contain the account number (random 4digit
integer), account type (saving or checking), and balance of the account. The base class and Account can be
declared as suggested in the follows:
enum account_type {saving, checking}
class Account {
public:
Account ()
~Account()
private:
int account_number
account_type type
double balance
}
class Bank {
public:
Bank()
~Bank()
// additional functions as needed
virtual void deposit() = 0
virtual void withdraw() = 0
private:
vector <Account> bank_accounts
}
Create 2 other derived classes from the base class called Saving and Checking. Redefine the
deposit and withdraw functions for each class as follow:
For Saving class
when call deposit function, a new amount (can be zero) will be added to the
current balance along with the interest from the original balance
when call withdraw function, check if the amount is valid (cannot exceed the
current balance)
For Checking class
when call deposit function, a new amount (cannot be zero) will be added to the
current balance a transaction fee will be subtracted from the balance.
when call withdraw function, check if the amount is valid (cannot exceed the
current balance minus the transaction fee) withdraw the amount and subtract the
transaction fee from the balance.
When making the bank accounts, the account numbers will be the random 4digit
integers the initial balances will be the random double value between $0 and $100.00 the account type will
be either saving or checking.
The interest rate will be 0.01 for all saving accounts. The transaction rate will be $0.50 for all
checking account. Start the program by making 5 random accounts. The following is the sample
inputs and outputs
Select the following options
1. Add new account
2. Deposit to an account
3. Withdraw from an account
4. Print all accounts
5. Quit 4
Account number Type Balance
1123 Saving 23.45
5432 Checking 54.65
7421 Checking 87.34
2376 Saving 65.76
5341 Checking 65.34
Select the following options
1. Add new account
2. Deposit to an account
3. Withdraw from an account
4. Print all accounts
5. Quit 1
Enter account number: 1111
Enter account type: Saving
Enter account balance: 123
Account number Type Balance
1123 Saving 23.45
5432 Checking 54.65
7421 Checking 87.34
2376 Saving 65.76
5341 Checking 65.34
1111 Saving 123.00
Select the following options
1. Add new account
2. Deposit to an account
3. Withdraw from an account
4. Print all accounts
5. Quit 2
Enter account number: 2376
Enter amount: 50
Deposit $50.00 to Saving account 2376, the new balance is $116.41
Select the following options
1. Add new account
2. Deposit to an account
3. Withdraw from an account
4. Print all accounts
5. Quit 3
Enter account number: 7421
Enter amount: 50
Withdraw $50 from Checking account 7421, the new balance is $36.84
Select the following options
1. Add new account
2. Deposit to an account
3. Withdraw from an account
4. Print all accounts
5. Quit 5
Program terminated
Explanation / Answer
#include<iostream>
#include<cstdlib>
using namespace std;
class Account
{
private:
char name[10],type[10];
int acc_no,balance;
public:
void enterdata(void)
{
cout<<"enter name of person";
cin>>name;
cout<<"enter type of account";
cin>>type;
cout<<"enter account no.";
cin>>acc_no;
cout<<"enter balance";
cin>>balance;
}
void deposit(void)
{
int n;
cout<<"enter amount to deposit";
cin>>n;
cout<<"total is:"<<balance+n;
balance=balance+n;
}
void withdraw(void)
{
int w;
cout<<"balance is:"<<balance;
cin>>w;
cout<<"balance is:"<<balance-w;
balance=balance-w;
}
void dispdata(void)
{
cout<<"name:"<<name;
cout<<"balance left:"<<balance;
}
};
int main(void)
{
Account b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
int k,i,choice;
while(k)
{
cout<<" 1.To assign the initial values ";
cout<<"2.To deposit an amount ";
cout<<"3.To withdraw an amount ";
cout<<"4.To display name and balance ";
cout<<"5.Exit ";
cin>>choice;
switch(choice)
{
case 1: b1.enterdata();
break;
case 2: b1.deposit();
break;
case 3: b1.withdraw();
break;
case 4: b1.dispdata();
break;
case 5: exit(0);
break;
default:
cout<<"wrong choice";
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.