Answer to Question #193023 in C++ for Ajith M

Question #193023

To evaluate the following equation A=B%3, where A and B are two objects of the same class. Develop a C++ program to implement this using operator overloading with friend function


1
Expert's answer
2021-05-16T00:29:49-0400
#include <iostream>

using namespace std;

class Number {
private:
    int value;
public:
    explicit Number(int value) {
        this->value = value;
    }
    int get_value() const {
        return this->value;
    }
    friend Number * operator%(const Number &a, const Number &b) {
        return new Number(a.value % b.value);
    }
};

int main() {

    auto A = new Number(9);
    auto B = new Number(5);

    cout << (*A % *B)->get_value(); // 9 % 5 = 4

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Boopathi
15.05.21, 18:02

To evaluate the following equation A=B%3, where A and B are two objects of the same class. Develop a C++ program to implement this using operator overloading with friend function.

Leave a comment

LATEST TUTORIALS
New on Blog