1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <cstdio>
void welcome();
void displayEqn(float a, float b, float c);
void displayResults(float x, float result);
float getX();
void readCoeffs(float &a, float &b, float &c);
float calcResults(float a, float b, float c, float x);
int main()
{
welcome();
float a, b, c, result, x;
displayEqn(a, b, c);
readCoeffs(a, b, c);
x = getX();
result = calcResults(a, b, c, x);
displayResults(x, result);
return 0;
}
void welcome()
{
printf("You will be asked to enter the three \n");
printf("coefficients for a degree 2 polynomial. The equation\n");
printf("will then be displayed and you will be given the\n");
printf("opportunity to apply the polynomial to a data value.\n");
}
void displayEqn(float a,float b, float c)
{
printf("f(X) = %.2fX^2 + %.2fX + %.2f\n", a, b, c);
}
float calcResults(float a, float b, float c, float x)
{
float result;
result = (a*x*x) + (b*x) + (c);
}
void displayResults(float x, float result)
{
printf("f(%.2f) = %.2f", x, result);
}
float getX()
{
float x;
printf("Please enter a value for X: ");
scanf("%g", &x);
return x;
}
void readCoeff(float &a, float &b, float &c)
{
printf(" Please enter the coefficient for the degree 2 term: ");
scanf("%g", &a);
printf(" Please enter the coefficient for the degree 1 term: ");
scanf("%g", &b);
printf(" Please enter the coefficient for the degree 0 term: ");
scanf("%g", &c);
}
|