Question
C++ Program having Polynomial.h, Polynomial.cpp and Main.cpp Implement an ADT representing a Polynomial (e.g.: ). You will do this by creating a class called Polynomial.
C++ Program having Polynomial.h, Polynomial.cpp and Main.cpp
Implement an ADT representing a Polynomial (e.g.: ). You will do this by creating a class called Polynomial.
Implementation A polynomial can be represented by a collection of coefficient/exponent pairs. For example, the above polynomial can be represented by the following collection of number pairs: (4,5) (7,3) (-1,2) (9,0)
One way to do this would be to use an array of structures. You may assume a limit of 10 terms in the equation. Also, all exponents will be positive and integers. All coefficients will be integers.
Methods You will need to implement the following methods: void addTerm(int coefficient, int exponent) add the specified term to the polynomial. Used repeatedly to construct the polynomial. int degree() - return the degree of the polynomial that is, the highest exponent. int coefficient(int power) return the coefficient of the term with the given power, or 0 if there is no such term. int numberOfTerms() - return the number of terms in the polynomial. int value(int x) return the value of the polynomial for the given value of x.
For the above polynomial: degree() 5 coefficient(2) -1 coefficient (5) 4 coefficient(0) 9 coefficient(7) 0 numberOfTerms() 4 value(2) 189 ()
Main Program Your main program should read pairs of numbers from a file and create a Polynomial by repeatedly calling the addTerm() method You will run your program 2 times, using 2 different input files:
File 1 (representing ) 4 5 7 3 -1 2 9 0
File 2 (representing ) -11 0 1 4 10 7 5 2 -3 3 (notice the terms are in no particular order)
For each execution, output the following:
Degree: d # terms: t coeff(0): c coeff(1): c : : coeff(7): c value(1): v
4.75 + 7x 12 + 9Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started