Three Dimensional Shape Class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Three Dimensional Shape Class

  1. #1
    Join Date
    May 2010
    Posts
    1

    Question Three Dimensional Shape Class

    Hey all. This is an assignment I've been given by my professor for a C++ course. The assignment description is below:

    Create a class ThreeDShape that has a default constructor and pure virtual functions double getSurfaceArea(), double getVolume() and void print(). Function getSurfaceArea() should compute and return the surface area of a three dimensional shape. Function getVolume() should compute and return the volume of a three dimensional shape. Function print() should displays the values of all member variables, the surface area and the volume. The class should also declare a public static constant of type double, PI, with a value of 3.14159265358979. The code for this class and the derived classes should be place in namespace ThreeDimensionalShapes.

    Create a derived class of ThreeDShape named Sphere which has the following:
    Private member variable radius.
    A one-parameter constructor that sets the radius. The radius must be greater than 0.
    Appropriate accessor and mutator functions for the radius.
    Implementations of the pure virtual functions inherited form class ThreeDShape.

    Create a second class derived from ThreeDShape named Cylinder which has the following:
    Private member variables for the radius and the height of the cylinder.
    A two-parameter constructor that sets the height and the radius of the cylinder. Both the radius and the height must be greater than 0.
    Appropriate accessor and mutator functions for the member variables.
    Implementations of the virtual functions inherited from class ThreeDShape.

    Formulas for computing the surface areas and volumes are given below:
    Surface Area Volume
    Cylinder 2*PI * r * (r + h) PI * pow(r,2) * h where r is radius ; h is height
    Sphere: 4* PI*pow(r,2) 4.0/3.0* PI * pow(r, 3) where r is radius

    Write a driver program that creates a sphere and a cylinder and then calls the print() function to display information about them. Each class that you create should be separated into an interface (header) file and an implementation file.

    // END of description

    The parts I don't understand how to code are the virtual functions. Also how would I place the classes in a new namespace called ThreeDimensionalShapes? The other thing I am not clear on is what is meant by "Each class that you create should be separated into an interface (header) file and an implementation file." Would the implementation file be a standard .cpp file? What then should go into the header file? Any help would be very much appreciated!

  2. #2
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Three Dimensional Shape Class

    Quote Originally Posted by aspiringRPGdesigner View Post
    The parts I don't understand how to code are the virtual functions.
    What do you mean by "how to code virtual functions?" That is too broad a description of what you don't know.
    Also how would I place the classes in a new namespace called ThreeDimensionalShapes?
    Code:
    namespace ThreeDimensionalShapes 
    {
       // your classes go here
    }
    The other thing I am not clear on is what is meant by "Each class that you create should be separated into an interface (header) file and an implementation file." Would the implementation file be a standard .cpp file? What then should go into the header file? Any help would be very much appreciated!
    The implementation file is the .cpp file. What goes in the header is the class declaration.

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center