0% found this document useful (0 votes)
3 views2 pages

Assignment 2

The assignment requires students to create a Shape class in C++ with specific member functions and data members, including constructors, destructors, and methods to calculate area and perimeter. Students must derive Circle, Rectangle, and Square classes from Shape, implementing additional functionalities such as copy constructors and operator overloading. The assignment must be submitted as a zip file on CMS/LMS by April 25, 2025, and plagiarism will result in severe consequences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Assignment 2

The assignment requires students to create a Shape class in C++ with specific member functions and data members, including constructors, destructors, and methods to calculate area and perimeter. Students must derive Circle, Rectangle, and Square classes from Shape, implementing additional functionalities such as copy constructors and operator overloading. The assignment must be submitted as a zip file on CMS/LMS by April 25, 2025, and plagiarism will result in severe consequences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 2 (Graded)

COSC-1102-Object Oriented Programming


Course Instructor: Dr. Nasir Mehmood
Submission Deadline: April 25, 2025, 11:59:59 PM
Submission Method: Submit on CMS/LMS

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.

ˆ Write complete code in single file ”YourCompleteRollNo.cpp” for example


(CSEC261100200.cpp) and create a zip file ”YourCompleteRollNo.zip”.
Make sure there is no folder or any other file in the zip file. Upload
”YourCompleteRollNo.zip” on CMS

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.

ii) A parameterized constructor that receives a string (as a character pointer)


and an integer for the number of parameters. The constructor first dynam-
ically allocates memory for the name variable and then copies values of the
parameters to the member variables.

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)

v) A member function FindPerimeter that should calculate and return the


perimeter of the shape. (Figure out yourself if the function sould 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.

iii) Overload insertion operator to display parameters of each of the derived


classes. For example, cout<<Circle; should display parameters of the Cir-
cle.
Write main function to test your code completely.

You might also like