1) [25 points] You’ve been hired by Sphere Calculator to write a function that u
ID: 3606608 • Letter: 1
Question
1) [25 points] You’ve been hired by Sphere Calculator to write a function that uses the global declaration of constant PI, const double PI = 3.1419;, which stores the value of p and accomplishes the following:
Prompt the user to input the value of a double variable r in unit of meters, which stores
the radius of a sphere. Use this variable as the parameter of functions that can accomplish the following:
function i. The value of A = 4r2, the surface area of the sphere. Return A then print it to the console in the main function.
Function ii. The value of V = (4/3)r3, the volume of the sphere. Return V then print it to the console in the main function.
Do NOT use using namespace std;, you need to use scope resolution operator to finish this lab assignment. The output should look like this:
Explanation / Answer
#include <iostream>
const double PI = 3.1419;
double surfaceArea(double radius){
return 4 * PI * radius * radius;
}
double volume(double radius){
return (4/3) * PI * radius * radius * radius;
}
int main()
{
double radius;
std::cout << "Enter the radius of the sphere: ";
std::cin >> radius;
double A = surfaceArea(radius);
std::cout << "Surface area of the sphere is " << A << std::endl;
double V = volume(radius);
std::cout << "Volume of the sphere is " << V << std::endl;
return 0;
}
**Comment for any further queries. Upvote if the answer is satisfactory.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.