Question: In C++, please help create a new file to work for an operator overload and rational number objects. I want some explanation with comments in
In C++, please help create a new file to work for an operator overload and rational number objects. I want some explanation with comments in the new file which I want to call Rational.cpp. I was given two files that will not be edited as the point was to create a new file and work the other two files in. Also, maybe add in another h file but I don't know. In the new file called rational.cpp I need to create a class called Rational that holds two values of the numerator and denominator of a rational fraction. Also, provide the following operators as member functions: *, /, +, -, =, ==, and !=.
Overload <, and conversion to double and provide two constructors as well. Finally, add safety with no common factor for the numerator and denominator other than 1, in which the denominator of 0 is 1. The denominator is positive, and the negative numbers have a negative numerator.
The two files being provided must not be changed; all code can work with the new file.
Assert.h
#ifndef ASSERT_H #define ASSERT_H #include
hw3.cpp
#include
The output that we should get:
Handles zero over anything as 0 over 1 OK Normalizes Rational(99,33) in the constructor. OK (1/3) * (100/1) = (100/3) OK (3/7) / (1/7) = (3/1) OK OK OK (1/3) + (2/5) = (11/15) OK (2/3) - (1/6) = (1/2) OK OK (11/15) = (11/15) = (11/15) OK OK 0.73333333333
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
