Activity: Cone Volume (iPad)

The Assignment

Working with your partner, write a C++ program which computes the volume of a cone, given the radius (r) and height (h), using the formula:

cone_volume

For example, if the input is 20.0 3.0, the output should be

Volume of this cone: 1256.636

Begin by creating a new C++ file called ConeVolume.cpp in the iPad C++ compiler. Next, copy and paste this starter code into the file:

#include <iostream>
#include <cmath>

using namespace std;

int main() 
{
   const double PI = 3.14159;// a constant for the value of "pi"
   double radius = 0.0;      // declare a variable to store the cone radius
   double height = 0.0;      // declare a variable to store the height of the cone
   double volume = 0.0;      // declare a variable to store the volume of the cone
   
   // input the radius and height...
   cin >> radius >> height;
   
   // compute the volume of the cone...

   cout.setf(ios::fixed);    // always show the decimal point
   cout.precision(3);        // two digits on the right of the decimal
   
   // output the volume...
   cout << "Volume of this cone: " << volume << endl;
   // return "success" to the OS...
   return 0;
}

Modify the code to complete the assignment. When you have completed the assignment, demonstrate it for the instructor.