data for a clipped cone

This is a program for finding data for a clipped cone I'm not getting the equations for slant_height ,volume,surface area right where am I going wrong ?

#include <iostream>

#include <cmath> // sqrt
using namespace std;

int main()
{

// constants
const double PI = 3.14159;

// variables definitions
double height;
double surface_area;
double slant_height;
double volume;

// Interger literals
height = 3.91;
//

cout << "Albert Grennan\n\n";
cout << "Height " << height << endl;
cout << "slant height" << slant_height << endl;
cout << "surface area" << surface_area << endl;
cout << "volume " << volume << endl;

return 0;

First, please post code with code tags. See http://www.cplusplus.com/articles/jEywvCM9/

Now, lets look at the first equation:
 ``12`` ``````// slant_height = sqrt(pow(height, 2)) + pow(radius2 - radius1, 2);``````

Are you, by any chance, using Pythagora's a²+b²=c² ?

Whether or not, let me break down your equation a bit:
 ``123456`` ``````auto a = height; auto b = radius2 - radius1; // note that pow( foo, 2 ) == foo*foo // substitute your pows with a*a and b*b: slant_height = sqrt( a*a ) + b*b;``````

Does the equation still look as it should?

 ``12`` ``````surface_area = PI * (pow(radius1, 2)) + (pow(radius2, 2)) + (radius1 + radius2) * slant_height; volume = PI * height / 3 * (pow(radius1, 2)) + (radius1 * radius2) + (pow(radius2, 2));``````

Can't help it. Must rephrase:
 ``123456789`` ``````auto rad1pow = pow(radius1, 2); auto rad2pow = pow(radius2, 2); // substitute: surface_area = PI * (rad1pow) + (rad2pow) + (radius1 + radius2) * slant_height; volume = PI * height / 3 * (rad1pow) + (radius1 * radius2) + (rad2pow); // there are still unnecessary parentheses. Remove them: surface_area = PI * rad1pow + rad2pow + (radius1 + radius2) * slant_height; volume = PI * height / 3 * rad1pow + radius1 * radius2 + rad2pow;``````

Is that really how area and volume are calculated?
Last edited on
Sorry this is my first time here and thank you

slant height = sqrt h2 + ( r2 – r1 )2

surface area = PI[r12 + r22 + ( r1 + r2 )s] volume = PI* 3 h ( r12 + r1r2 + r22
the equations are from a algebra textbook I've been trying to figure out what parentheses don't belong. when you put rad1pow is that the way you enter it ? how does that work? does it automatically use the second power? how does it know the exponent ? Thank you and I'll go articles and what code tags are

Thanks
Are your dimensions those shown as r1, r2 and h below?
 ``` .\ /|\ . | . \ | . | . \ | . | . \ | . | - ---------- | APEX /|\ | r1 \ | | | \ | | | \ | h | \ | | | \ | | | \ | \|/ | r2 \ \|/ - ------------------ - ```

If so, you may find it easier to find the hypothetical apex height of the original cone first:
APEX = h * r2 / (r2 - r1)

Then the height of the removed cone with radius r1, is APEX - h.

Volume and curved surface area best found by subtraction as WHOLE CONE minus REMOVED CONE.

Volume (for a non-truncated cone) = PI.R2.H/3
Curved surface area (for a non-truncated cone) = PI.R.L, where L is slant length.

Slant length L found by Pythagoras. For the total surface area you presumably wish to add the circular areas at top and bottom.

After a lot of algebra, and some fortuitous(?) cancellation, I get
V = PI (r12+r22+r1r2)h/3
A = PI [ (r1+r2)S + r12 + r22 ] (including top and bottom circles)
where
S = sqrt[ h2 + (r2-r1)2 ]
is the slant length of the truncated cone.

I would always write `R * R`, not `pow(R,2)`.

Your BRACKETING is wrong. If you space out your variables much more, you will find it easier to get brackets in the correct place - this is particularly true of your sqrt() calculation for slant height and the collection of terms for volume.

You might also like to make PI a little more accurate, whilst "Interger" is actually spelt "double".
Last edited on
Topic archived. No new replies allowed.