Answer to Question #315610 in C++ for cece

Question #315610

Write a program that defines the named constant PI, const double PI = 3.14159;, which stores the value of π. The program should use PI and the functions listed in Table 6-1 to accomplish the following:

  • Output the value of √π .
  • Prompt the user to input the value of a double variable r, which stores the radius of a sphere. The program then outputs the following:
  • The value of 4.0πr², which is the surface area of the sphere.
  • The value of (4.0/3.0)πr³, which is the volume of the sphere.
1
Expert's answer
2022-03-22T09:07:08-0400
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;




int main(void){
	const double PI = 3.14159;
	double r;
	cout<<"sqrt(PI): "<<sqrt(PI)<<"\n";
	cout<<"Enter the radius of a sphere: ";
	cin>>r;
	double surfaceArea=4*PI*r*r;
	double volume=(4.0/3.0)*PI*r*r*r;


	
	cout<<"The surface area of the sphere: "<<surfaceArea<<"\n";
	cout<<"The volume of the sphere: "<<volume<<"\n";
	
	
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog