C++



Write a class called Bank. Which consist of the below members.



Member Variables:



·         account_ID

·         account_Name

·         national_Id_card_Number

·         account_Balance



Member Functions:



·         Two constructor, one is empty and another one is with parameter to initialize member variables

·         showInformation() method to show the information

·         deposit(int amount) method for deposit money

·         withdraw(int amount) method for withdraw money

·         and transferMoney(Bank *acc1, Bank *acc2, int amount) method for transfer money from one account to another account


#    #include <iostream>
#include<string>
#include<cstdlib>
using namespace std;
class bank{
    int acc_id;
    string acc_name;
    int national_id;
    int acc_balance;
public:
    bank();
    bank(int n, string st, int m, int b);
    void show_information();
    void deposit_money(int m);
    void withdraw(int m);
    int current_balance();
    void transfer_money(bank *acc1,bank *acc2, int amount);
};
bank::bank(int n, string st, int m, int b){
    acc_id= n;
    acc_name= st;
    national_id= m;
    acc_balance=b;
}

void bank::deposit_money(int x){
    acc_balance=acc_balance+x;
}
void bank::withdraw(int x){
    acc_balance=acc_balance-x;
}
void bank::transfer_money(bank *acc1,bank *acc2, int amount){
    acc1->withdraw(amount);
    acc2->deposit_money(amount);
    acc1->show_information();
    acc2->show_information();
}
int bank::current_balance(){
        return acc_balance;
}
void bank::show_information(){
    cout<< " account id : "<< acc_id<<endl;
    cout<< " account name : " << acc_name<<endl;
    cout<< " national id : " << national_id<<endl;
    cout<< " account balance: " << acc_balance<<endl;
}

int main(){
    bank a (1134,"alex",125655, 50000), b1(1456,"john",125465,60000);
    int choice;
    int b;
    cout<<"enter 1 to deposit money\n enter 2 to withdraw money\n enter 3 to check money\n enter 4 to transfer money\n enter 5 to exit\n";
        cin>>choice;
        switch(choice){
            case 1: cout<<"Current Balance: "<<a.current_balance()<<endl;
                cout<<"Enter amount to deposit: \n";
                cin>>b;
                a.deposit_money(b);
                cout<<a.current_balance()<<endl;
                break;
        case 2: cout<<"Current Balance: "<<a.current_balance()<<endl;
                cout<<"Enter amount to withdraw: \n";
                cin>>b;
                a.withdraw(b);
                cout<<a.current_balance()<<endl;
                break;
        case 3: a.show_information();
                break;
        case 4: a.show_information();
                b1.show_information();
                int amount;
                cout<<"Enter amount to transfer: \n";
                cin>>amount;
                a.transfer_money(&a, &b1, amount);
                break;
        case 5: cout<<"Exiting...";
                exit(4);
                break;
        default:
                cout<<"Wrong Number\n";
    }
         return 0;
    }
  
   






       
































 


Comments