Question

C-Programming please.

The task is to create second-degree polynomial calculator for the function, its integral and its derivative. A second-degree5. Your program is to loop over all possible x values in your main() function. The first x value is to be x, the second x + A

10. An example of what the output table should look like is given below. Assume that the user enters 2.0 -2.0 -1.0 for a, b,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_SIZE 100

void explain ();
double userinput(char*);
void calculations(int a, int b, int c, int x, int x_initial, double *f, double *fprime, double *area);

int main()
{
double a, b, c, xi, xf, deltaX; // a, b, c, x initial, x final and x step variables
double x[MAX_SIZE], f[MAX_SIZE], fprime[MAX_SIZE], A[MAX_SIZE];
int i = 0; //counter for for loops
int N = 0; // the size of the arrays
explain();

//prompts user to enter values
a = userinput("Enter a value for a:\n");
b = userinput("Enter a value for b:\n");
c = userinput("Enter a value for c:\n");
xi = userinput("Enter a value for x initial:\n");
xf = userinput("Enter a value for x final:\n");
deltaX = userinput("Enter a value for x step:\n");

printf("f(x) = %gx^2 + %gx + %g\n\n", a, b, c);

N = xf / deltaX; // the seize of all arrays


printf(" x\tf(x)\tf'(x)\tA\t\n");
printf("-----------------------------\n");

for(i = 0; i <= N; i++) {
x[i] = xi + (i * deltaX);
calculations(a, b, c, x[i], xi, &f[i], &fprime[i], &A[i]);
printf(" %.3f\t%.3f\t%.3f\t%.3f\t\n", x[i], f[i], fprime[i], A[i]);
}
return 0;

}

//explains the program to the user
void explain()
{
printf("Hello! This program accepts inputs for a, b, c, x initial,\n");
printf("x final and x step. The program generates and outputs f(x),\n");
printf("f'(x) and the area under the curve using the integral.\n\n");
}

//error checks for only numbers entering the program
double userinput(char message [])
{

double answer; //variable to hold answer
int status, error; //variable to check if there is an error

do
{
printf("%s", message);
status = scanf("%lf", &answer);

error = status != 1;

if (error)
{
printf("Input Error...\n");
fflush(stdin);
}
}
while (error);

return answer;
}

void calculations(int a, int b, int c, int x, int x_initial, double *f, double *fprime, double *area){
double Fx_i = 0;
double Fx = 0;

Fx_i = (a / 3) * (x_initial * x_initial * x_initial) + (b / 2) * (x_initial * x_initial) + c * x_initial;
Fx = (a / 3) * (x * x * x) + (b / 2) * (x * x) + c * x;

*f = (a * x * x) + (b * x) + c;
*fprime = (2 * a * x) + b;
*area = Fx - Fx_i;

}

Output:

Add a comment
Know the answer?
Add Answer to:
C-Programming please. The task is to create second-degree polynomial calculator for the function, its integral and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the final project, you will create an integral calculator polynomials of degree zero, one, two...

    For the final project, you will create an integral calculator polynomials of degree zero, one, two three and four Degree Function yz where z is a constant 3 where a,b.c.d.z e R, real numbers You will ask the user for the degree of the polynomial and then the coefficients and the constant values of the polynomial. Then you will ask the user for the beginning and the end of the interval along with the number of steps between the interval...

  • Python 3 please and thank you Task 3: Create a Function 7 Create the function TotalRewardPoints...

    Python 3 please and thank you Task 3: Create a Function 7 Create the function TotalRewardPoints which accepts the dictionary that you created in Task 1 and a list of ticket purchases and displays the information as shown below. Ticket Purchase List is formatted as [Number of Tickets, Type of Ticket....] The total reward points a user gets is calculated by using the following formula: Reward Points = Number of Ticket Bought x Reward Points for that Ticket Type Your...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • python the polynomial equation is Ax^3+Bx^2+Cx+D b) Evaluating a polynomial derivative numerically For a function f(x),...

    python the polynomial equation is Ax^3+Bx^2+Cx+D b) Evaluating a polynomial derivative numerically For a function f(x), the derivative of the function at a value x can be found by evaluating f(x+2)-(*) and finding the limit as a gets closer and closer to 0. Using the same polynomial as the user entered in part (a), and for the same value of x as entered in part (a), compute the limit numerically. That is, start with an estimate by evaluating** 72 using...

  • A function f, which has derivatives for all orders for all real numbers, has a 3rd degree Taylor polynomial for f center...

    A function f, which has derivatives for all orders for all real numbers, has a 3rd degree Taylor polynomial for f centered at x = 5. The 4th derivative of f satisfies the inequality f^(4)(x) ≤ 6 for all x the interval from 4.5 to 5 inclusive. Find the LaGrange error bound if the 3rd degree Taylor polynomial is used to estimate f(4.5). You must show your work but do not need to evaluate the remainder expression.

  • Python: Create a simple program that calls a function call gradeCalculated, in the main area the...

    Python: Create a simple program that calls a function call gradeCalculated, in the main area the user is asked to enter their grade from 0-100. Pass in the number grade via a parameter into the function, based on their grade tell the user what letter grade they got as a letter grade and number and then tell me a quote how you feel about your grade. 90+ A 80-89 B 70-79 C 60-69 D Below 60 F

  • *Please try to use C++ specific coding for my understanding because I never learned C. A...

    *Please try to use C++ specific coding for my understanding because I never learned C. A polynomial P is a function defined by an array of coefficients CI. Example : C-(4, 2, 1), then In the general case, given the array CI of size N, we can define Write a program - with the function main0 that gets N, the coefficients C] and a value x from the user. - with a function poly( that calculates and returns the value...

  • C++ Question Polynomial Calculator (Will Rate All Answers) Hello, this question will be divided into many...

    C++ Question Polynomial Calculator (Will Rate All Answers) Hello, this question will be divided into many parts, this is the second part. Will quickly rate your answer! Thank you. First part is here : https://www.chegg.com/homework-help/questions-and-answers/c-question-polynomial-calculator-rate-answers-hello-question-divided-many-parts-s-first-pa-q39525382 This question has to do with operators and polynomials. - Scalar Polynomial Multiplication: const Polynomial operator* (const Polynomial& P, double z) The scalar multiplication P * z simply multiplies each coefficient in p with z as depicted in the following example: 0.5 (3.2x5 + 1.6x2...

  • Use C Create a function that will take in a vector (three double variables) representing a...

    Use C Create a function that will take in a vector (three double variables) representing a position in meters. Calculate the magnitude of the vector in meters: sqrt(x * x + y * y + z * z) Calculate the magnitude of the vector in feet: magnitudeInMeters * 3.28084 Using passing by reference, return both outputs from the same function. Input: Three unique doubles, each one representing a component of the vector. Output: Magnitude of the vector in meters, magnitude...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT