Question: Use a template so the class works with any kind of number (i.e. int, float, double) fractionType num1(5, 6); fractionType num1(5.1, 6.2); Tip: get your
Use a template so the class works with any kind of number (i.e. int, float, double) fractionType num1(5, 6); fractionType num1(5.1, 6.2);
Tip: get your class working with integer values first for numerator and denominator and convert to a template after it is working with ints. When converting to a template you may need to move all of your implementations into the .h header file. This means that instead of creating function definitions in the header and putting the implementations in the .cpp file, you wont even have a .cpp. File. Just put the function implementation inside the header file - no need for a function definition if you do this. i.e. Typical definition in the .h file bool operator
IMPORTANT: The above are just samples of a portion of the fraction class - you are required to add templating to the entire fraction class. Below is a template of the class given to you with all of the functions empty - you need to make sure your fraction class implements all of the folloeing: #ifndef H_fraction #define H_fraction #include using namespace std; template class fractionType { // overload stream insertion and extraction operators friend ostream& operator> (istream& is, fractionType& fraction) { } public: //Constructor fractionType(T num = 0, T den = 1) { } //overload + fractionType operator+(fractionType rightFr) { } //overload * fractionType operator*(fractionType rightFr) { } //overload - fractionType operator-(fractionType rightFr) { } //overload / fractionType operator/(fractionType rightFr) { } //overload relational operators bool operator==(fractionType rightFr) const { } bool operator!=(fractionType rightFr) const { } bool operator=(fractionType rightFr) const { } bool operator>(fractionType rightFr) const { } private: T numerator; //variable to store the numerator T denominator; //variable to store the denominator }; #endif
Use a template so the class works with any kind of number (i.e. int, float, double) fractionType num1(5, 6); fractionType num1(5.1, 6.2); Tip: get your class working with integer values first for numerator and denominator and convert to a template after it is working with ints. When converting to a template you may need to move all of your implementation into the .h header file.


0. Rational fractions are of the form a/b, in which a and b are integers and b=0. In this exercise, by "fractions" we mean rational fractions. Suppose a/b and c/d are fractions. Arithmetic operations on fractions are defined by the following rules: a/b+c/d=(ad+bc)/bda/bc/d=(adbc)/bda/bc/d=ac/bd(a/b)/(c/d)=ad/bc;inwhichc/d=0. Fractions are compared as follows: a/b op c/d if adopbc, in which op is any of the relational operations. For example, a/b
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
