I
Irina Danilyuk
For one of the questions on the assigment sheet it said to 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.)
1. The program should start by printing a message saying this is the
output of your first program.
2. 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).
3. 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.
4. 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.
5. Have your program count how many times the formula yields positive,
negative, and zero results. Print these three values.
So far I have worked with a different program, and had a code done for
it, to help me with this assignment, but I do not understand where I
should be posting them to complete the program. because both of the
problems are similar.
/* program prob2
* create a table to evaluate a formula result = f(gpa)
*/
#include <iostream>
using namespace std;
int main()
{
double gpa,result;
cout << "Table of Function Values" << endl << endl;
cout << "Grade Point Average Value of Formula Status" <<
endl;
for (gpa = 0.00; gpa <= 4.00; gpa = gpa + 0.50)
{
result=(gpa*gpa*gpa+7*gpa-1)/(gpa*gpa - (gpa+5)/3);
cout << " " << gpa << " " << result;
if (result >= 0)
cout << " Admit";
cout << endl;
}
cout << endl << "The table is finished" << endl;
// system("pause"); //un-comment when using DevC++
return 0;
}
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.)
1. The program should start by printing a message saying this is the
output of your first program.
2. 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).
3. 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.
4. 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.
5. Have your program count how many times the formula yields positive,
negative, and zero results. Print these three values.
So far I have worked with a different program, and had a code done for
it, to help me with this assignment, but I do not understand where I
should be posting them to complete the program. because both of the
problems are similar.
/* program prob2
* create a table to evaluate a formula result = f(gpa)
*/
#include <iostream>
using namespace std;
int main()
{
double gpa,result;
cout << "Table of Function Values" << endl << endl;
cout << "Grade Point Average Value of Formula Status" <<
endl;
for (gpa = 0.00; gpa <= 4.00; gpa = gpa + 0.50)
{
result=(gpa*gpa*gpa+7*gpa-1)/(gpa*gpa - (gpa+5)/3);
cout << " " << gpa << " " << result;
if (result >= 0)
cout << " Admit";
cout << endl;
}
cout << endl << "The table is finished" << endl;
// system("pause"); //un-comment when using DevC++
return 0;
}