```
#include "Poly.h"
#include <iostream>
using namespace std;
istream& operator>> (istream& stream, Polynomial& poly)
{
// This needs serious help
return stream;
}
ostream& operator<< (ostream& stream, Polynomial& poly)
{
for (int i = 0; i < poly.number_of_terms(); i++)
// This next line also needs help.
if (poly.expo=0)
stream << poly[i].co << "\t";
if (poly.expo=1)
stream << poly[i].co <<poly[i].var<< "\t";
else
stream << poly[i].co <<poly[i].var+"^"<<poly[i].expo<< "\t";
return stream;
}
Polynomial::Polynomial()
{
reset();
}
void Polynomial::addTerm(term t)
{
it= poly.begin();
if(poly.empty())
poly.insert(poly.begin(), t);
else if( t.expo < poly.last().expo)
{
poly.push_back(t);
}
else if( t.expo > poly.front().expo)
{
poly.insert(poly.begin(), t);
}
else if
{
for( int x = 0; x<poly.size(); x++)
{
if(t.expo==(poly[x].expo))
{
if (t.var==(poly[x].var))
{
poly[x].co+=t.co;
}
else
{
int i = 0
do{
it++;
i++;
if(i==x)
poly.insert(it, t);
}while( i<x)
}
}
}
}
}
void Polynomial::reset()
{
poly.clear();
}
int Polynomial::number_of_terms()
{
return poly.size();
}
Polynomial operator+( const Polynomial& p1, const Polynomial& p2 )
{
Polynomial result;
for{int x=0, x<p1.size(); x++)
{
result.addTerm(p1.poly[x]);
}
for{int y=0, y<p2.size(); y++)
{
result.addTerm(p2.poly[x]);
}
// need help
return result;
}
```

```
#ifndef poly
#define poly
#include <iostream>
#include <vector>
using namespace std;
struct term
{
int co;
int expo;
char var;
};
class Polynomial
{
friend istream& operator>> (istream& stream, Polynomial& poly);
friend ostream& operator<< (ostream& stream, Polynomial& poly);
public:
// The list of terms in the polynomial
// (not necessarily ordered)
vector<term> poly;
vector<term>::iterator it;
// default constructor
Polynomial();
// empties the polynomial of all terms
void reset();
// sort the terms from the highest to lowest exponent
void sort();
// add two polynomials
friend Polynomial operator+( Polynomial& p1, Polynomial& p2);
// returns the number of terms in the polynomial
int number_of_terms();
};
#endif
```

```
#include <iostream>
#include <vector>
#include "Poly.h"
using namespace std;
void menu (void)
{ cout<<endl;
cout<<"1. Enter a polynomial"<<endl;
cout<<"2. Reset the polynomial"<<endl;
cout<<"3. Sum"<<endl;
cout<<"4. Number of Terms" << endl;
cout<<"5. Print Polynomial"<<endl;
cout<<"6. Quit"<<endl;
cout<<"Enter selection>";
}
void add(Polynomial& P)
{
Polynomial p2, result;
p2.reset();
result.reset();
//enter values for second polynomial
cout<<"Enter terms for second polynomial, enter x to stop"<<endl;
cin>>p2;
result = p + p2;
cout<<"Values for added polynomial are:"<<endl;
cout<<"Number of Terms: "<<result.size()<<endl;
cout<<"Sum: "<<result.addTerm( )<<endl;
}
int main (void)
{
int choice;
int co, expo;
char var;
//declare a Polynomial
Polynomial p;
p.reset();
do {
//print menu
menu();
cin>>choice;
switch (choice) {
case 1 : cout<<endl<<"Enter The coefficient> ";
cin>>co;
p.poly.addTerm(co);
cout<<endl;
cout<<endl<<"Enter Variable> ";
cin>>var;
p.poly.addTerm(var);
cout<<endl;
cout<<endl<<"Enter Exponent> ";
cin>>expo;
p.poly.addTerm(expo);
cout<<endl;
break;
case 2 : p.reset();
cout<<endl<<"Polynomial reset"<<endl;
break;
case 3: cout<<endl<<"Sum is "<<p.result()<<endl;
break;
case 4: cout<<endl<<"Number of Terms is "<<p.number_of_terms()<<endl;
break;
case 5: cout<< "The polynomial is: " << poly << endl;
break;
case 6: cout<<endl<<"Thanks and goodbye."<<endl;
break;
default : cout<<endl<<"Invalid command. Try again."<<endl;
}
} while (choice != 5);
}
```