Question: C language please In this exercise we will realize a structure representing a polynomial and the operations defined on it . Define the constant in
C language please
In this exercise we will realize a structure representing a polynomial and the operations defined on it
Define the constant in the file
#define
SIZE
and define the following structures
typedef struct
int coefficient;
int power;
Monom;
typedef struct
Monom monomsSIZE;
int numOfElements;
Polynomial;
The structure Monom represents one term in a polynomial, for example: x Each monomial will have the fields:
The coefficient of x whole number and the power of x whole number
The structure Polynom will store the terms of the polynomial using an array of size SIZE of pointers to the monomial as well as its size the numbers of the terms of the polynomial.
The length of the polynomial will be at most SIZE, but this is not necessarily the degree of the polynomial. That is the polynomial xx is a valid polynomial because its length is less thanequal to even though its degree is greater than Apply the following functions:
Monom createMonomint coefficient, int power
This function will create a new monomial with the given coefficient and power. If a coefficient equal to is received, the function will return NULL.
void printMonomMonom monom
This function will print a monomial in the appropriate format will be detailed later If an empty pointer is received, the function will return and do nothing.
void addMonomPolynom polynom, int coefficient, int power
This function will add a monomial to a polynomial, in a free space as you wish, while handling the case where a monomial with the same power already exists
If an empty pointer is received, a coefficient equals or the polynomial is already SIZESIZE in length, the function will return and do nothing..
void void printPolynomPolynom polynomprintPolynomPolynom polynom
This function will print the entire polynomial in the appropriate format it will be detailed later
void void deletePolynomPolynom polynomdeletePolynomPolynom polynom
This function will release all the memory allocated to the polynomial..
Monogram print format ::
For power only the coefficient will be printed
For power only the coefficient and x will be printed, for example: x
For coefficient or the coefficient will not be printed, for example :: x xxx
For a power greater than or less than the coefficient, x the sign and the power will be printed. For example: x
Polynomial print format ::
The function printPolynomprintPolynom will print to the screen the terms of the polynomial sorted by power, from the largest to the smallest, with the plus sign before a positive coefficient and without spaces. For example: xxxxxx
Printing in a different format than required will lead to points being deducted.
Write a file named PolynomPolynom.hh in which you define the structures and methods.
Write a file called Polynom.cPolynom.c and implement the methods in it
Write a file called main.c main.c in which you can create a polynomial and check the correctness of the implementation.
Sample main plan:
int
int main main
Polynom Polynom polynom; polynom;
polynomial.numOfElements ; polynomial.numOfElements ; Initialize the number of elements Initialize the number of elements
addMonom&polynom, ; addMonom&polynom, ; xx
addMonom&polynom, ; addMonom&polynom, ; xx
addMonom&polynom, ; addMonom&polynom, ; Add x update existing monom to x Add x update existing monom to x
printPolynompolynom; printPolynompolynom; Print the polynomial Print the polynomial
deletePolynompolynom; deletePolynompolynom; Clean up Clean up
return return ;;
Program output ::
xx
xx
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
