Part A: Basic LO Create a file lab10a.cpp and write a C++ program that prints ou
ID: 3811422 • Letter: P
Question
Part A: Basic LO Create a file lab10a.cpp and write a C++ program that prints out the prompt "bank>"and waits for user input. The user can enter the following commands: "deposit withdraw balance" and "quit". Repeat the prompt after handling each user input. If the user selects "deposit", print out "DEPOSIT SELECTED If the user selects "withdraw", print out "WTTHDRAWSELECTED". If the user selects "balance", print out "BALANCE SELECTED". If the user selects "quit", exit the program. e execution bank deposit DEPOSIT SELECTED bank withdraw WITHDRAW SELECTED bank balance BALANCE SELECTED bank quit Part B: C++ Classes Create a copy of lab10b.cpp adapt your I/O from part l to accommodate the following functionality (Note: You will need to create additional files for the class implementation and you will l to create an instance of type Bank in your have lab10b.cpp file): Implement a C+ class Bank. Your bank will contain 10 accounts, whose account numbers range from 0 to 9. Bank contains the following public functions (you can choose the return type):Explanation / Answer
/*
PART - A: Please find the required solution:
--------------------------------------------
*/
#include <iostream>
using namespace std;
int main()
{
string input;
do
{
cout << "bank>";
cin >> input;
if(input.compare("deposit") == 0)
cout << "DEPOSIT SELECTED";
else if(input.compare("withdraw") == 0)
cout << "WITHDRAW SELECTED";
else if(input.compare("balance") == 0)
cout << "BALANCE SELECTED";
else if(input.compare("quit")!= 0 )
cout << "Please select correct operation";
cout<<" ";
} while(input.compare("quit") != 0);
return 0;
}
/*
Sample output:
--------------
bank>deposit
DEPOSIT SELECTED
bank>withdraw
WITHDRAW SELECTED
bank>balance
BALANCE SELECTED
bank>quit
*/
/*
PART - B: Please find the required solution:
--------------------------------------------
*/
#include <iostream>
using namespace std;
class Bank
{
int account_balance[10] ;
public:
void initialize() {
for(int i=0 ; i<10;i++)
account_balance[i] = 0;
};
void deposit (int num,int value);
void withdraw (int num,int value);
int balance(int num);
void transfer(int from, int to, int value);
};
void Bank::deposit (int num, int value)
{
account_balance[num] = account_balance[num] + value;
}
void Bank::withdraw (int num, int value)
{
if(account_balance[num] >= value)
account_balance[num] = account_balance[num] - value;
else
cout << "Insufficient Balance in account" << num << " ";
}
int Bank::balance (int num)
{
return account_balance[num];
}
void Bank::transfer(int from, int to, int value)
{
if(account_balance[from] >= value)
{
account_balance[from] = account_balance[from] - value;
account_balance[to] = account_balance[to] + value;
}
else
{
cout << "Error! funds exceeded" << " ";
}
}
int main()
{
Bank bank;
string input;
int num1,num2,value;
bank.initialize();
do
{
cout << "bank>";
cin >> input ;
if(input.compare("balance") == 0) {
cin >> num1;
cout << bank.balance(num1);
}
else if(input.compare("deposit") == 0){
cin >> num1 >> num2;
bank.deposit(num1,num2);
}
else if(input.compare("withdraw") == 0){
bank.withdraw(num1,num2);
}
else if(input.compare("transfer") == 0){
cin >> num1 >> num2 >> value;
bank.transfer(num1,num2,value);
}
else if(input.compare("quit")!= 0 )
cout << "Please select correct operation";
cout<<" ";
} while(input.compare("quit") != 0);
return 0;
}
/*
Sample output:
bank>deposit 3 50
bank>balance 3
50
bank>balance 8
0
bank>transfer 3 8 20
bank>balance 3
30
bank>balance 8
20
bank>transfer 3 2 40
Error! funds exceeded
bank>quit
--------------*/