Question: Below is my code, I keep getting the errors: fractionType:t is not valid template type argument for parameter T and t: undeclared identifier Please help

Below is my code, I keep getting the errors:

"fractionType":"t" is not valid template type argument for parameter "T"

and

"t": undeclared identifier

Please help me out to fix these errors

#include

using namespace std;

// class definition template class fractionType { // template class with generic data types T num, den;

public: // default constructor fractionType() {}

// parameterized constructor fractionType(T a, T b) { num = a; den = b; }

// overload the stream insertion operators friend ostream& operator<<(ostream& out, fractionType f) { out << f.num << "/" << f.den; return out; }

friend istream& operator>>(istream& in, fractionType & f) { cout << "Enter a Numerator: "; in >> f.num; cout << "Enter a Denominator: "; in >> f.den; return in; }

// overlaod the arithmetic operators friend fractionType operator+(fractionType a, fractionType b) { fractionType sum((a.num * b.den + a.den * b.num), (a.den * b.den)); return sum; }

friend fractionType operator-(fractionType a, fractionType b) { fractionType diff((a.num * b.den - a.den * b.num), (a.den * b.den)); return diff; }

friend fractionType operator*(fractionType a, fractionType b) { fractionType res((a.num * b.num), (a.den * b.den)); return res; }

friend fractionType operator/(fractionType a, fractionType b) { fractionType res((a.num / b.den), (a.den * b.num)); return res; }

// overload the relational operators friend bool operator<(fractionType a, fractionType b) { return a.num * b.den < a.den* b.num; }

friend bool operator>(fractionType a, fractionType b) { return a.num * b.den > a.den * b.num; }

friend bool operator<=(fractionType a, fractionType b) { return a.num * b.den <= a.den * b.num; }

friend bool operator>=(fractionType a, fractionType b) { return a.num * b.den >= a.den * b.num; }

friend bool operator==(fractionType a, fractionType b) { return a.num * b.den == a.den * b.num; }

};

// small main function to test some operators and functions int main() { fractionType x; fractionType y; cin >> x; cin >> y; fractionType z = x + y; cout << z; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!