Hi Fatima

I think the below code can solve ur problem

Code:

#include <iostream>
class RationalNumber {
private:
int numerator;
int denominator;
public:
RationalNumber() : numerator(0), denominator(0) {}
RationalNumber(const int __numerator,
const int __denominator) : numerator(__numerator),
denominator(__denominator) {}
RationalNumber Add(RationalNumber __first, RationalNumber __second);
RationalNumber Sub(RationalNumber __first, RationalNumber __second);
RationalNumber Mul(RationalNumber __first, RationalNumber __second);
RationalNumber Div(RationalNumber __first, RationalNumber __second);
void Print();
};
RationalNumber RationalNumber::Add(RationalNumber __first,
RationalNumber __second) {
RationalNumber result;
result.denominator = __first.denominator * __second.denominator;
result.numerator = ((result.denominator / __first.denominator) * \
__first.numerator) + \
((result.denominator / __second.denominator) * \
__second.numerator);
return result;
}
RationalNumber RationalNumber::Sub(RationalNumber __first,
RationalNumber __second) {
RationalNumber result;
result.denominator = __first.denominator * __second.denominator;
result.numerator = ((result.denominator / __first.denominator) * \
__first.numerator) - \
((result.denominator / __second.denominator) * \
__second.numerator);
return result;
}
RationalNumber RationalNumber::Mul(RationalNumber __first,
RationalNumber __second) {
return RationalNumber( __first.numerator * __second.numerator, \
__first.denominator * __second.denominator);
}
RationalNumber RationalNumber::Div(RationalNumber __first,
RationalNumber __second) {
return RationalNumber(__first.numerator * __second.denominator, \
__first.denominator * __first.numerator);
}
void RationalNumber::Print() {
std::cout << numerator << " / " << denominator << std::endl;
}
int main() {
RationalNumber number_A(3, 5);
RationalNumber number_B(4, 7);
RationalNumber result;
result = result.Add(number_A, number_B);
result.Print();
result = result.Sub(number_A, number_B);
result.Print();
result = result.Mul(number_A, number_B);
result.Print();
result = result.Div(number_A, number_B);
result.Print();
return 0;
}

Let me knw did u get that or not ??