Generate a polynomial program.

Can you please give me some idea on how to do this problem.

The math department has asked us to write a program that will allow the user to enter

in information about a polynomial function. Then the program needs to allow the user to

enter any value in for x and output the result in the following format:

When the user is prompted for the coefficients of the individual terms the variable part of

the term must be represented i.e. x^4

1. Have to make your own function, power(), to calculate x value raised to a power… no using

the built-in function.

2. Ask the user for the highest exponent. Need to make sure that the highest exponent is a

positive integer. Your program only needs to check this once and then moves on with the

program knowing that the second time it will be entered correctly.

3. If coefficient is 0 the function should never be called.

4. Use a “for” loop when asking for the coefficients.

5. Do not use any global variables.

6. Do not use array to hold coefficients. Indeed, you don’t need to.

7. All local variables in main() and power() need to be declared at the beginning of the

functions

8. The program must ask for the highest exponent of the polynomial they need to check that

the exponent enter is a positive number (once) check for this once by entering a negative

value at the time prompted. When re-prompted enter the correct value.

9. Must use a “for” loop when asking for the coefficients

10. Must only use “<” or “<=” with their “for” loops

11. Must have a function that finds a number raised to a power. The multiplying must be done

in the function i.e. 2^3 must be 2 * 2 * 2 and this must be done using a “for” loop

a. Must use a “for” loop for doing the multiplying in the function

b. Should only be two values sent to the function, x value and number of times it needs

to be multiply – 5 if they send more than these two.

They are supposed to allow the user to enter the values of a polynomial and let the user enter a

value for x and the program will evaluate the result. Note that coefficients and x can be floating-
point numbers.



Sample Run 1:

$ ./polynormial.exe

Enter the highest exponent of your function: 5

Enter the value of x: -2.2

Enter the coefficient of the x^5 term: -5

Enter the coefficient of the x^4 term: 2

Enter the coefficient of the x^3 term: -7

Enter the coefficient of the x^2 term: -3

Enter the coefficient of the x^1 term: 8

Enter the constant number for your function: -17

f(-2.2)= 329.949

Sample Run 2:

$ ./polynormial.exe

Enter the highest exponent of your function: -7

This exponent is negative

Please enter a positive integer now: 5

Enter the value of x: 3

Enter the coefficient of the x^5 term: 3.4

Enter the coefficient of the x^4 term: 0

Enter the coefficient of the x^3 term: 7.6

Enter the coefficient of the x^2 term: -4

Enter the coefficient of the x^1 term: 0

Enter the constant number for your function: 5

f(3)= 1000.4n here.

Topic archived. No new replies allowed.