CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: hierarchy of shapes

    Quote 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.
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  2. #17
    Join Date
    Feb 2003
    Posts
    377

    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);}

  3. #18
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: hierarchy of shapes

    Quote 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.
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured