Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Operator Overloading You are creating a program for a Bank to manage Accounts. The given code declares an Account class which has a

In C++

Operator Overloading

You are creating a program for a Bank to manage Accounts. The given code declares an Account class which has a balance and interest members. The bank asks you to add a new functionality to merge two accounts together, resulting in a new account with the sum of the balances and interests of the given accounts. Overload the + operator to allow adding two Account objects, adding the balances and interests.

The overloaded operator should return a new Account object, with the corresponding member values.

#include

using namespace std;

class Account {

private:

int balance=0;

int interest=0;

public:

Account() {}

Account(int a): balance(a)

{

interest += balance/10;

}

int getTotal() {

return balance+interest;

}

//your code goes here

};

int main() {

int n1, n2;

cin >> n1 >> n2;

Account a(n1);

Account b(n2);

Account res = a+b;

cout << res.getTotal();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions