C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2002, 02:31 PM   #1
Unregistered
Guest
 
Posts: n/a
Polynomial

Hi there,

Could someone help with multiplying two polynomials. I have implemented a Polynomial class to overload the +, -, *operators...

Polynomial class{

public:
Polynomial operator+(const Polynomial &)
Polynomial operator*(const Polynomial &)
// overload more operators ........

private:
int* ptr; // pointer of the first array element
int size; // size of array
}

Description: a polynomial is an array of terms (each term will contain a coefficent & an exponent). In the array, the subscript is the exponent, whereas the contents is the coefficient.

This is how the addition works. All it does is to add like terms.
// ================== addition ====================
// pass in a 2nd polynomial
// Polynomial Polynomial:: operator+(const Polynomial &rt) {
Polynomial tempPly(*this)
for(int i=0; i<rt.size; i++)
tempPly.ptr[i] = ptr[i] + rt.ptr[i];
return tempPly;
}

Thanks in advance
  Reply With Quote
Old 04-17-2002, 05:00 PM   #2
Registered User
 
Join Date: Oct 2001
Posts: 2,936
Try this:
Code:
Polynomial &Polynomial:: operator+(const Polynomial &rt) {
   Polynomial *tempPly;
   tempPly = new Polynomial(rt.size);
   for(int i=0; i<rt.size; i++)
      tempPly->ptr[i] = ptr[i] + rt.ptr[i]; 
   return *tempPly; 
}
swoopy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Entering in an nth degree polynomial Noah C Programming 1 03-02-2006 09:02 PM
Polynomial CompiConQuiso C++ Programming 4 05-16-2005 12:13 AM
Polynomial Problem softcoder76 C++ Programming 5 03-01-2002 02:07 PM
linked lists of a polynomial Unregistered C++ Programming 4 02-11-2002 07:51 PM
linked lists of a polynomial Unregistered C++ Programming 1 02-11-2002 06:44 PM


All times are GMT -6. The time now is 01:35 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22