You are on page 1of 3

Assignment 2 Report

1. Interpreted program requirements:

This program will take user input (a number between 1 and 5).
 Option 1 will ask more information about a shape before sending it to an array.
 Option 2 will calculate the area of each form in the array.
 Option 3 will show the data from the array's forms without sorting it.
• Option 4 will offer the user the option to select between (a, b, or c). A will display forms from
smallest to largest in terms of area. B will display forms in descending order of largest to
smallest area. C will exhibit forms in each category in order of largest to smallest. Starting with
WS shapes and proceeding on to NS shapes.
2. Program design:

Main Menu

Input sensor
Data
Select output

Calculate Area

Print Shapes
output

Sort the
Shapes
3. Summary of function implementation:
Class structure:

Vertex
The coordinates of a shape's vertex are kept in this struct. It has a comparator to arrange the
vertices first on the y-axis and then on the x-axis, along with a default constructor and another
constructor.
ShapeTwoD
It includes the shape's name, a boolean indicating if it contains warpspace, and a vector
representing its vertices.
Constructors are the first three methods. There is one default constructor, one for circles, and
one for the remaining forms.
These files define the ShapeTwoD base class, which is a two-dimensional form representation
abstract class. The name of the shape and whether or not it contains warp space are private
members of the class.It provides virtual functions for building data, computing area, acquiring
area, identifying whether a point is within or on the shape, and producing a string
representation of the form. The constructor determines the form's name and warp space state.

Circle
Circle, in addition to inheriting all variables and methods from ShapeTwoD, includes two
additional variables for storing data not contained in ShapeTwoD: center and radius.
To be applicable to a circular shape, the methods toString, computeArea, isPointInShape,
isPointOnShape, getPerimeter, and getInternal are overridden.
Methods for changing and accessing the new variables are added.

Cross
The methods toString, computeArea, isPointInShape, isPointOnShape, getPerimeter, and
getInternal are overridden to be applicable to a cross shape.
The isValidCross method has been introduced. This is a static method that checks if an array of
vertices makes a valid cross.
Rectangle
A method isValidSquare is added. This is a static method to determine if an array of vertices
makes a valid square.
The methods toString, computeArea, isPointInShape, isPointOnShape, getPerimeter, and
getInternal are overridden to be relevant to a rectangular form.
The isValidRectangle function is introduced. This is a static method that checks if an array of
vertices makes a valid rectangle.
Square
A method isValidSquare is added. This is a static method to determine if an array of vertices
makes a valid square.
The methods toString, computeArea, isPointInShape, isPointOnShape, getPerimeter, and
getInternal are overridden to be applicable to a square shape.
A method called isValidSquare is introduced. This is a static method for determining if an array
of vertices forms a valid square.
4. Reflection:

I gained a better grasp of object-oriented programming principles in C++, such as inheritance,


encapsulation, polymorphism, and class hierarchies, as a result of this approach. My approach to
integrating shape-specific behaviour within derived classes while utilising the base class's
common functions exemplifies modular and maintainable code architecture.

To increase code readability, maintainability, and separation of responsibilities, the code might
be organized into separate header and implementation files for each class. Additionally,
consistent use of access specifiers like as public, private, and protected in class declarations, as
well as suitable visibility for member variables and methods, might imprve code clarity.

You might also like