Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, I need to make a polynomial calculator with the following methods, a Linked List should be used to store the polynomials. The exponents

In C++, I need to make a polynomial calculator with the following methods, a Linked List should be used to store the polynomials. The exponents are integers, the coefficients are real numbers. In addition to the member methods given in the notes, implement the following member methods:

add, multiply, evaluate, Coef, and LeadExp.

The input should be given interactively from the screen and be menu-driven as follows (computer prompts in italic): Your program should first ask the user : What do you wish to do: 1. Add two polynomials 2. Multiply two polynomials 3. Evaluate one polynomial at a given value 4. Find the coefficient of a given exponent for a given polynomial. 5. Find the leading (biggest) exponent for a given polynomial. 6. exit If the user chooses menu options 1 or 2, he should be asked for the two polys to be added or multiplied. For example, in response to the user picking 1: 1 Please input the first polynomial in the form of: (non-zero coefficient, exponent) pairs, in descending order of exponents 3 1 5 0 (i.e. user gave as input the poly 3x3+5) Please input the second polynomial in the same format 1 2 2 0 (i.e. user gave as input the poly x2+2) Your program should then calculate the resulting polynomial (adding the two polys for 1, or multiplying them for 2), and print the resulting poly in the form of (non-zero coefficient, exponent) pairs, in descending order of exponents. So, in the case of menu choice 1 (addition) for the above input case, the output should be:

3 3 1 2 7 0 Or if menu choice was 2 (multiply), the displayed output should be: 3 5 2 3 5 2 10 0 After which the menu choices are displayed again unless the user chose to input 6 (exit). So, for example, If the user now chooses menu option 3 (i.e. to evaluate a poly at a given value for the variable), s/he should be asked to provide a poly and a real value: Please input the polynomial in the form of: (non-zero coefficient, exponent) pairs, in descending order of exponents 3 3 5 0 (user given poly input) Please give a value to evaluate the polynomial on. 1.0 (user-given the value) Your program should then should calculate and print: The evaluation of poly (3 3 5 0) for the value 1.0 is 8.0 and repeat the menu. If the user chooses option 4, the user should be asked for a polynomial and an exponent. Please input a polynomial in the form of: (non-zero coefficient, exponent) pairs, in descending order of exponents 3 3 7 1 2 0 (user gives the poly) Please give an exponent whose coefficient you want to know. 1 (user gives an exponent) Your program should then should calculate and print: The coefficient of exponent 1 is 7

and if the user chooses option 5, s/he should be asked to input a polynomial, and then as output you should display the degree of the polynomial (i.e. its highest exponent). For example, in response to menu choice #5: Please input a polynomial in the form of (non-zero coefficient, exponent) pairs, in descending order of exponents 7 4 5 1 2 0 (user gives the poly) The degree of the given polynomial is 4 The menu should be re-displayed again after each calculation until menu option 6 is chosen, which terminates the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Understand why customers complain.

Answered: 1 week ago