You need to change line 9 to:
double cf[3], a, b, c;
to avoid memory management problems. Come to think of it, why do you have a cf array AND values a, b, and c? You should have one or the other.
You have declared the destructor wrong. Line 17 declares a ~ operator. Line 17 should be :
~Quatratic();
, but really, if you make the change above, then there's no need to define a destructor at all because there will be no need to free up memory.
Look at lines 107 and 108:
If you needed to add integers, you wouldn't write:
1 2 3
|
int i1=1, i2=2;
i1+i2;
cout << i1;
|
because i1+i2 doesn't change i1, it just evaluates to a
new integer. In particular, you don't want
cout << i1+i2
to modify i1 as a side effect, and you really don't want cout << i1+i2+i3 to make changes to the variables along the way.
Your operators should work the same way.
Q1+Q2
shouldn't change either Q1 or Q2. So your main program should be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int main ()
{
Quadratic Q1;
Quadratic Q2(11, 22, 33);
Quadratic Q3;
Q1.print();
Q2.print();
Q3 = !Q2;
Q3.print();
Q3 = Q2 + Q1;
Q3.print();
Q3 = Q1 - Q2;
Q3.print();
Q2 += Q1;
Q2.print();
return 0;
}
|
Note that this applies to everything except the += operator. That one really DOES change the argument.