Answer: The c++ program is given below.
#include <iostream>
#include<iomanip>
using namespace std;
double getRadius();
double calcCirc(double r);
double calcArea(double r);
int main() {
double radius, area, circumference;
int r, c, a;
radius = getRadius();
if(radius>0 && radius<10)
r=3;
if(radius>10 && radius<100)
r=4;
if(radius>100 && radius<1000)
r=5;
cout<<"The radius of the circle is "<<setprecision(r)<<radius<<endl;
circumference=calcCirc(radius);
if(circumference>0 && circumference<10)
c=3;
if(circumference>10 && circumference<100)
c=4;
if(circumference>100 && circumference<1000)
c=5;
cout<<"The circumference of the circle is "<<setprecision(c)<<circumference<<endl;
area=calcArea(radius);
if(area>0 && area<10)
a=3;
if(area>10 && area<100)
a=4;
if(area>100 && area<1000)
a=5;
cout<<"The area of the circle is "<<setprecision(a)<<area<<endl;
}
double getRadius()
{
double r;
cout<<"Enter the radius of the circle : "<<endl;
cin>>r;
return r;
}
double calcCirc(double r)
{
double PI = 3.14159;
return (2*PI*r);
}
double calcArea(double r)
{
double PI = 3.14159;
return (PI*r*r);
}
OUTPUT
Enter the radius of the circle :
11.1111
The radius of the circle is 11.11
The circumference of the circle is 69.81
The area of the circle is 387.85
Step-by-step explanation:
As per the requirement, all the variables radius, area, and circumference are declared with data type double in main function.
The methods getRadius, calcCirc, calcArea are declared with return type double.
getRadius
This method prompts the user to input the radius and returns the radius to the calling function main. This value is stored in variable radius.
calcCirc
This method takes radius as input, calculates the circumference and returns the circumference to the calling function main. This value is stored in variable circumference.
calcArea
This method takes radius as input, calculates the area and returns the area to the calling function main. This value is stored in variable area.
All the three values are displayed with two decimal places. This is achieved using setprecision() method.
The number of digits is inclusive of 2 decimal places and all digits before the decimal. This value is declared based on the values of radius, circumference and area. The total number of digits is passed as a parameter to the setprecision() method.
All the values are displayed with two decimal places.