OOP BSSE Spring 2015
Assignment 04
(Email before 11:59 Saturday night, 1 minute before Sunday)
Create class Shape. Shape has pure virtual functions to calculate area & perimeter. Create child
classes of Shape Rectangle, Circle, & Triangle.
- Rectangle has 4 data members start x, start y, width & length
- Circle has data member center x, center y & radius
- Triangle has x1, y1, x2, y2, x3, y3 i.e. 6 end points
Create Non-Parameterized constructor in all classes. Inside, initialize all data members randomly
between 1-10. Overwrite pure virtual functions of Parent class, see formula from Google.
Create class Ellipse child class of Circle, add another data member radius 2 because ellipse has two
radius. One is radius x & other is radius y. Implement calculate area & calculate perimeter function
in Ellipse class.
Create class Canvas. Canvas has data members count of shapes. Take a double pointer of type
Shape. Create parameterized constructor with integer variable. Inside constructor declare pointer
array of Shape according to count. Run a loop count time, inside loop generate random number 0-3
both inclusive and assign objects of different classes according to criteria:
- Create object of Rectangle, if number is 0
- Create object of Circle, if number is 1
- Create object of Triangle, if number is 2
- Create object of Ellipse, if number is 3
Create show function display area & perimeter of all objects by calling their respective functions.
------------------- Start with Bismillah & End with Alhumdulillah, May Allah be with you ------------------
Resource Person: Abdul Mateen Page 1 of 1