Question: Hello I need help with these requirements for the C++ program. The program is almost all written. I will rate fast. Thanks. Requirements: - Provide
Hello I need help with these requirements for the C++ program. The program is almost all written. I will rate fast. Thanks.
Requirements:





- Provide the reason/explanation on why the increment/decrement test sequence (one statement vs 6 statements) produce different outcome.

Expected output:

Frac.h
// Function Prototypes for Overloaded Stream Operators // Forward declaration needs to be filled // if multifiles are used, make sure to place the inclusion guard. #include
ostream &operator > (istream &, Frac &); class Frac { private: int num, den; long gcd(long a, long b) Frac lowterms(Frac &f); public: Frac(); Frac(string s); Frac(int num_, int den_); Frac(const Frac& rhs); Frac operator=(const Frac& rhs); // math + - * must be minimum term, i.e. no 2/8 Frac operator + (Frac &rhs); Frac operator - (Frac &rhs); Frac operator * (Frac &rhs); Frac operator / (Frac &rhs); // increment ++ decrement -- Frac operator++(); Frac operator++(int); Frac operator--(); Frac operator--(int); // comparators bool operator == (Frac &f2); bool operator != (Frac &f2); bool operator (Frac &rhs); bool operator = (Frac &f2); // overloading >> >(istream& strm, Frac& f); friend ostream& operator
testFrac.cpp
///////////////////////////////////////////////////////////// // This starter is a one-file all inclusive test appliation. // This starter combines with the necessary Frac definition. // Do not re-include the Frac.h // If you prefer a multiple file approach, separte them cleanly. ///////////////////////////////////////////////////////////// #include
using namespace std;
class Frac; ostream &operator
class Frac { long num; long den; public: // Frac() { num=0; den=1; } Frac() : num(0), den(1) {} Frac(long n, long d) {num=n; den=d;} Frac(const Frac &obj) {*this = obj;} void operator=(const Frac &rhs) { num = rhs.num; den = rhs.den; } // Frac a = b; // string constructor is challenging, worth 2 pts, try your best! Frac(string s); // math operators Frac operator+(const Frac &rhs) { Frac temp; temp.num = num*rhs.den + rhs.num*den; temp.den = den*rhs.den; // need to apply lower term by / gcd here return temp; }
// postfix increment operator ++ -- Frac operator++() { num += den; // lowterms(*this); return *this; } Frac operator--() { num -= den; // lowterms(*this); return *this; } // overload ostream insertion operator
int main() { Frac x(3,4); Frac y(1,2); cout
// Turn on this one when you completed the definition of string constructor // Frac s("6/7"); // passing a Frac number as a string. // cout
Frac z(x); cout
cout The form and format the Fractional number to be used In this project, We are only going to (1) use two numbers: numerator over denominator to represent a fraction, no mixed numerals. (2) allow the usage of the proper and improper fraction: Proper Fraction: the number is inferior to the denominator, for instance 3/4; Improper fraction: the numerator is superior to the denominator, for instance 9/2; We are not going to use Mixed Fraction and Equivalent Fractions: Mixed Fraction or Mixed Numeral: it is composed of a whole part and a fractional one, for instance 2 1/3; Equivalent Fractions: fractions that keep on the same proportion of another fraction, for instance: 5/2 =10/4; All Fraction shall be the minimum number representation. TODO List To complete the definition of all Five (5) Required Frac class method groups: 1. Constructors: * you may combine the first 3 contructors below into one. default: numerator default as 0, denominator default as 1 1 argument: (int numerator) numerator only, denominator default as 1 2 arguments: (int numerator, int denominator) string constructor: (string s); where s in the format of "3/4" 2. Necessary getter and setters 3. Support the following operators: basic math: +,-*./ pre and postfix ++ and -- comparators: ,=, !=,== 4. Type conversion operators, to convert Frac numbers to integer or floating point numbers: cout > operator Part-2 Sequence of operations in 1 statements vs. 6 statements 5 pts To include the Special ++/-- Test Pattern (inside the testFrac_starter.cpp) as part of your final test program. // line #74 onward cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
