im making a polynomial class, operator / is working while the operator /= overloaded function is not working.Someone pleasssssssssssssseeeee help out. ive to submit it next week. -
int degree;
-
double ab[100];
-
char dummy;
-
-
/////////////////////////////Division////////
-
-
Poly Poly::operator/(Poly& a)
-
{
-
Poly temp;
-
double result[20],temp1[20],temp2[20],temp3[20];
-
int count=0,cnt,i=0,j=0,k=0;
-
-
for(i=0 ; i<=20 ; i++)
-
{
-
result[i]=0;temp1[i]=0;temp2[i]=0;temp3[i]=0;
-
-
}
-
-
if(degree>=a.degree)
-
{
-
for(i=degree; i>=0 ; i--)
-
temp1[i]=ab[i];
-
for(i=a.degree-1 ; i>=0 ;i--)
-
temp2[i]=a.ab[i]*-1;
-
-
-
for(i=degree ; i>=a.degree ; i--)
-
{
-
cnt=0;
-
-
result[count]=temp1[i];
-
-
for(j=a.degree-1 ; j>=0 ; j--)
-
{
-
temp3[j]=temp2[j]*temp1[i];
-
}
-
-
for(k=i-1 ; k>=0 ; k--)
-
{
-
if(a.degree-1-cnt>=0)
-
{
-
temp1[k]+=temp3[a.degree-1-cnt];
-
cnt++;
-
}
-
-
}
-
-
count++;
-
-
}
-
count-=1;
-
-
for(i=count ; i>=0 ; i--)
-
temp.ab[count-i]=result[i];
-
temp.degree=count;
-
temp.dummy=dummy;
-
}
-
-
else
-
cout<<" invalid input "<<"\n";
-
-
return temp;
-
}
-
-
-
//////////not working
-
-
Poly& Poly::operator/=(Poly& a)
-
{
-
double result[20],temp1[20],temp2[20],temp3[20];
-
int count=0,cnt,i=0,j=0,k=0;
-
-
for(i=0 ; i<=20 ; i++)
-
{
-
result[i]=0;temp1[i]=0;temp2[i]=0;temp3[i]=0;
-
-
}
-
-
-
if(degree>=a.degree)
-
{
-
-
for(i=degree; i>=0 ; i--)
-
temp1[i]=ab[i];
-
for(i=a.degree-1 ; i>=0 ;i--)
-
temp2[i]=a.ab[i]*-1;
-
-
-
for(i=degree ; i>=a.degree ; i--)
-
{
-
cnt=0;
-
-
result[count]=temp1[i];
-
-
for(j=a.degree-1 ; j>=0 ; j--)
-
{
-
temp3[j]=temp2[j]*temp1[i];
-
}
-
-
for(k=i-1 ; k>=0 ; k--)
-
{
-
if(a.degree-1-cnt>=0)
-
{
-
temp1[k]+=temp3[a.degree-1-cnt];
-
cnt++;
-
}
-
-
}
-
-
count++;
-
-
} count--;
-
-
this->degree=count;
-
-
for(i=degree ; i>=0 ; i--)
-
this->ab[degree-i]=result[i];
-
-
cout<<"done";
-
-
-
}
-
-
else
-
cout<<" invalid input "<<"\n";
-
-
return *this;
-
}
4 5000
If your Poly::operator/() is working then why not just: -
Poly& Poly::operator/=(Poly& a)
-
{
-
*this = *this / a;
-
return *this;
-
}
-
?
If your Poly::operator/() is working then why not just: -
Poly& Poly::operator/=(Poly& a)
-
{
-
*this = *this / a;
-
return *this;
-
}
-
?
u r genius.......oooohhhh how stupid of me.....its working now....thanks a lot
a lot....im so happy......thanksss
but still why that function /= isn't working ??? i jst copy paste that / code and change the assignment of result to temporary object to this pointer...
Perhaps in your /= operator you are using this as if it was the original polynomial after you have modified it.
Perhaps in your /= operator you are using this as if it was the original polynomial after you have modified it.
but ive used this pointer when all the calculations are done....at the end before ending if ive changed the the original attributes it should work
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Just |
last post by:
While googling for a non-linear equation solver, I found
Math::Polynomial::Solve in CPAN. It seems a great little module, except
it's not Python... I'm especially looking for its poly_root()...
|
by: strotee76 |
last post by:
What do I need to do to setTerm() for it to work properly?
If you notice any other glaring issues, then please let me know.
With this header file:
=======================
#ifndef Polynomial_h...
|
by: Rubén Campos |
last post by:
I've trying to implement polynomials of arbitrary order as a C++ template,
as shown here:
template <unsigned long int N>
class Polynomial
{
public:
Polynomial ();
~Polynomial ();
|
by: Chen L. |
last post by:
Hi all,
If I have a 32-bit data M, and the CRC genrator polynomial G(x),which
power is 32, then I can get the CRC checkword R by the following
algorithm:
X^32*M(x) = Q(x)G(x) + R(x),
But how...
|
by: Tiza Naziri |
last post by:
Hi,
Anybody have an idea on how to start writing a C code for generating
the inverse of finite field GF(2^8) using extended Euclidean algorithm?
What I mean is how to represent a polynomial,...
|
by: daniel.wolff |
last post by:
I am looking for a quick C program that takes n+1 pairs of values
(integers) (a_i, f(a_i)), i=0,...,n, generates the coefficients
\alpha_i, i=0,...,n of the polynomial of degree n that fits these...
|
by: Josiah Manson |
last post by:
In the following program I am trying to learn how to use functional
programming aspects of python, but the following program will crash,
claiming that the recursion depth is too great. I am...
|
by: madman228 |
last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial
in which i need a derivative method I have everything, just dont know how to start the derivative method. Any...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |