Page 1 of 1

A Polynomial function is a function of the form: P(x) = 0,*" + an-14 *an-zxn-1 + ax + ao where an, On-1,...,01, ao are r

Posted: Mon May 09, 2022 6:23 am
by answerhappygod
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 1
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 1 (37.02 KiB) Viewed 34 times
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 2
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 2 (40.18 KiB) Viewed 34 times
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 3
A Polynomial Function Is A Function Of The Form P X 0 An 14 An Zxn 1 Ax Ao Where An On 1 01 Ao Are R 3 (27.58 KiB) Viewed 34 times
A Polynomial function is a function of the form: P(x) = 0,*" + an-14 *an-zxn-1 + ax + ao where an, On-1,...,01, ao are real numbers and n is non-negative. Write a C++ program that reads two polynomials and output their sum, i.e. if P1(x) = 3x4 + 5x3 + x P2(x) = 2x5 - 5x4 - x + 2 their sum is: P1(x) + P2(x) = 2x5 - 2x4 + 5x3 + 2 NOTE: Polynomials should be entered as [ 3x4+5x3+x] where 3,5 and 1 are the coefficients of x4, x3 and xl, respectively. Your program should give an error message if a non valid polynomial is entered.
To store your polynomial you can use a one-dimensional array: the coefficient in the array; the power is the index (position) of array. Also note that all powers are bigger than 0. Thus 5x-2 is 5x minus 2; power cannot be negative.
#include <iostream> using namespace std; int main() { double polynomial[10] - 0); char c; double coefficient = 0; int power = 0; bool next Power = false; while (c = cin.get(), c != '\n') { if (c == '+' || C == '') nextPower = false; else if (c == 'X' Il c == 'X') nextPower - true; else if (c >= '@' && C <= '9') { cin.unget(); if (nextPower) { cin >> power; polynomial[power] = coefficient; nextPower = false; } else cin >> coefficient; } } for (int i = 9; i >= 0; i--) if (polynomial != 0) { cout << "coefficient = " << polynomial << " power = " << i << endl; } return; }