Question
Hello I need help following the requirements for this C++ code. I have most of the code done. Code: Frac.h #pragma once #ifndef FRAC_H #define
Hello I need help following the requirements for this C++ code. I have most of the code done.
Code:
Frac.h
#pragma once #ifndef FRAC_H #define FRAC_H #include class Frac { private: long num; long den; public: // constructors Frac() { den = 1; } Frac(long n, long d) { num = n; den = d; } Frac(const Frac& obj) { *this = obj; } // *dereference this and assign new object to obj // outputs object as its numerator over its denominator friend ostream& operator // assignment operator (default) void operator= (const Frac& right) { num = right.num; den = right.den; } // math operators // num1/den1 + num2/den2 = // ((num1*den2) + (num2*den1))/(den1*den2) Frac operator+ (const Frac& right) { Frac temp; temp.num = ((num * right.den) + (den * right.num)); temp.den = (den * right.den); return temp; } Frac operator- (const Frac& right) { Frac temp; temp.num = ((num * right.den) - (den * right.num)); temp.den = (den * right.den); return temp; } Frac operator* (const Frac& right) { Frac temp; temp.num = (num * right.num); temp.den = (den * right.den); return temp; } Frac operator/ (const Frac& right) { Frac temp; temp.num = (num * right.den); temp.den = (den * right.num); return temp; } // comparison operators // greater than // (num1*den2) - (num2*den1) > 0 // (num1*den2) > (num2*den1) bool operator>(const Frac& right) { return (num * right.den) > (right.num * den); } bool operator bool operator==(const Frac& right) { return ((num == right.num) && (den == right.den)); } // preincrement and postincrement operators // pre ++ 3/4 return 4/4 the value after will be 4/4 // post ++ 3/4 return 3/4 the value after will be 4/4 // (int) signifies post nothing signifies pre Frac operator++() { ++num; return *this; } Frac operator++(int) { Frac copy = *this; ++num; return copy; } Frac operator--() { --num; return *this; } Frac operator--(int) { Frac copy = *this; --num; return copy; } }; #endif testFrac_starter.cpp #include "Frac.h" #include using namespace std; int main() { Frac x(3, 4); cout Frac z(x); cout //Frac v = x + y; //cout cout cout cout //cout cout cout cout } Requirements: - Provide the reason/explanation on why the increment/decrement test sequence (one statement vs 6 statements) produce different outcome. Expected output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started