A pyramid is a polyhedron that has a base, which can be any polygon, and three or more triangular faces that meet at a point called the apex.
Your homework defines your pyramid as one with a square base, so create a Square class. A square has only one size of side. Your single data member should preferably be a double, for precision.
Your Square class should have two overloaded constructors, default (no parameters) using a default value for the side and the other constructor that passes the value of the side.
The Square class needs a class function (method) that calculates the square's area from the single side value.
You might want to provide methods to change the square's side value, and get the value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class Square
{
private:
double side;
public:
Square();
Square(double new_side);
public:
double Area() const;
public:
double GetSide() const;
void SetSide(double new_side);
};
|
The volume of a pyramid is calculated from the area of the base and the height from the base to the apex.
Inheriting a pyramid from square could be as easy as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class Pyramid : public Square
{
private:
double height;
public:
Pyramid();
Pyramid(double new_height);
Pyramid(double new_height, double new_side);
public:
double Volume() const;
public:
double GetHeight() const;
void SetHeight(double new_height);
};
|
This should get you started.