So I am developing a polynomial square where a user input: 1x ^ 0 + 2x ^ 1 + 3x ^ 2 .. and 1,2,3 (coefficient) are stored in an integer array
My overloaded + and - functions work, however, * does not work. It does not matter, it always shows- 842150450
when should be (5x ^ 0 + x ^ 1) * (-3x ^ 0 + x ^ 1) = -15x ^ 0 + 2x ^ 1 + 1x ^ 2 or (x + 5) (x-3) = x ^ 2 + 2x - 15
I am using overloaded * functions such as: polynomial times = one two;
I am guessing the problem strtol (p; and endptr, 10) because it uses a long int, nevertheless, adding and subtracting tasks completely
My constructor
polynomial :: polynomial (four * s) {char * string; String = new four [Stellen (s) + 1]; Int length = Stellen (string); Streakpie (string, s); Four * copy; Copy = new four [length]; Strcpy (copy, string); Char * p = strtok (string, "+ -"); Counter = 0; While (P) {P = Strokec (NULL, "+ -"); Counter ++; } Coefficient = New Int [Counter]; P = stroke (copy, "+"); Int a = 0; While (p) {long interval coeff; Char * endptr; Coeff = strtol (p, end, 10); // first stops in non-number if (* p == 'x') coeff = 1; Coefficient [a] = coffe; P = stroke (faucet, "+"); One ++; }}
and overloaded * function
Polynomial Multilateral :: Operator * (Cost Polymic and Write) {Multilayer Temporary; // coefficient the array array int count = (counter + right.counter) - 1; Temp.counter = count; Temp.coefficient = new int [count]; For (int i = 0; i
and reads my whole code:
To zero in the operator, temp.coefficient [i + j]
is not visible to start
. .
temp.coefficient = new int [count]; Std :: memset (temp.coefficient, 0, count * sizeof (int));