Question
// I really need help. Please follow the instructions and solve it by C++. For Part 1 The output should be like this TODO List
// I really need help. Please follow the instructions and solve it by C++.
For Part 1 The output should be like this
TODO List
Part-1
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
- One (1) argument Fill Constructor: (int numerator) numerator only, denominator default as 1
- Two (2) arguments Fill Constructor: (int numerator, int denominator)
- String Constructor: (string s); where s in the format of "3/4"
2. Necessary getters and setters
3. Support the following operators:
- basic math: +, -, *. /
- pre and postfix ++ and -- (4 different types)
- comparators: , =, !=, ==
4. Type conversion operators, to convert Frac numbers to integer or floating point numbers:
cout5. Test overload friend iostream insertion , and extraction >> 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 coutAfter successfully implemented and executed your program:
Hint for the Part-2 above:
This test code is placed inside the testFrac_starter.cpp to generate the erroneous behavior described in the TODO List item 6:
cout/////////////////// CODE ///////////////
(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
class Frac;
ostream &operator const Frac &);
istream &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
bool operator > (Frac &rhs);
bool operator
bool operator >= (Frac &f2);
// overloading >>
friend istream& operator>>(istream& strm, Frac& f);
friend ostream& operatorconst Frac& f) {
};
//////////////////
(testFrac_starter.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
#include
#include // stringstream
using namespace std;
class Frac;
ostream &operatorconst &rhs);
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
friend ostream &operatorconst &rhs) {
stm
};
int main() {
Frac x(3,4);
Frac y(1,2);
cout
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
Frac v = x + y;
cout
cout
Frac f(5,6);
cout // start
// end of one statement
cout
cout
cout
cout
cout
cout
cout
}
Part-1.1 Constructors Created Frac x(3,4) as 3/4 Created Frac y(1,2) as 1/2 String constructed: s: 6/7 Copy constructed z as x: 3/4 Assigned 'assignedFrac' as z: 3/4 Part-1.2 Getters and Setters getSetTest is initialized to: 0/1 setting getSetTest.num to 3 Its num is now: 3 setting getSetTest.den to 4 Its den is now: 4 Part-1.3 operators basic math: +, -, *. / x + y is: 5/4 X-y is: 1/4 y is: 3/8 x/y is: 3/2 x pre and postfix ++ and -- (4 different types) 3/2 is c in c C++ C-- --C ++C 3/23/21/23/23/2 comparators: , =, !, == X > y is: true x y is: true X > Enter a fraction to test iostream operators: 5/6 You have entered: 5/6 Part-2 Operators in one statement v. separated statements. 11/6 11/6 11/6 11/6 11/6 11/6 11/6 5/6 5/6 11/6 5/6 11/6 Provide your observation and explanation as part of the submission Exit code: 0 (normal program termination)
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