You are on page 1of 3

 Create a Square and rectangle and access

them via a pointer to Shape


◦ What happened when we try to access the area /
perimeter functions
◦ How could we solve this problem?
 HINT: virtual
class Shape{
access_specifier:
Shape();
double area ();
double perimeter();
access_specifier :
double width_, height_;
};

 Questions
◦ Does it make sense to create an object of the Shape class?
◦ Should we, and how can we, prohibit this?
HINT: pure virtual method / abstract class
 Create an array of 4 Shapes and use it to
store 2 Triangles and 2 Rectangles
 Write a program that computes the total area
of shapes in the array
◦ Are there any issues with this?
◦ If we add a member variable to store the angle
between two sides of triangle does the program
break? Why?

You might also like