Shape class and reflect and translate point

Hello
I was asked to write an abstract shape class with pure virtual functions and then implement derived class ie rectangle, circle and square . But I am also asked to translate and reflect point and my point class should be in Shape class.
I am able to implement Shape class , and point class and derived clases but I dont know how should I implement Point center in my Shape class and in derive class and how to implement translate and reflect functions. (Euclidean space) Please help me .

Looking for forward for positive response.
Thankyou
This is the output I am supposed to get but I am getting errors


int main()
{
int size = 5;

Shape** shapes = new Shape*[size];

Point* centre = new Point(5,5);
Rectangle* rectangle1 = new Rectangle(*centre, 4, 3);
shapes[0] = rectangle1;

shapes[1] = new Rectangle (*new Point(10, -10), 4, 4);

Rectangle* rectangle3 = new Square(*new Point(-8.5,-10), 2.5);
shapes[2] = rectangle3;

Square* square2 = new Square (*new Point(-1,-1), 1.5);
shapes[3] = square2;

Circle* circle = new Circle(*new Point(100,100), 25.4);
shapes[4] = circle;

cout << "\n11111111111111111111111111\n";

for (int i = 0; i < size; ++i)
shapes[i] -> display();

cout << "\n22222222222222222222222222\n";

cout << "\nthe area of the first rectangle is: ";
cout << rectangle1->area() << endl;

cout << "It is a square, the area is: ";
Square* square = dynamic_cast<Square*> (rectangle3);
cout << square->area() << endl;

cout << "the perimeter of the circle is: ";
cout << circle->perimeter() << endl;

cout << "\n33333333333333333333333333\n";

cout << "\nThe four vertices of the first rectangle are: (clockwise from top-left)\n";
rectangle1->printFourVertices();

cout << "\nThe four vertices of the third rectangle are:\n";
rectangle3->printFourVertices();

cout << "\n44444444444444444444444444\n";

rectangle1->reflectX();

shapes[2] -> translate(1.5, 3);

shapes[4] -> translate(-100,-100);

cout << "\nAfter reflection and translation, here are the moved shapes:\n" ;
for (int i = 0; i < size; ++i)
shapes[i] -> display();

cout << "\n55555555555555555555555555\n";

cout << "\nNow, the four vertices of the first rectangle are:\n";
rectangle1->printFourVertices();

cout << "\nNow, the four vertices of the third rectangle are:\n";
rectangle3->printFourVertices();

cout << "\n66666666666666666666666666\n\n";

for (int i = 0; i < size; ++i)
cout << shapes[i] -> area() << endl;

// From the following statements, understand how setLength() and setWidth()
// work for rectangles and squares.

cout << "\n777777777777777777777777777\n";

shapes[1] -> display();
dynamic_cast<Rectangle*> (shapes[1]) -> setLength(8.2);
cout << "\nAfter setLength(8.2), the rectangle is: ";
shapes[1] -> display();
dynamic_cast<Rectangle*> (shapes[1]) -> setWidth(5);
cout << "\nAfter setWidth(5), the rectangle is: ";
shapes[1] -> display();

square2 -> display();
square2 -> setLength(8.2);
cout << "\nAfter setLength(8.2), the rectangle is: ";
square2 -> display();
square2 -> setWidth(5);
cout << "\nAfter setWidth(5), the rectangle is: ";
square2 -> display();

system("pause");
return 0;
}


/*
11111111111111111111111111

Rectangle:
Centre: (5, 5)
Length: 4
Width: 3

Rectangle:
Centre: (10, -10)
Length: 4
Width: 4

Square:
Centre: (-8.5, -10)
Side Length: 2.5

Square:
Centre: (-1, -1)
Side Length: 1.5

Circle:
Centre: (100, 100)
Radius: 25.4

22222222222222222222222222

the area of the first rectangle is: 12
It is a square, the area is: 6.25
the perimeter of the circle is: 159.512

33333333333333333333333333

The four vertices of the first rectangle are: (clockwise from top-left)
(3, 6.5)
(7, 6.5)
(7, 3.5)
(3, 3.5)

The four vertices of the third rectangle are:
(-9.75, -8.75)
(-7.25, -8.75)
(-7.25, -11.25)
(-9.75, -11.25)

44444444444444444444444444

After reflection and translation, here are the moved shapes:

Rectangle:
Centre: (5, -5)
Length: 4
Width: 3

Rectangle:
Centre: (10, -10)
Length: 4
Width: 4

Square:
Centre: (-7, -7)
Side Length: 2.5

Square:
Centre: (-1, -1)
Side Length: 1.5

Circle:
Centre: (0, 0)
Radius: 25.4

55555555555555555555555555

Now, the four vertices of the first rectangle are:
(3, -3.5)
(7, -3.5)
(7, -6.5)
(3, -6.5)

Now, the four vertices of the third rectangle are:
(-8.25, -5.75)
(-5.75, -5.75)
(-5.75, -8.25)
(-8.25, -8.25)

66666666666666666666666666

12
16
6.25
2.25
2025.8

777777777777777777777777777

Rectangle:
Centre: (10, -10)
Length: 4
Width: 4

After setLength(8.2), the rectangle is:
Rectangle:
Centre: (10, -10)
Length: 8.2
Width: 4

After setWidth(5), the rectangle is:
Rectangle:
Centre: (10, -10)
Length: 8.2
Width: 5

Square:
Centre: (-1, -1)
Side Length: 1.5

After setLength(8.2), the rectangle is:
Square:
Centre: (-1, -1)
Side Length: 8.2

After setWidth(5), the rectangle is:
Square:
Centre: (-1, -1)
Side Length: 5
*/
Please use code tags. Edit your post, highlight the code and click the <> botton to the right of the edit window.

Please post code that will compile. The code you posted doesn't declare the Point, Shape or Rectangle classes.
Topic archived. No new replies allowed.