Question: Remove all friend functions from the program. Begin by moving the prototypes for the + and < < friend functions to just after the end

Remove all friend functions from the program. Begin by moving the prototypes for the + and << friend functions to just after the end of the Fraction class definition; remove the friend keywords. The body of operator + will now take its two parameters (an integer and a fraction) and simply return the sum of a fraction and an integer, calling the Fraction method for addition with an integer on the right of the + operator. The body of operator << will now pass the outfile parameter to the method write, again returning outfile as its result. In both cases, the need to access private data has been replaced by access to public methods. Overload operator >> to read Fraction objects from a stream parameter. Reading an integer value stops when a non-digit, non-blank character is encountered; therefore, it is straightforward to read fractions as 3/5 or 2/7 if the / is read as a character and then discarded. Extend the Fraction class so that it includes implementations of these operators: - : both binary operator subtraction and unary operator negation * : multiplication / : division < : less-than > : greater-than <= : less-than or equal-to >= : greater-than or equal-to == : equal-to != : not equal-to All operations should allow for any possible combination of Fraction and int operands. Do not use floating-point operations in your relational operator implementations. Implement a test suite. Extend function main() to thoroughly test each of these operator implementations. Grading will be based in part on the thoroughness of the testing performed. Be sure to include tests that do not depend on user input! Someone running your program should be able to verify that your testing is successful (or unsuccessful) just by running the program and examining your testing code. NOTE: to test the input and output stream operations, you can use the std::istringstream and std::ostringstream objects from the library. These objects let you convert a string into a stream-like object, and vice-versa. istringstream can act as an input stream (hence, the i), and ostringstream can act as an output stream. A small example is shown below. More information is available online at these links: istringstream http://www.cplusplus.com/reference/sstream/istringstream/istringstream/ http://en.cppreference.com/w/cpp/io/basic_istringstream ostringstream http://www.cplusplus.com/reference/sstream/ostringstream/ostringstream/ http://en.cppreference.com/w/cpp/io/basic_ostringstream library http://www.cplusplus.com/reference/sstream/ http://en.cppreference.com/w/cpp/header/sstream Example of std::istringstream // Simple example of std::istringstream std::istringstream iss; // put your pre-planned input (separated by space) into iss... iss.str("1 2 3 4 5"); int sum = 0; while(iss.good()){ // You can test to see if the "stream" is still good! int temp; iss >> temp; // you can extract from iss like a stream! sum += temp; } std::cout << sum << ' '; // You can pass iss to a function expecting a stream! iss.clear(); // clear the state flags... iss.str("1 2 3 4 5"); // put some new values in... std::cout << sum_from_stream(iss) << ' '; Example of std::ostringstream // Simple example of std::ostringstream std::ostringstream oss; // oss will behave like an output stream. oss << "The sum of " << 3 << " plus " << 2 << " is " << (3+2) << ' '; // But you can get its contents as a string: std::string result = oss.str(); std::cout << result << ' '; // You could use this to do "output checks": std::string expected{ "The sum of 3 plus 2 is 5 " }; if(oss.str() == expected){ std::cout << "The strings match... "; } else{ std::cout << "The strings don't match. "; }

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!