Write the definition of the Shape class in Shapes.h.
Shape should have a pure virtual function named Draw. Draw should be pure virtual because you cannot "draw" an abstract shape, but you would like to force subclasses to draw it. The function should return void and be const.
Shape should have another pure virtual function named getArea. getArea should be pure virtual because you cannot calculate the area of an abstract shape, but you would like to force subclasses to define it. The function should return a double and be const.
Shape should have a virtual (not pure virtual) function
called getName. getName simply returns a string that is the name
of the Shape, in shape's case: "Abstract Shape" (do
return "Abstract Shape"
in the function). You can define
this function in-line in Shape.h. The function should return
a string and be const.
Hints:
class X
{
...
string MyFunction() const
{
return "hello world";
}
...
};
Write the definition of the Square class in Shapes.h, directly after Shape. You can put the implementation (stuff that usually goes in the .cpp) in Shapes.h if you wish.
Square should publicly inherit off of Shape.
Square's constructor takes in one parameter: a double that tells the length of a square's side. You should have a private data double that stores this length.
Square should override the three virtual functions provided in Shape:
Write the definition of the Triangle class in Shapes.h, directly after Square. You can put the implementation (stuff that usually goes in the .cpp) in Shapes.h if you wish.
Triangle should publicly inherit off of Shape.
Triangle's constructor takes in two parameters: a double that tells the length of triangle's base and a double that tells the length of the triangle's height. You should have two private data doubles that store this data.
Triangle should override the three virtual functions provided in Shape:
vector < Shape* >
)g++ -ansi -Wall Lab10Main.cpp
(this may change if you have any more .cpp's)./a.out
Square
- Area: 16
- []
Triangle
- Area: 10
- |>
Square
- Area: 25
- []
Triangle
- Area: 20
- |>
Extra Credit
2 points: Square ASCII art
In Draw() for Square,
print out the square in ASCII art. For example, a square of
size 3 should look like:
***
***
***
4 points: Triangle ASCII art
In Draw() for Triangle,
print out the triangle (assume it is a right triangle) in ASCII art. For example, a triangle
of size 3x5 should look like:
*
***
*****
The hypotenuse should be as straight as possible (think about how you can use the formula of a line: y = mx+b). Please demonstrate
your beautiful art with several new triangles with interesting
dimensions.