Write a C++ program that computes and outputs the volume of a cone, given the diameter of its base and its height. The formula for computing the cone’s volume is:
1/3 Pi X Radius2 X Height
The output should be clearly labelled.
Write a C++ program that...?
Ok
When u r programming, try to divide ur program into functions, and if possible, try to divide each function into smaller and smaller functions, that makes it easier when u r trying to find errors in ur program, and when u r explaining the code to somebody else, this technique is called "divide and conquer".
Define a function that calculates the volume of the cone, this function should take 2 parameters, the radius and the height as double or float, and it should return the area as a double or float.
#include %26lt;iostream.h%26gt;
#define pi 3.1415926535
// Definition of the function (area of cone)
double cone_area(double height, double radius)
{
return (1/3)*pi*radius*height;
}
void main()
{
double raidus,height;
cout%26lt;%26lt;"We are going to calculate the area of a cone"%26lt;%26lt;endl;
cout%26lt;%26lt;"Enter its raidus: ";
cin%26gt;%26gt;radius;
cout%26lt;%26lt;endl;
cout%26lt;%26lt;"Enter it height: ";
cin%26gt;%26gt;height;
cout%26lt;%26lt;"Area of that cone = "%26lt;%26lt;cone_area(height,radius)%26lt;%26lt;endl;
}
Good luck
Bye
Reply:Can only answer Java questios.
Reply:This program should do it. I'm not sure what input you will use? This is just basic. And I used 22/7 for pi.
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
float diameter = 0;
float height = 0;
cout %26lt;%26lt; "Enter the diameter:";
cin %26gt;%26gt; diameter;
cout %26lt;%26lt; "Enter the height:";
cin %26gt;%26gt; height;
float volume = 0;
volume = (1/3)*(22/7)*(diameter/2)*2*height;
cout %26lt;%26lt; "The volume is: " %26lt;%26lt; volume %26lt;%26lt; endl;
}
wedding
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment