I’ve been looking all over the web to find anyone who might have made a program to do this.
it’s supposed to have an inheritance in the format of
class line:: public shape
class verticalline :: public line
class horizontalline :: public line
class triangle :: public shape
class parallelogram :: public shape
class rectangle :: public parallelogram
These classes represent shapes in two-dimensional plane via the Cartesian coordinates. In particular, the class Shape is an abstract class with the following data members:
double *x; double *y; string color;
A Line object has two points: x and y pointers are both to point to an array of size 2 (a dynamically allocated C-style array), representing the two end points of the line.
A VerticalLine object has both x coordinates the same.
A HorizontalLine object has both y coordinates the same.
A Triangle object is represented by 3 points.
A Parallelogram object has 4 coordinates, represented by arrays of size 4.
The sides of this shape are parallel to each other, and at least two of them should be perpendicular to one of x and y axis. We call this the parallelogram property. This gives further structure and the constructor might take only 3 parameters, since the 4th point is determined by the other 3 points, as will be explained below.
A Rectangle is a special parallelogram with all the sides perpendicular to the x or y axes.
also it needs to have a constructor and a destructor for each class. And also a toString()function for each class so that, for instance for a Triangle object tri with color red
cout << tri.toString() << endl;
prints out the object as follows:
This is a red triangle with coordinates
1: 0.34 0.45
2: 0.89 0.45
3: 0.78 0.09
For writing the constructors, give the following data appropriately in the parameter list.
A line is determined by 4 coordinates (2 end points).
A vertical line and a horizontal line is determined by 2 coordinates (1 end point) and a length.
A triangle is determined by 6 coordinates (3 end points).
A parallelogram is also determined by 6 coordinates (3 points determine the parallelogram due to its definition).
In fact, it is possible that the given 3 points do not determine a parallelogram. So, if the parameters do not satisfy the parallelogram property, return nullptr.
A rectangle is determined by 4 coordinates (2 end points of one of the diagonal of the rectangle).
The class Shape also has a pure virtual function named area, which returns the area of a descendant shape. this should be implemented in all classes.
Finally, a main function (in main.cpp), which creates 10,000 random shapes, and stores all of them in a vector of Shape pointers. All the coordinates should be in the range [0..1]. The type of the object should also be randomly determined. and also randomly assign colors to the objects. a color set of 4-5 colors should be enough.
Source: Windows Questions C++