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 20
and define the following structures
typedef struct {
int coefficient;
int power;
} Monom;
typedef struct {
Monom* monoms[SIZE];
int numOfElements;
} Polynomial;
The structure Monom represents one term in a polynomial, for example: 5x^2. 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 6 x^30+2x is a valid polynomial because its length is less than/equal to 20, even though its degree is greater than 20. Apply the following functions:
1. Monom* createMonom(int coefficient, int power)
This function will create a new monomial with the given coefficient and power. If a coefficient equal to 0 is received, the function will return NULL.
2.void printMonom(Monom 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.
3.void addMonom(Polynom* 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 0 or the polynomial is already SIZESIZE in length, the function will return and do nothing..
4. void void printPolynom(Polynom polynom)printPolynom(Polynom polynom)
This function will print the entire polynomial in the appropriate format (it will be detailed later)
5. void void deletePolynom(Polynom polynom)deletePolynom(Polynom polynom)
This function will release all the memory allocated to the polynomial..
Monogram print format ::
For power 0 only the coefficient will be printed
For power 1 only the coefficient and x will be printed, for example: 5x
For coefficient 1 or 11-- the coefficient will not be printed, for example :: , x^4, x^4x^2x^2--
For a power greater than 1 or less than 1- the coefficient, x, the sign ^ and the power will be printed. For example: 5x^2
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: 22--7x+5+2x^7x+5+2x^--x^2x^255
Printing in a different format than required will lead to points being deducted.
Write a file named PolynomPolynom.h.h 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 =0; polynomial.numOfElements =0; // Initialize the number of elements// Initialize the number of elements
addMonom(&polynom, 3,2); addMonom(&polynom, 3,2); //3x^2//3x^2
addMonom(&polynom, 4,3); addMonom(&polynom, 4,3); //4x^3//4x^3
addMonom(&polynom, 5,2); addMonom(&polynom, 5,2); // Add 5x^2, update existing monom to 8x^2// Add 5x^2, update existing monom to 8x^2
printPolynom(polynom); printPolynom(polynom); // Print the polynomial// Print the polynomial
deletePolynom(polynom); deletePolynom(polynom); // Clean up// Clean up
return return 0;0;
}
}
Program output ::
4x^3+8x^2
4x^3+8x^2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!