Polynomial Function operator

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# include <iostream>
using namespace std; 

class Polynomial
{
      private :
                int *array ;
                int x ;
      public  :
                Polynomial(int y  , int arr[])
                {
                  x = y ;
                  array = new int [x] ;                  
                }
                void  setPolynomial() ;
                int getPolynomial() ;

     	        void operator =  (const Polynomial& ) ;
     	        Polynomial operator +  (const Polynomial& )const ;
     	        Polynomial operator -  (const Polynomial& ) ;
     	        Polynomial operator *  (const Polynomial& ) ;
     	        Polynomial operator += (const Polynomial& ) ;
     	        Polynomial operator -= (const Polynomial& ) ;
     	        Polynomial operator *= (const Polynomial& ) ;
};

void Polynomial::setPolynomial()
{
     array = new int [x] ;
     int arr[x] ;
     for ( int i = 0 ; i < x+1 ; i++ )
     {
         cout << "Enter Cofficinet x^( " << i <<") : " ;
         cin  >> arr[i] ;
         array[i] = arr[i] ;
     }
}

int Polynomial::getPolynomial()
{
//    array = new int [x] ;
    for (int i = 0 ; i < x+1 ; i++)
    {
      cout <<"Cofficinet x^( " << i <<") : " << array[i] << endl;
    }
}

void Polynomial::operator = (const Polynomial& p ) 
{
   int* arr  ;
   arr = new int [x] ;
   
   for ( int i = 0 ; i < x+1 ; i++ )
   {
       arr[i] = p.array[i] ;
   }
   
}

Polynomial Polynomial::operator +  (const Polynomial& p ) const 
{
   int* arr  ;
   arr = new int [x] ;
//   p.array = new int [x] ;
   
   for ( int i = 0 ; i < x+1 ; i++ )
   {
       arr[i] = array[i] + p.array[i] ;
   }
       return Polynomial ( x , arr) ;
}



int main ()
{
    int  power ;
    int* poly1 ;
    cout << "The Polynomial Function to the Power : " ;
    cin >> power ;
    
    poly1 = new int [power] ;    
    
    Polynomial p1(power ,poly1);
    p1.setPolynomial() ;

    int* poly2 ;
    poly2 = new int [power] ;    
    Polynomial p2(power ,poly2);
    p2.setPolynomial();

    p1.getPolynomial();
    p2.getPolynomial();
    
    int* poly3 ;
    poly3 = new int [power] ;
    
    Polynomial p3(power ,poly3) ;
    
    p3 = p1+p2 ;
    p3.getPolynomial();
    
    system("pause");
    return 0 ;
}
can anyone help me in run this program ???
double post: http://cplusplus.com/forum/beginner/17541/

please read forum rules before posting. and there's nothing wrong with your old post, if you have found a solution to your problem say so in the other topic then post a new topic with the new question regarding your code.
Last edited on
i have add some functions in this program they are no the same plz check them thanks :)
Topic archived. No new replies allowed.