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
#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;
}
Comments
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