Question: In c++ please Rationals.h file rationals.cpp file The sampleProgram.cpp We're gonna make a rational number library! Take a look at rationals.h-that file contains the declarations

In c++ please

In c++ please Rationals.h file rationals.cpp file The sampleProgram.cpp We're gonna make

Rationals.h file

a rational number library! Take a look at rationals.h-that file contains the

rationals.cpp file

declarations for three functions that you will implement in rationals.cpp. Anyone who

wants to use your library will #include your rationals.h! Now go to

The sampleProgram.cpp

rationals.cpp and start implementing the functions. You should see a GCD function

We're gonna make a rational number library! Take a look at rationals.h-that file contains the declarations for three functions that you will implement in rationals.cpp. Anyone who wants to use your library will #include your rationals.h! Now go to rationals.cpp and start implementing the functions. You should see a GCD function implemented for you already-you'll use that in your rationalSimplify function to simplify the numerator and denominator of a rational number. Notice that rationalSimplify and rationalTimes do not return anything-rather, they have some reference parameters that will automatically get changed thanks to the magic of call-by-reference. rational PrettyString returns the string form of a rational number. Remember to give back a string and to not print anything out. I've made a program called sample Program.cpp that will help you test out your solution. Compile it with: g++ -std=c++17 sampleProgram.cpp rationals.cpp -o sampleProgram (remember to include rationals.cpp-g++ needs the implementation when it links your program!). Here's what the output should look like given some sample inputs: solution git:(master) X ./sampleProgram Enter first numerator: 2 Enter first denominator: -22 Enter second numerator: 4 Enter second denominator: 8 Simplified first number: -1 / 11 Second number: 1 / 2 First number * Second number: -1 / 22 solution git: (master) X We're gonna make a rational number library! Take a look at rationals.h-that file contains the declarations for three functions that you will implement in rationals.cpp. Anyone who wants to use your library will #include your rationals.h! Now go to rationals.cpp and start implementing the functions. You should see a GCD function implemented for you already-you'll use that in your rationalSimplify function to simplify the numerator and denominator of a rational number. Notice that rationalSimplify and rationalTimes do not return anything-rather, they have some reference parameters that will automatically get changed thanks to the magic of call-by-reference. rational PrettyString returns the string form of a rational number. Remember to give back a string and to not print anything out. I've made a program called sample Program.cpp that will help you test out your solution. Compile it with: g++ -std=c++17 sampleProgram.cpp rationals.cpp -o sampleProgram (remember to include rationals.cpp-g++ needs the implementation when it links your program!). Here's what the output should look like given some sample inputs: solution git:(master) X ./sampleProgram Enter first numerator: 2 Enter first denominator: -22 Enter second numerator: 4 Enter second denominator: 8 Simplified first number: -1 / 11 Second number: 1 / 2 First number * Second number: -1 / 22 solution git: (master) X HO C rationals.h > ... 1 #ifndef RATIONALS_H 2 #define RATIONALS H 3 4 #include // see the .cpp file for a more thorough description of the functions // convert a rational # to a nice-looking string std::string rationalPrettyString(int numer, int denom); 6 7 8 9 10 11 12 13 14 15 16 17 // multiply two rational numbers void rationalTimes (int numeri, int denomi, int numer2, int denom2, int& resultNumer, // simplify a rational # to lowest terms void rationalSimplify(int& numer, int& denom); #endif File Edit Selection View Go Run Terminal Help u C rationals.cpp X E rationals.cpp > GCD(int, int) #include "rationals.h" 2 3 #include 4 #include // for abs 5 #include // for to_string 6 using namespace std; 7 8 9 Calculates the greatest common divisor of a and b using Euclid's algorithm. A 10 We need this function to use in our rationalSimplify function. 13 14 15 16 17 18 19 20 This is a function our user doesn't get to see/know about, so we won't put it in the .h file. */ int GCD(int a, int b) { while (b != 0) { int newA = b; int newB = a % b; a = newA; b = newB; return a; /* If the number is negative, the numer should become negative (*not* the denom). void rationalSimplify(int& numer, int& denom) { // FIXME: implement this function 34 35 // FIXME: 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 (9 Left File Edit Selection View Go Run Terminal Help sample Program.cpp X Co sample Program.cpp > . 1 #include 2 #include "rationals.h" 3 using namespace std; 4 5 int main() { 6 int numeri, denomi, numer2, denom2; 7 cout > numerl; 9 cout > denoml; cout > numer2; cout > denom2; cout (9 Left

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!