Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a full C++ program that computes the volume of a sphere of radius, r, (V_s

ID: 3806315 • Letter: W

Question

Write a full C++ program that computes the volume of a sphere of radius, r, (V_sphere = 4/3 pir^3) and the Area of a sphere (A_sphere = 4 pi r^2/h) where h is some division(a section of) of the area. It starts by asking the user for a value of r and if r > 0 but  100 cm than the program calculates the area of a sphere but it must ask for the h value or the division(or part of the area) wanted of the sphere in that case. It outputs the area of the sphere along with the h value. The program continues (it asks for another value of r then returns) until r=0 which causes it to terminate. If r is out of the range then your program should produce a message to the user stating that fact. Flow chart last program

Explanation / Answer

#include<iostream>
#include<math.h>
#define pi 3.14
using namespace std;
int main()
{
   double r;//variable declaration
   int h;
   while(1)//loop breaks when radius is 0
   {
      cout<<"Enter radius (in centimeters)(0 to exit): ";
      cin>>r;//reading number
      if(r==0)//breaking condition of loop
      break;
      else if(r>0 && r<50)
      {//then printing Volume of the sphere
       cout<<"Volume of sphere is: "<<(4/3*pi*r*r*r)<<"cm^3"<<endl;//calculating and sphere volume
      }
      else if(r>100)
      {
       cout<<"Enter divison(or part of area) value:";
       cin>>h;//reading number      
       cout<<"Area of sphere is: "<<((4*pi*r*r)/h)<<"cm^2"<<endl;//calculating and sphere area
  
      }
      else
      {
       cout<<"Given radius is out of range | it is either between 0 to 50 or greater than 100:"<<endl;      
      }
   }
  
   return 0;
}

output:-

Enter radius (in centimeters)(0 to exit): 10
Volume of sphere is: 3140cm^3
Enter radius (in centimeters)(0 to exit): 101
Enter divison(or part of area) value:2
Area of sphere is: 64062.3cm^2
Enter radius (in centimeters)(0 to exit): 60
Given radius is out of range | it is either between 0 to 50 or greater than 100:
Enter radius (in centimeters)(0 to exit): -1
Given radius is out of range | it is either between 0 to 50 or greater than 100:
Enter radius (in centimeters)(0 to exit): 5
Volume of sphere is: 392.5cm^3
Enter radius (in centimeters)(0 to exit): 120
Enter divison(or part of area) value:10
Area of sphere is: 18086.4cm^2
Enter radius (in centimeters)(0 to exit): 0


Process exited normally.
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote