poly overloading plz help

The purpose of this Assignment is to be familiar with classes, Files and overloaded operators. The class you will be working on defines one-variable polynomials (i.e 2x3+5x+4), and you will deal with arithmetic operators, including addition + and subtraction -
So you need to implement a C++ class called poly for polynomials, with the following specifications:
1. The class constructor, which initializes the polynomial variables degree and coefficients.
2. The method eval () for evaluating the polynomial based on the input value
3. The method print() for printing out the polynomial, which should follow the format below:(for example 1+ 2x^1+3x^2-7x^3…)
4. Overload the + operator for polynomial addition (x3 + x2 + 1) + (x4 + 3 x2 −2) = (x4 + x3 + 5x2 −1)
5. Overload the - operator for polynomial subtraction
6. Overload the <<(Insertion) and >>(extraction) operator so you can easily write
Poly obj; cin>>obj; cout<<obj;

Your will use the following input/output files to test your program.
Sample Input file Format
4 The number of polynomials used as inputs
3 1.00 0.00 1.00 1.00  1+x2+x3 First poly
4 -2.00 0.00 3.00 0.00 1.00 -2+3x2+x4 second
3 1.00 0.00 1.00 1.00 third
4 -2.00 0.00 3.00 0.00 1.00 fourth

In each line, the first number is the degree of that polynomial and the rest are the coefficients. The coefficients are in ascending power, following the format described in the “print()” function; For example, 4 -2.00 0.00 3.00 0.00 1.00 corresponds to (
-2+3x2+x4).
i write it
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;


class poly {

public:int degree;
int *coefficient;
poly(int );
void fill ();
~poly();
void print();
};
void poly:: fill(){
fstream input("c:\\file.txt");
input>>coefficient[0];
for(int i=1;i<degree+1;i++){
input >> coefficient[i];}
}
poly ::poly(int a){
degree=a;
coefficient=new int[degree+1];}

poly::~poly(){
delete []coefficient;}
void poly:: print (){
cout<< coefficient[0];
for(int i=1;i<degree+1;i++)
cout<<"+"<<coefficient[i]<<"x^"<<i;
}
int main(){

poly x(2);
x.fill();
x.print();
getch();
return 0;
}
Topic archived. No new replies allowed.