Question: C++ code pelase header file down below #ifndef ECRational_h #define ECRational_h // ***************************************************************** // Generic rational of two quantities (e.g. integers, floating point, complex number,
C++ code pelase
header file down below
#ifndef ECRational_h
#define ECRational_h
// *****************************************************************
// Generic rational of two quantities (e.g. integers, floating point, complex number, or polynomila)
// Assume the quantity class T supports (i) default constructor and copy constructor, (ii) assignment operator, and (iii) arithmatic operators: +, -, * and /
// Note: you don't need to simplify the rational. That is, it is OK to have common factors in numerator and denominoator. For example, 4/4 = 1/1
template
class ECRational
{
public:
// YW: change the following code if needed...
ECRational() {}
ECRational(const T &numeratorIn, const T &denominatorIn);
// copy constructor
...
// assignment operator
...
// operators: define +, -, *, / operators yourself
// access numerator and denominator
const T &GetNumerator() const;
const T &GetDenominator() const;
private:
// your code
};
#endif /* ECRational_h */
test code below
#include
using namespace std;
#include "ECRational.h"
#include "ECPolynomial.h"
void Test()
{
// test rational of ints
ECRational
ECRational
cout
ECRational
cout
ECRational
cout
ECRational
cout
}
void Test2()
{
// test rational of polynomials
ECPolynomial p1(2), p2(2), p3(1);
// p1=1-x+x^2
p1.SetCoeffAt(0, 1);
p1.SetCoeffAt(1, -1);
p1.SetCoeffAt(2, 1);
// p2=1-x^2
p2.SetCoeffAt(0, 1);
p2.SetCoeffAt(2, -1);
// p3=1+2x
p3.SetCoeffAt(0, 1);
p3.SetCoeffAt(1, 2);
// Create rational: p1/p2 and p2/p3
ECRational
ECRational
// r1+r2= ( 2+ x -3x^2+ 2x^3+ x^4)/ ( 1+ 2x -x^2 -2x^3)
cout
r3.GetNumerator().Dump();
cout
r3.GetDenominator().Dump();
cout
ECRational
// r1*r2= ( 1- x + x^3 - x^4)/ ( 1+ 2x -x^2 -2x^3)
cout
r4.GetNumerator().Dump();
cout
r4.GetDenominator().Dump();
cout
}
int main()
{
Test();
Test2();
}
In this assignment, you need to implement a class called ECRational, supporting generic rational of two quantities. The quantities can be C++ value types (e.g. integers, floating point) or user-defined value types (e.g. complex number, or polynomials). You may assume the data type supports the following: (i) default constructor and copy constructor, (ii) assignment operator, and (iii) arithmetic operators: +,, and / (division). Note: you don't need to simplify the rational. That is, it is OK to have common factors in numerator and denominator. For example, 4/4=1/1 are both acceptable. Therefore, ECRational should be a template class, with the following functions: 1. Customer constructor: taking two quantities as numerator and denominator. 2. Copy constructor, assignment operator, 3. +: add two rationals. 4. -: subtract two rationals. 5. *: multiply two rationals 6. /: divide two rationals. 7. Two methods to return the values of numerator/denominator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
