Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 using namespace std; class Frac; ostream& operator

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:

image text in transcribed

image text in transcribed

image text in transcribed

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

image text in transcribed

Expected output:

image text in transcribed

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 After successfully completed the definitions of the above 5 groups of methods: 6. include the Special ++/-- Test Pattern (inside the testFrac_starter.cpp) as part of your final test program. Hint for the item 4 above: This test code is placed inside the testFrac_starter.cpp to generate the erroneous behavior described in the TODO List item 6: cout ,=, !=,== 4. Type conversion operators, to convert Frac numbers to integer or floating point numbers: cout > operator After successfully completed the definitions of the above 5 groups of methods: 6. include the Special ++/-- Test Pattern (inside the testFrac_starter.cpp) as part of your final test program. Hint for the item 4 above: This test code is placed inside the testFrac_starter.cpp to generate the erroneous behavior described in the TODO List item 6: cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions