Question: C++ language question Do Programming project 2 on page 697. The student may start with the attached code. Please notice that main function is given

C++ language question

Do Programming project 2 on page 697. The student may start with the attached code. Please notice that main function is given as well as several test functions. It is good idea to understand the main function and test functions first. When you implement the code, try to implement the functions are required for test 1 first. Commnent away the code in main function so that only test one part will be executed. After pass test one, then implement the functions that are required for test 2. This time, uncomment the code in main function that tests test 2. And so on. The program will tell you what is your grade for this program.

Photo from book:

C++ language question Do Programming project 2 on page 697. The student

Sample code:

/* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include  #include  #include  using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e 0 // member functions int get_numerator() const; // return the numerator of the fraction int get_denominator() const; // return the denominator of the fraction void reduce(); // reduce this fraction to simplest form. For instance, // 2/4 will be reduced to 1/2 Fraction reciprocal() const; // return the reciprocal of this Fraction // friend functions friend Fraction operator +(const Fraction& f1, const Fraction& f2); // return the sum of f1 and f2, // the result is reduced friend Fraction operator -(const Fraction& f1, const Fraction& f2); // return the difference of f1 and f2, // the result is reduced friend Fraction operator *(const Fraction& f1, const Fraction& f2); // return the product of f1 and f2, // the result is reduced friend Fraction operator /(const Fraction& f1, const Fraction& f2); // return the quotient of f1 and f2, // the result is reduced friend Fraction operator -(const Fraction& f); // return the negation of f friend bool operator  (const Fraction& f1, const Fraction& f2); // return true if f1 is greater than f2. // False otherwise friend bool operator = (const Fraction& f1, const Fraction& f2); // return true if f1 is greater or equal to f2. // False otherwise friend bool operator == (const Fraction& f1, const Fraction& f2); // return true if f1 is equal to f2. // False otherwise friend bool operator != (const Fraction& f1, const Fraction& f2); // return true if f1 is not equal to f2. // False otherwise friend istream& operator >> (istream& in, Fraction& f); // input f in the form of a/b, where b cannot be zero. Also, // if b is negative, the Fraction will change b to be positive. // So, again, 1/-3 will be changed to -1/3 friend ostream& operator , =, > and  0) cout  1.4) cout  0) cout  1.4) cout  0) cout  2.9) cout  if(f1 > f2 || !(f2 > f1) || f1 > f3) { cout  operator was wrong. "; result -= 0.5; } // Test == if(f1 == f2 || !(f1 == f3) || f2 == f3) { cout = if(f1 >= f2 || !(f1 >= f3) || !(f2 >= f3)) { cout  0) cout  1.9) cout > f; if(f.get_denominator() != 4 || f.get_numerator() != -3) { cout > choice; if(choice != 'y' && choice != 'Y') { cout  0) cout  0.9) cout   2. Define a class for rational numbers. A rational number is a number that be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By 1/2, etc., we mean the everyday meaning of the fraction, not the integer division this expression can would produce in a C++ program.) Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call the class Rational. Include a constructor with two arguments that can be used to set the member variables of an object to any legitimate values. Also include a constructor that has only a single parameter of type int; call this single parameter wholeNumber and define the constructor so that the object will be initialized to the rational number wholeNumber/1. Also include a default constructor that initializes an object to 0 (that is, to 0/1). Overload the input and output operators >> and  >=, +, -, , and /. Also write a test program to test your class. (Hints: Two rational numbers a/b and c/d are equal if a*d equals c*b. If b and d are positive rational numbers, a/b is less than c/d provided a*d is less than c*b. You should include a function to normalize the values stored so that, after normalization, the denominator is positive and the numerator and denominator are as small as possible. For example, after normalization 47-8 would be represented the same as -1/2. You should also write a test program to test your class.)

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!