Question: in c++ please rationals.cpp rationals.h test.cpp thankkkkkk youuuuu Part 2: Implement rational.cpp and run Lawton's tests Take a look at rationals.h-that file contains the declaration
in c++ please

rationals.cpp



rationals.h

test.cpp


thankkkkkk youuuuu
Part 2: Implement rational.cpp and run Lawton's tests Take a look at rationals.h-that file contains the declaration of the Rational class. You will implement its member functions in rationals.cpp. Anyone who wants to use your Rational class will #include your rationals.h! Now go to rationals.cpp and start implementing the methods-most of them are from last lab and require only minimal modification. The main new thing is the + operator to add two Rationals, which requires you to find a common denominator: ad + bc b'd bd a After you've completed rationals.cpp, run the tests in test.cpp. I've made 3 for you. Compile that with: g++ -std=C++17 test.cpp rationals.cpp -o test and run it. If the tests pass, you should see the following output: + solution git:(master) x ./test PASSED: Construct and simplify 27-44 PASSED: 2/-44 * -3/6 PASSED: 5/-45 + -7/42 + solution git:(master) Once those tests pass, it's your turn to write some. Part 3: Write your own tests To be extra extra confident in your implementation, you must write 2 more tests in the same style as the ones given in test.cpp. Feel free to adapt the ones you wrote for the previous lab. Add them to the end of the main function and get them to pass. Then you're all set to turn in your assignment! rationals.cpp > ... 1 #include "rationals.h" 2 3 #include 4 #include // for abs 5 #include // for to_string 6 using namespace std; 7 8 // FIXME: implement this method 9 Rational:: Rational(int n, int d) { 10 // set numer and denom, and then simplify 11 12 // remember that constructors don't return anything! 13 // They implicitly "return" a newly-made object. 14 } 15 16 // FIXME: implement this method 17 std::string Rational::toPrettyString() const { 18 // You can't call simplify anymore because of "const", but you 19 // should never need to because it'll be called for you now 20 // whenever a Rational is constructed. 21 22 // return a pretty version of the current object 23 24 return "stub"; 25 } 26 27 // FIXME: implement this method 28 Rational Rational::operator* (const Rational& other) const { 29 // return a new Rational that is the result of multiplying the current object 30 31 // remember that numer2 is other.numer now, etc. 32 33 // remember that simplification is done in the constructor, 34 // so you don't have to do it twice 35 36 return Rational (0, 0); 37 } return Rational(0, 0); 7 3 // FIXME: implement this method Rational Rational::operator+(const Rational& other) const { // return a new Rational that is the result of adding the current object with 2: 3 1 2 3 4 5 return Rational(0, 0); } 7 3 3 1 2. 3 4 5 5 7 3 /* There's no need for GCD to be a member function. */ int GCD(int a, int b) { while (b != 0) { int newA = b; int newB = a % b; a = newA; b = newB; } return a; } 1 2 3 1 // FIXME: implement this method to simplify the current object // If the number is negative, the numer should become negative (*not* the denom) void Rational: :simplify() { // Same as last lab, but there's no need for parameters! // numer and denom are member variables, so they're already defined -- // it's your job to change them here 7 3 // First, figure out if the rational number is negative or positive by // checking 3 cases: // 1. if numer 0, it's negative // 2. if numer > 0 and denom 0, it's negative // 2. if numer > 0 and denom 5 7 B 3 1 2 3 1 class Rational { public: // constructor--initializes the numerator and denominator to n and di Rational (int n, int d); // creates a pretty string for our Rational std::string toPrettyString() const; // multiplies two Rationals Rational operator* (const Rational& other) const; // adds two rationals Rational operator+(const Rational& other) const; 7 3 private: // we don't let the user call simplify--it's just for us void simplify(); 3 1 2 3 1 // member variables for numerator and denominator int numer; int denom; #endif 1 2 3 4. #include #include "rationals.h" using namespace std; 5 7 B void assertTrue(bool b, string description) { if (!b) { cout ... 1 #include "rationals.h" 2 3 #include 4 #include // for abs 5 #include // for to_string 6 using namespace std; 7 8 // FIXME: implement this method 9 Rational:: Rational(int n, int d) { 10 // set numer and denom, and then simplify 11 12 // remember that constructors don't return anything! 13 // They implicitly "return" a newly-made object. 14 } 15 16 // FIXME: implement this method 17 std::string Rational::toPrettyString() const { 18 // You can't call simplify anymore because of "const", but you 19 // should never need to because it'll be called for you now 20 // whenever a Rational is constructed. 21 22 // return a pretty version of the current object 23 24 return "stub"; 25 } 26 27 // FIXME: implement this method 28 Rational Rational::operator* (const Rational& other) const { 29 // return a new Rational that is the result of multiplying the current object 30 31 // remember that numer2 is other.numer now, etc. 32 33 // remember that simplification is done in the constructor, 34 // so you don't have to do it twice 35 36 return Rational (0, 0); 37 } return Rational(0, 0); 7 3 // FIXME: implement this method Rational Rational::operator+(const Rational& other) const { // return a new Rational that is the result of adding the current object with 2: 3 1 2 3 4 5 return Rational(0, 0); } 7 3 3 1 2. 3 4 5 5 7 3 /* There's no need for GCD to be a member function. */ int GCD(int a, int b) { while (b != 0) { int newA = b; int newB = a % b; a = newA; b = newB; } return a; } 1 2 3 1 // FIXME: implement this method to simplify the current object // If the number is negative, the numer should become negative (*not* the denom) void Rational: :simplify() { // Same as last lab, but there's no need for parameters! // numer and denom are member variables, so they're already defined -- // it's your job to change them here 7 3 // First, figure out if the rational number is negative or positive by // checking 3 cases: // 1. if numer 0, it's negative // 2. if numer > 0 and denom 0, it's negative // 2. if numer > 0 and denom 5 7 B 3 1 2 3 1 class Rational { public: // constructor--initializes the numerator and denominator to n and di Rational (int n, int d); // creates a pretty string for our Rational std::string toPrettyString() const; // multiplies two Rationals Rational operator* (const Rational& other) const; // adds two rationals Rational operator+(const Rational& other) const; 7 3 private: // we don't let the user call simplify--it's just for us void simplify(); 3 1 2 3 1 // member variables for numerator and denominator int numer; int denom; #endif 1 2 3 4. #include #include "rationals.h" using namespace std; 5 7 B void assertTrue(bool b, string description) { if (!b) { cout