Question
Operator Overloading Problems, Augment the code below to answer in c++ #include #include #include using namespace std; class RationalNumber { public: RationalNumber(): RationalNumber(0, 1) {
Operator Overloading Problems, Augment the code below to answer in c++
#include
class RationalNumber { public: RationalNumber(): RationalNumber(0, 1) { } RationalNumber(int n): RationalNumber(n, 1) { } RationalNumber(int n, int d); int getNumerator() const { return numerator; } int getDenominator() const { return denominator; } void setNumerator(int n) { numerator = n; } void setDenominator(int d) { denominator = d;}
static int gcd(int a, int b); static int lcm(int a, int b); void reduce();
void output() const { cout
RationalNumber::RationalNumber(int n, int d) { if(d == 0) { cout
int temp; while(b != 0) { temp = a; a = b; b = temp%b; } return a; }
int RationalNumber::lcm(int a, int b) {
return (a*b)/gcd(a, b); }
void RationalNumber::reduce() {
int x = gcd(numerator, denominator); numerator = numerator/x; denominator = denominator/x; }
int main() { RationalNumber r1{12, 18}; cout
8. Augment the code in problem 7. a. Overload the and operators. b. Verify both functions are working properly. 9. Augment the code in problem 8. a. Overload the ,!-, >, > (extraction) operators b. Verify that all functions are working properly. 11. Augment the code in problem 10 a. Overload the [ (bracket) operator. b. Verify that all functions are working properlyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started