Need Help in C++

Declare a class name “Polynomial” which contains an array of size (n) (dynamic allocation of this array is not required, you can use a global variable to represent the degree of the polynomial, to store the coefficients of the polynomial into the indices corresponding to their powers. For example if we want to make a polynomial 2x4 + 3x3 – 12x2 + x – 19 (degree-4) then the polynomial class will have an array of the following form. –19, 1, -12, 3, 2
Polynomial (int degree)
Description: Constructor, which initializes the array to zero.
void outputPolynomial()
Description: Prints the polynomial in the following format, 2x^4 + 3x^3 – 12x^2 + x -19

I have written the following Code. But I am confused how to assign value to the polynomial in the main function. And how to initialize the global variable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream.h>
#include <stdlib.h>

int Degree;

class Polynomial
{
   protected:
             int size[Degree];
   public:
             Polynomial(){}
             Polynomial (int degree);
             void outputPolynomial();
};

Polynomial::Polynomial (int degree)
{
         for(int a=0;a<=degree;a++)
         {        size[a]=0;
}

void Polynomial::outputPolynomial()
{
         //2x^4+3x^3-12x^2+x-19
         int b=5;
         cout<<endl;
         for(int a=0;size[a]=='\0';a++)
         {
          cout<<size[a]<<"x"<<"^"<<b<<" ";
          b--;
          }
}

int main()
{
      Polynomial P(4);
      //P(–19, 1, -12, 3, 2);   How it work
      P.outputPolynomial();

      system("PAUSE");
      return 0;
}


The complete description is in http://vulms.vu.edu.pk/courses/CS304/Final%20Projects.doc
Topic archived. No new replies allowed.