Question
Write a rational number class. For now, we will use member functions add, sub, mul, div and less that each carry out the operations +,
Write a rational number class. For now, we will use member functions add, sub, mul, div and less that each carry out the operations +, -, *, /, and <. For example , a+b will be written as a.add(b), and a
The rational number is composed of two integers with division indicated as 2/3, 15/32. 65/4; the division is not carried out, it is only indicated. So in the rational number is represented by two int values, numerator and denominator.
The constructor is to create objects with any legal value, so the constructor will have two it parameters. Since every int is also a rational number, like 2/1 or 9/1, you should have a constructor with a single int parameter.
Member functions add, sub, mul, div will return a rational value; function less will return a bool value. These functions should do the operation suggested by the name.
Write a friend function addFraction, the function should have two parameters which are objects of rational number, the friend function will return a fraction object
Write a main function that will thoroughly tests your class implementation.
The following formulas will be useful in defining functions: a/b + c/d = (a*d +b*c)/b*d
a/b - c/d = (a*d - b*c)/b*d
a/b * c/d =(a*c) / (b*d)
(a/b) / (c/d) = (a*d) /(c*b)
(a/b><(c/d) means (a*d) <(c*b)
Let any sign be carried by the numerator, keep the denominator positive.
C++ program.
Step 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