Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A common way to represent a polynomial expression (e.g. 3x5 - 2.2x3 +4x 1.713) is with linked structures that have three members a) b) c)
A common way to represent a polynomial expression (e.g. 3x5 - 2.2x3 +4x 1.713) is with linked structures that have three members a) b) c) A member to represent the coefficient (3) A member to represent the exponent (5) A pointer to the next term in the expression Write a program that does the following: Write a function input poly(ptrl) that reads in two polynomials at a time with coefficient and exponent from a file cp7in.txt. The file will contain 2n polvnomials, where n is an integer that is 10 or less. Space for the polynomial will be allocated in run time and there is no limit to the size of the polynomial, e. the first two lines of the file is 3 5-2.2 341-1.713 0 3 100 -2.2 3 14 55 3.1 101 (Note the terms may be in any order) Then, two polynomials will be created 3x5- 2.2x34x 1.713 and 3.1x101 + 3x100 + 14x5- 2.2x3 Write a function add poly(ptr1, ptr2) that expects pointers ptrl and ptr2 to two lists that represent polynomials and returns a pointer to a third list that represents the sum of polynomials. You will find the sum of every pair of polynomials. 1) 2) 3) Write a function mult poly(ptrl, ptr2) that expects pointers ptrl and ptr2 to two lists that represent 4) Write a function print poly(ptrl) that prints the polynomial pointed to by ptrl to a file, cp7.out. The terms From the function main0. you may call the function print poly(ptrl) to print out the following to cp7.out: polynomials and returns a pointer to a third list that represents the product of polynomials. You will find the product of every pair of polynomials. must be printed in descending order of exponent. That is to say, e.g. 3x5 - 2.2x3+4x 1.713 is correct but e.g.-2.2x3+3x5 +4x - 1.713 is not. The sum of polynomials 3x5- 2.2x34x-1.713 3.1x101 + 3x100 + 14x5- 2.2x3 1S 3.1x101 + 3x100 + 14x55 +3x5-4.4x3 +4x-1.713 The product of polynomials:: 3x5- 2.2x34x-1.713 3.1x101 + 3x100 + 14x5- 2.2x3 1S 105 6.82x 104_6.6x10312.41026.6897 101-5 60 58 3x 5.139x100+42030.8r08+ 56x56 -23.9825.6r4.84r68.r4 +3.7686x3 Precision up to 3 digits after the decimal is enough. Do not need more and do not print more (I have here, but you should not). Note that each polynomial can have any number of terms (which is why you will require malloc/calloc) but the total number of polynomials in the file will be 2n. There will be n pairs of polynomials. n is 10 pairs or less (i.e. 20 polynomials maximum). You will not be given points for documenting your code, but points will be docked if you do not, with a maximum penalty of -20 points. Again, you must document what each function does and what the different parameters are for, and critical sections of the code, including how you convert decimal to binary for both decimal integers and floating point numbers. You are to do this alone, not with anyone else. No teams of two. A common way to represent a polynomial expression (e.g. 3x5 - 2.2x3 +4x 1.713) is with linked structures that have three members a) b) c) A member to represent the coefficient (3) A member to represent the exponent (5) A pointer to the next term in the expression Write a program that does the following: Write a function input poly(ptrl) that reads in two polynomials at a time with coefficient and exponent from a file cp7in.txt. The file will contain 2n polvnomials, where n is an integer that is 10 or less. Space for the polynomial will be allocated in run time and there is no limit to the size of the polynomial, e. the first two lines of the file is 3 5-2.2 341-1.713 0 3 100 -2.2 3 14 55 3.1 101 (Note the terms may be in any order) Then, two polynomials will be created 3x5- 2.2x34x 1.713 and 3.1x101 + 3x100 + 14x5- 2.2x3 Write a function add poly(ptr1, ptr2) that expects pointers ptrl and ptr2 to two lists that represent polynomials and returns a pointer to a third list that represents the sum of polynomials. You will find the sum of every pair of polynomials. 1) 2) 3) Write a function mult poly(ptrl, ptr2) that expects pointers ptrl and ptr2 to two lists that represent 4) Write a function print poly(ptrl) that prints the polynomial pointed to by ptrl to a file, cp7.out. The terms From the function main0. you may call the function print poly(ptrl) to print out the following to cp7.out: polynomials and returns a pointer to a third list that represents the product of polynomials. You will find the product of every pair of polynomials. must be printed in descending order of exponent. That is to say, e.g. 3x5 - 2.2x3+4x 1.713 is correct but e.g.-2.2x3+3x5 +4x - 1.713 is not. The sum of polynomials 3x5- 2.2x34x-1.713 3.1x101 + 3x100 + 14x5- 2.2x3 1S 3.1x101 + 3x100 + 14x55 +3x5-4.4x3 +4x-1.713 The product of polynomials:: 3x5- 2.2x34x-1.713 3.1x101 + 3x100 + 14x5- 2.2x3 1S 105 6.82x 104_6.6x10312.41026.6897 101-5 60 58 3x 5.139x100+42030.8r08+ 56x56 -23.9825.6r4.84r68.r4 +3.7686x3 Precision up to 3 digits after the decimal is enough. Do not need more and do not print more (I have here, but you should not). Note that each polynomial can have any number of terms (which is why you will require malloc/calloc) but the total number of polynomials in the file will be 2n. There will be n pairs of polynomials. n is 10 pairs or less (i.e. 20 polynomials maximum). You will not be given points for documenting your code, but points will be docked if you do not, with a maximum penalty of -20 points. Again, you must document what each function does and what the different parameters are for, and critical sections of the code, including how you convert decimal to binary for both decimal integers and floating point numbers. You are to do this alone, not with anyone else. No teams of two
Step 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