Lab 8
int mystery (int x, double y, char ch)
{
int u’
if (‘A’ <= ch && ch <= ‘R’)
return (2*x +
static_cast<int> (y));
else
return(
static_cast<int>(2 * y) – x);
}
What is the output of the
following C++ statements?
a.
cout <<
mystery (5, 4.3, ‘B’) << endl;
b.
cout <<
mystery (4, 9.7, ‘v’_ << endl;
c. cout << 2 * mystery (6, 3.9, ‘D’) << endl;
If one of the points
corresponds to the center point of a circle, and the other point corresponds to
a point on the circle, we can figure out the radius of the circle using the
above formula.
Here is the main
program:
#include<iostream>
#include<cmath>
using
namespace std;
//the
function prototype goes here
int
main()
{
double x1,y1,x2,y2;
cout<<"Enter 4 numbers
corresponding to the”;
cout<<"coordinates of two
points";
cin>>x1>>y1>>x2>>y2;
cout<<"The radius is:
"<<radius(x1,y1,x2,y2);
return 0;
}
//the
code of the function goes here
Type in the code
that is listed above. Create the
function prototype and function code for radius and place them in the appropriate spots. The function accepts 4 double numbers and
return 1 double number. The function
should use the sqrt and pow
predefined functions.
Write another
function called circumference, that takes the radius of the circle and
returns the circle’s circumference. The
formula for a circumference is: 2àr where à = 3.14
Write another
function called area
that takes the radius of the
circle and returns the area of the circle.
The formula for the area of the circle is: àr2
Edit main() to call
circumference and area and print out the value for both