DST Practicals - Important

 IMPORTANT

Ex0018: Question from July21 Question paper (basic solution, modify it to make it more appropriate)

Write a C++ program to create class named Bank Account with data member like acc_no and balance, Create two constructor- One without argument and another with argument to initialize the data member. Create showBalance method to display the current balance. Also create withDraw method to withdraw amount from the bank. Create two objects of the class and perform withdraw operation. Display balance for both the accounts before and after withdraw operation

#include <iostream>

using namespace std;

class bankAccount{

    private:

        int accnumber;

        float balance;

    public:

        bankAccount(){

            accnumber = 0;

            balance = 0;

        }

        bankAccount(int x, float y){

            accnumber = x;

            balance = y;

        }

       float showBalance(){

            cout << "Current balance of account number " << accnumber << " is = " << balance<<endl;

        }

       void withdraw(float z){

            balance = balance - z;

        }

};

int main() {

    cout << "****Welcome to my baking system****\n\n\n\n";

    bankAccount acc1(1,1000);

    bankAccount acc2(2,2000);

    acc1.showBalance();

    acc2.showBalance();

    acc1.withdraw(500);

    acc2.withdraw(200);

    cout << "\n\n\n\n\n Amounts after withdrawal \n\n";

    acc1.showBalance();

    acc2.showBalance();

}

Comments