Use C++ I need three files, one main.cpp file, one rational.cpp file and one rational.h file. I'll put the code for the main.cpp file and rational.h file below. No need to change them I just need the rational.cpp file. Modify the code to have operator overloading functions with the following operators. ==, <, <=, >, >=, +, -, *, / Use the Rational interface and main code in the next page. main.cpp: #include #include "rational.h" int main() { Rational r1, r2; char answer = 'y'; while (answer == 'y') { cout << "Enter the first fraction (e.g. 3/4) : "; cin >> r1; cout << "Enter the second fraction (e.g. 3/4) : "; cin >> r2; cout << "r1 : " << r1 << endl; cout << "r2 : " << r2 << endl << endl; cout << "r1 + r2 = " << r1 + r2 << endl; cout << "r1 - r2 = " << r1 - r2 << endl; cout << "r1 * r2 = " << r1 * r2 << endl; cout << "r1 / r2 = " << r1 / r2 << endl << endl; cout << "r1 == r2 -> " << (r1 == r2) << endl; cout << "r1 < r2 -> " << (r1 < r2) << endl; cout << "r1 <= r2 -> " << (r1 <= r2) << endl; cout << "r1 > r2 -> " << (r1 > r2) << endl; cout << "r1 >= r2 -> " << (r1 >= r2) << endl << endl; cout << "Again (y/n)? "; cin >> answer; } return 0; } rational.h: #include #include using namespace std; class Rational { public: Rational(); Rational(int); Rational(int, int); friend istream& operator >>(istream&, Rational&);// input function friend ostream& operator<<(ostream&, const Rational&);// output function // Arithmetic operators (+, -, *, /) friend Rational operator+(const Rational&, const Rational&); friend Rational operator-(const Rational&, const Rational&); friend Rational operator*(const Rational&, const Rational&); friend Rational operator/(const Rational&, const Rational&); // Relational operators (==, >, <, >=, <=) friend bool operator==(const Rational&, const Rational&); friend bool operator>(const Rational&, const Rational&); friend bool operator<(const Rational&, const Rational&); friend bool operator>=(const Rational&, const Rational&); friend bool operator<=(const Rational&, const Rational&); private: int numerator; int denominator; void simplify(); }; make the code run the same as in the picture
Use C++
I need three files, one main.cpp file, one rational.cpp file and one rational.h file. I'll put the code for the main.cpp file and rational.h file below. No need to change them I just need the rational.cpp file.
Modify the code to have operator overloading functions with the following operators.
==, <, <=, >, >=, +, -, *, /
Use the Rational interface and main code in the next page.
main.cpp:
#include <iostream>
#include "rational.h"
int main()
{
Rational r1, r2;
char answer = 'y';
while (answer == 'y') {
cout << "Enter the first fraction (e.g. 3/4) : "; cin >> r1;
cout << "Enter the second fraction (e.g. 3/4) : "; cin >> r2;
cout << "r1 : " << r1 << endl;
cout << "r2 : " << r2 << endl << endl;
cout << "r1 + r2 = " << r1 + r2 << endl;
cout << "r1 - r2 = " << r1 - r2 << endl;
cout << "r1 * r2 = " << r1 * r2 << endl;
cout << "r1 / r2 = " << r1 / r2 << endl << endl;
cout << "r1 == r2 -> " << (r1 == r2) << endl;
cout << "r1 < r2 -> " << (r1 < r2) << endl;
cout << "r1 <= r2 -> " << (r1 <= r2) << endl;
cout << "r1 > r2 -> " << (r1 > r2) << endl;
cout << "r1 >= r2 -> " << (r1 >= r2) << endl << endl;
cout << "Again (y/n)? ";
cin >> answer;
}
return 0;
}
rational.h:
#include<iostream>
#include<cstdlib>
using namespace std;
class Rational
{
public:
Rational();
Rational(int);
Rational(int, int);
friend istream& operator >>(istream&, Rational&);// input function
friend ostream& operator<<(ostream&, const Rational&);// output function
// Arithmetic operators (+, -, *, /)
friend Rational operator+(const Rational&, const Rational&);
friend Rational operator-(const Rational&, const Rational&);
friend Rational operator*(const Rational&, const Rational&);
friend Rational operator/(const Rational&, const Rational&);
// Relational operators (==, >, <, >=, <=)
friend bool operator==(const Rational&, const Rational&);
friend bool operator>(const Rational&, const Rational&);
friend bool operator<(const Rational&, const Rational&);
friend bool operator>=(const Rational&, const Rational&);
friend bool operator<=(const Rational&, const Rational&);
private:
int numerator;
int denominator;
void simplify();
};
make the code run the same as in the picture
![Enter the first fraction (e.g. 3/4): 3/5
Enter the second fraction (e.g. 3/4): 2/6
r1: 3/5
r2: 1/3
- r1 + r2 = 14/15
- r1 - r2 = 4/15
- r1 * r2 = 1/5
- r1 / r2 = 9/5
- r1 == r2 -> 0
- r1 != r2 -> 1
- r1 >= r2 -> 1
- r1 <= r2 -> 0
- r1 > r2 -> 1
- r1 < r2 -> 0
Again (y/n)? y
Enter the first fraction (e.g. 3/4): 4/7
Enter the second fraction (e.g. 3/4): 1/2
r1: 4/7
r2: 1/2
- r1 + r2 = 15/14
- r1 - r2 = 1/14
- r1 * r2 = 2/7
- r1 / r2 = 8/7
- r1 == r2 -> 0
- r1 != r2 -> 1
- r1 >= r2 -> 1
- r1 <= r2 -> 0
- r1 > r2 -> 1
- r1 < r2 -> 0
Again (y/n)? n](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcdbdf4c8-5459-45de-99f8-cd8d71031beb%2Fcb1536d1-545d-40a8-a64d-345e76d82876%2F1b2t6k5_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)