// © Copyrights 2026 Praajna Pattada

#include <iostream>
#include <string>
#include <limits>

class BankAccount
{
    private:
        int balance;

    public:
        // Constructor for the class
        BankAccount(int initialBalance) : balance { initialBalance } {}

        std::string accountName {};
        friend BankAccount operator+(const BankAccount& acc1, const BankAccount& acc2); // Declaring the operator+ function as a friend of the BankAccount class allows it to access the private members
        void displayBalance();
};

void BankAccount::displayBalance()
{
    std::cout << "The current balance of " << accountName << " is " << balance << "." << '\n';
}

// This is a function to overload the '+' operator for the BankAccount class. It takes two BankAccount objects as parameters and returns a new BankAccount object as the result of the addition.
BankAccount operator+(const BankAccount& acc1, const BankAccount& acc2)
{
    // Add the given balances of the two BankAccount objects and return a new BankAccount object with the resulting balance.
    return (acc1.balance + acc2.balance);
}

int main()
{
    BankAccount Account1 { 8000 }; // Initializing Account1 with a balance of 10000
    Account1.accountName = "Account 1";
    Account1.displayBalance();
    BankAccount Account2 { 2000 }; // Initializing Account2 with a balance of 2000
    Account2.accountName = "Account 2";
    Account2.displayBalance();

    // Using the overloaded '+' operator to add the balances of Account1 and Account2, we create a new BankAccount object called 'NewAccount'
    BankAccount NewAccount { Account1 + Account2 };
    NewAccount.accountName = "New Account";
    NewAccount.displayBalance();

    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    std::cin.get();
    return 0;
}
