write a c++ program that asks the user for a radius r. The program must include
ID: 3641453 • Letter: W
Question
write a c++ program that asks the user for a radius r. The program must include a function called calcwradius that accepts the value of the radius r, and calls the function pi shown belowdouble pi()
{
return (2.0 * asin(1.0);
}
then calculates and passes the following three values back to the main function:
1. volume = (4/3) pi r^3
2. area = pi r^2
3. circum =2 pi r
the main function will then print these values to the screen. You must include the function pi() and the prototypes for pi and clacwradius in your program.
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
//PROTOTYPES
void calcwradius(double, double &, double &, double &);
int main()
{
//LOCAL DECLARATIONS
double radius;
double volume;
double area;
double circum;
cout << "Enter radius: ";
cin >> radius;
calcwradius(radius, volume, area, circum);
cout << endl << fixed << setprecision(3)
<< "Volume: " << volume << endl
<< "Area: " << area << endl
<< "Circumference: " << circum << endl;
cout << endl;
return 0;
}
//---------------------------------------------------------
// FUNCTION DEFINITIONS
//---------------------------------------------------------
double pi()
{
return 2.0 * asin(1.0);
}
//---------------------------------------------------------
void calcwradius(double radius, double &volume,
double &area, double &circum)
{
volume = (4.0 / 3.0) * pi() * pow(radius, 3.0);
area = pi() * radius * radius;
circum = 2.0 * pi() * radius;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.