Assignment 2
Assignment 2
Important Instructions
The assignments must be submitted online using CMS/LMS. Submission
by email or any other method will not be entertained.
Copying assignment from others or submitting assignment that is com-
pleted by some other students can result in zero-marks in the assignment
or failing the course depending on the severity of the plagiarism. (The
case may be forwarded to disciplinary committee for further action)
Do not wait for the last day to start. Start as early as possible.
Description
Create a class Shape that will represent a geometrical shape. Add two data
members, name as char pointer (string) and an integer, numParams,for number
of parameters. For example, A circle has only one parameter, the radius, a
rectangle has two parameters width and height, a triangle has two parameters,
base length and height. a square has one parameter, the side of a length. Add
following member functions of the base class:
i) A default constructor that will initialize the pointer to NULL and number
of parameters to zero.
iii) A destructor to deallocate any memory. Make sure the pointer is not
null before deallocating the memory. (Figure out yourself if the destructor
1
should be virtual or not. And write your justification as comments in the
cpp file.)
iv) A member function FindArea that should calculate and return the area of
the shape. (Figure out yourself if the function sould be non-virtual, virtual
or pure virtual. Write your justification as comments in the cpp file)
Derive three classes from the Shape class namely, Circle, Rectangle and
Square. Add one double type member variable in the circle class for the radius
of the circle. Add two double type member variables width and height in the
Rectangle class. Add one double type member variable sideLength in the square
class. It is up to you to decide appropriate constructors and a destructor in each
of the three classes. In the destructor just add a display line e.g. ”Destructor
of Circle”. Override the FindeArea and FindPerimeter methds in each of the
derived classes that calculate and return the area and perimeter of the given
shape.
Furthermore, add following functionality.
i) Add copy constructors in the base class as well as in each of the derived
classes.
ii) Overload the assignment operator in the base as well as derived classes.