Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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<<"\n";
- } 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 << "\n";
- }
- 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" << "\n";
- }
- }
- 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<<"\n";
- } 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
- --------------*/
Advertisement
Add Comment
Please, Sign In to add comment