Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program, including comments, to do the following: Your prog

ID: 3548939 • Letter: W

Question


Write a complete C++ program, including comments, to do the following: Your program will compute the values of a formula that expresses y in terms of x. The formula is:

where B...B means "absolute value of" and (...)1?2 means "square root of". (Use the built-in functions for these operations.)

y =  (9x^3 - 27x^2-4x +12)/((3x^2+1)^1/2 + |5-x^4 | )

The program should start by printing a message saying this is the output of your first program.

Then, it should evaluate the formula starting with x = -3, going up by 0.5 each time, until x reaches 4. Therefore, it will use values x: -3, -2.5, ..., -0.5, 0, 0.5, ..., 3.5, 4. For each value of x, the program should compute the corresponding value of y. It should print these values together with explanations of what the values represent. For example, it could print the string 'X = ', then the value of x, then the string 'Y = ', then the value of y, and then a message. (It is also possible to use column headings instead if you desire.) The message should say one of three things:

a) If the value of y is exactly 0, the message should say 'Y IS ZERO'.
b) If the value of y is positive, the message should say 'Y IS POSITIVE'. c) If the value of y is negative, the message should say 'Y IS NEGATIVE'.

A typical line of output would then be:

X = -2.5 Y = 1.23456 Y IS POSITIVE (in actuality, this may not be the value for y).

Once you have finished using x = 4, the program should print a message (underneath the last line of output) stating that the program is halting. Then, stop.

Have your program find which of the y values is closest to 10 (either larger or smaller). have the program print the x value that gives this closest y value. Also, print how close the y value is to 10.

Write a complete C++ program, including comments, to do the following: Your program will compute the values of a formula that expresses y in terms of x. The formula is: where B...B means "absolute value of" and (...)1?2 means "square root of". (Use the built-in functions for these operations.) y = (9x^3 - 27x^2-4x +12)/((3x^2+1)^1/2 + |5-x^4 | ) The program should start by printing a message saying this is the output of your first program. Then, it should evaluate the formula starting with x = -3, going up by 0.5 each time, until x reaches 4. Therefore, it will use values x: -3, -2.5, ..., -0.5, 0, 0.5, ..., 3.5, 4. For each value of x, the program should compute the corresponding value of y. It should print these values together with explanations of what the values represent. For example, it could print the string 'X = ', then the value of x, then the string 'Y = ', then the value of y, and then a message. (It is also possible to use column headings instead if you desire.) The message should say one of three things: If the value of y is exactly 0, the message should say 'Y IS ZERO'. If the value of y is positive, the message should say 'Y IS POSITIVE'. c) If the value of y is negative, the message should say 'Y IS NEGATIVE'. A typical line of output would then be: X = -2.5 Y = 1.23456 Y IS POSITIVE (in actuality, this may not be the value for y). Once you have finished using x = 4, the program should print a message (underneath the last line of output) stating that the program is halting. Then, stop. Have your program find which of the y values is closest to 10 (either larger or smaller). have the program print the x value that gives this closest y value. Also, print how close the y value is to 10.

Explanation / Answer

In C++


/* Header File declaration
cmath header file is used to declare pow and sqrt functions */
#include<iostream>
#include<cmath>

using namespace std;

//Driver Program
int main()
{
float x = -3; // Declaring X as float as it is decimal value
double y; //Declaring y as double as square root function gives double value
double maxX = -3, maxY = 0.0;

//While loop is to run through all the values from -3 to 4 with 0.5 increment
while ( x <= 4)
{
//Below function is to get the y value using functions
y = ( 9 * pow(x,3) - 27 * pow(x,2) - (4 * x) + 12 ) / (sqrt(( (3 * pow(x,2)) + 1 )) + abs(5 - pow(x,4)));

//Printing X and Y value
cout<<"X = "<<x<<" Y = "<<y<<" ";

//Below if and else block checks whether x is postive, negative or zero
if ( y < 0 )
cout<<"Y is NEGATIVE"<<endl;
else if ( y==0)
cout<<"Y is ZERO"<<endl;
else
cout<<"Y is POSITIVE"<<endl;

//Below if and else block checks for the closest
if ( abs(10-y)< abs(10 - maxY))
{
maxY = y;
maxX = x;
}
else
cout<<"Not closest"<<endl;

x = x + 0.5;
}

cout<<"The program is halting"<<endl;
cout<<" The closest value of y was at :"<<maxX<<" by "<<abs(10-maxY)<<" units";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote