// driver.cpp // Dr. Janet T. Jenkins // This is a sample driver program // Before it is really helpful, you will need to // have the insertion and extraction operators working // DO NOT START CODING...

I just need help with the Poly.cpp file!


// driver.cpp // Dr. Janet T. Jenkins // This is a sample driver program // Before it is really helpful, you will need to // have the insertion and extraction operators working // DO NOT START CODING ANYTHING UNTIL // THE CONSTRUCTOR METHOD, INPUT AND OUTPUT OPERATORS // ARE WORKING CORRECTLY // Feel free to change this main program as you wish. // You may find it easier to use to read polynomials // from a file rather than from standard input #include "Poly.h" #include #include using namespace std; void testConstructor(ostream&); void testInput(istream&, ostream&); void testReset(istream&, ostream&); void testEvaluate(istream&, ostream&); void testAdd(istream&, ostream&); void testMult(istream&, ostream&); void testPlusEqual(istream&, ostream&); void testDerivative(istream&, ostream&); int getChoice(); int main(){ ifstream input("input.txt"); ifstream reset("reset.txt"); ifstream eval("eval.txt"); ifstream add("add.txt"); ifstream mult("mult.txt"); ifstream plusE("pluse.txt"); ifstream deriv("deriv.txt"); int choice = getChoice(); while(choice){ system("cls"); switch (choice){ case 1: testConstructor(cout);break; case 2: testInput(input,cout); break; case 3: cout < "tested="" in="" other="" methods"="" ;="" break;="" case="" 4:="" testreset(reset,cout);="" break;="" case="" 5:="" testevaluate(eval,cout);="" break;="" case="" 6:="" testadd(add,cout);="" break;="" case="" 7:="" testmult(mult,cout);="" break;="" case="" 8:="" testplusequal(pluse,cout);="" break;="" case="" 9:="" testderivative(deriv,cout);="" break;="" default:="" cout="">< "invalid="" selection"="">< endl;="" }="" cout="">< "press="" enter="" to="" continue"="">< endl;="" cin.get();cin.get();="" system("cls");="" choice="getChoice();" }="" return="" 0;="" }="" void="" testconstructor(ostream&os){="">< "testing="" constructor"="">< endl;="">< "expect:\t"=""><><>" < endl;="" poly="" p;="" os="">< "actual:\t"="">< p="">< endl;="" }="" void="" testinput(istream&="" is,="" ostream&os){="" os="">< "testing="" extraction="" operator"="">< endl;="" os="">< "enter="" polynomial="" in="" specified="" format"="">< endl;="" poly="" p;="" is="">> p; os< endl;="">< "actual:\t"="">< p="">< endl;="" }="" void="" testreset(istream&="" is,="" ostream&os){="">< "testing="" reset,="" must="" have="" input"="">< endl;="">< "enter="" a="" polynomial"="">< endl;="" poly="" p;="" is="">> p; os< "before="" reset:\t"="">< p="">< endl;="" p.reset();="">< "after="" reset:\t"="">< p="">< endl;="" }="" void="" testevaluate(istream&="" is,="" ostream&os){="">< "testing="" evaluate"="">< endl;="" os="">< "enter="" a="" polynomial"="">< endl;="" poly="" p;="" is="">> p; os< "enter="" the="" value="" for="" x"="">< endl;="" int="" x;="" is="">> x; os< "polynomial:\t"="">< p="">< endl;="">< "evaluated="" at\t"="">< x="">< endl;="">< "is="" \t="" "="">< p.eval(x)="">< endl;="" }="" void="" testadd(istream&="" is,="" ostream&os){="">< "testing="" add"="">< endl;="" poly="" p1,="" p2;="">< "enter="" left="" operand"="">< endl;="" is="">> p1; os< "enter="" right="" operand="" "="">< endl;="" is="">> p2; os< p1="">< "="" +="" "="">< p2="">< "=" << endl; os<< p1 + p2 << endl; } void testMult(istream& is, ostream&os){ os<< " testing="" multiply"="">< endl;="" poly="" p1,="" p2;="">< "enter="" left="" operand"="">< endl;="" is="">> p1; os< "enter="" right="" operand="" "="">< endl;="" is="">> p2; os< p1="">< "="" *="" "="">< p2="">< "=" << endl; os<< p1 * p2 << endl; } void testPlusEqual(istream& is, ostream&os){ os<< " testing="" plus="" equal"="">< endl;="" poly="" p1,="" p2;="">< "enter="" left="" operand"="">< endl;="" is="">> p1; os< "enter="" right="" operand="" "="">< endl;="" is="">> p2; os< p1="">< "="" +=" << p2 << " ="="">< endl;="" p1+="p2;">< p1="">< endl;="" }="" void="" testderivative(istream&="" is,="" ostream&os){="">< "testing="" derivative"="">< endl;="" poly="" p1;="">< "enter="" polynomial"="">< endl;="" is="">> p1; os< "the="" derivative="" of="" "="">< p1="">< "is"="">< endl;="" p1.derivative();="">< p1="">< endl;="" }="" int="" getchoice(){="" cout="">< "select="" one"="">< endl;="" cout="">< "1.="" test="" constructor"="">< endl;="" cout="">< "2.="" test="" input="" "="">< endl;="" cout="">< "3.="" test="" output"="">< endl;="" cout="">< "4.="" test="" reset="" "="">< endl;="" cout="">< "5.="" test="" evaluate="" "="">< endl;="" cout="">< "6.="" testadd"="">< endl;="" cout="">< "7.="" testmult"="">< endl;="" cout="">< "8.="" testplusequal"="">< endl;="" cout="">< "9.="" testderivative"="">< endl;="" cout="">< "0.="" quit"="">< endl;="" int="" c;="" cin="">> c; return c; } #ifndef POLY_H #define POLY_H #include #include using namespace std; const unsigned int MAX = 21; class Poly{ int terms[MAX]; public: Poly(); double Eval(double x); void Reset(); void operator+=(const Poly& p); void Derivative(); friend istream& operator>>(istream& is, Poly& p); friend ostream& operator<(ostream& os, const poly& p); friend poly operator+(const poly& p1, const poly& p2); friend poly operator*(const poly& p1, const poly& p2); }; #endif os,="" const="" poly&="" p);="" friend="" poly="" operator+(const="" poly&="" p1,="" const="" poly&="" p2);="" friend="" poly="" operator*(const="" poly&="" p1,="" const="" poly&="" p2);="" };="">
Oct 25, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here