Pages

Sunday, May 18, 2025

Bank Account Assigment Question in OOPs

 #include <iostream>

using namespace std;

class BankAccount {
private:
    int accNumber;
    float balance;

public:
    // Constructor
    BankAccount(int accNum, double bal) {
        accNumber = accNum;
        balance = bal;
    }

    // Deposit money
    void deposit(double amount) {
        balance += amount;
        cout << "Deposited: " << amount << endl;
    }

    // Withdraw money
    void withdraw(double amount) {
        if (amount <= balance) {
            balance -= amount;
            cout << "Withdrawn: " << amount << endl;
        } else {
            cout << "You have insufficient balance." << endl;
        }
    }

    // Get current balance
    void getBal() {
        cout << "Your account balance: " << balance << endl;
    }
};

int main() {
    BankAccount raju(123456789, 1000.00);  // Account with ₹1000

    raju.deposit(200);     // Deposit ₹200
    raju.withdraw(500);    // Withdraw ₹500
    raju.getBal();         // Check balance

    return 0;
}


OUTPUT:
Deposited: 200 Withdrawn: 500 Your account balance: 700

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...