|
-
May 13th, 2008, 01:15 PM
#16
Re: hierarchy of shapes
 Originally Posted by ptg
can any one tell me if i did the volume for the tetrahedron right because i get a volume of zero.
Here
Code:
class Tetrahedron : public ThreeDimensionalShape{
public:
Tetrahedron(double iside){
side = iside;
}
virtual ~Tetrahedron(){}
virtual double GetArea(){return (side * side) * sqrt(3.0);}
virtual double GetVolume(){return (1.0f/12)*(side *side*side)*sqrt(2.0);}
private:
double side;
};
It's just a type issue. Your answer is 0.94 but since 1/12 is treated as an integer operation, you end up getting zero.
-
May 13th, 2008, 06:43 PM
#17
Re: hierarchy of shapes
Since we're using doubles I think I would go ahead and use a double there instead of a float 
Code:
virtual double GetVolume(){return (1.0/12)*(side *side*side)*sqrt(2.0);}
-
May 14th, 2008, 01:51 AM
#18
Re: hierarchy of shapes
 Originally Posted by jlou
Since we're using doubles I think I would go ahead and use a double there instead of a float 
Code:
virtual double GetVolume(){return (1.0/12)*(side *side*side)*sqrt(2.0);}
Heh..heh. Yes, it should be double instead of float.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|