Write a C program The shape of a bottle is approximated by t

Write a C++ program

The shape of a bottle is approximated by two cylinders of radius r1 and r2 and heights hi and h2, joined by a cone section of height h3 (see supplied diagram). The formula for the volume of a cylinder is V = pi r^2h, and the formula for a cone section is V = pi (r_1^2 + r_1r_2 + r_2^2)h_3/3 Write a C++ program to accept the 5 required values (one at a time), calculate the volume and display the result. Name the program file volume.cpp

Solution

#include <iostream>
using namespace std;

int main() {
   // your code goes here
   float r1,r2,h1,h2,h3;
  
   cout << \"Input the height of cylinder 1 : \";
   cin >> h1;
      
   cout << \"Input the radius of cylinder 1 : \";
   cin >> r1;  

   cout << \"Input the height of cylinder 2 : \";
   cin >> h2;
      
   cout << \"Input the radius of cylinder 2 : \";
   cin >> r2;
  
      
   cout << \"Input the height of cone : \";
   cin >> h3;
  
   float v1 = 3.14*r1*r1*h1;
   float v2 = 3.14*r2*r2*h2;
   float v3 = (3.14*(r1*r1 + r2*r2 + r1*r2)*h3)/3;
  
   float total = v1+v2+v3;
  
   cout << \"Total volume is : \" << total;
   return 0;
}

Write a C++ program The shape of a bottle is approximated by two cylinders of radius r1 and r2 and heights hi and h2, joined by a cone section of height h3 (see

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site