Question: In this exercise, you will work with 3 classes: Shape, Triangle and Rectangle. The first class is the class Shape. The Shape class has two

In this exercise, you will work with 3 classes: Shape, Triangle and Rectangle.
The first class is the class Shape. The Shape class has two float type properties: center_x and center_y. The Shape class also has the following methods:
a constructor Shape(), that will set center_x and center_y to zero.
set/get functions for the two attributes
1) You need to implement two additional functions for Shape:
setCenter(float x, float y), that will set the new center and print:
Figure moved to [,]
draw(), that will print:
Drawing Figure at [,]
2) You will have to implement another class, called Triangle, which inherits from the Shape class. The Triangle class has one int attribute: side. The Triangle class has the following methods:
a constructor that will receive one int parameters (side)
set/get for its attribute
setCenter(float x, float y), that will set the new center and print:
Triangle moved to [,]
draw(), that will print the following message and draw the triangle depending on the size of the side:
Drawing Triangle at [,]
*
**
***
//example of side =3
3) You will have to implement another class, called Rectangle, which inherits from the Shape class. The Rectangle class has two int attributes: base and height. The Rectangle class has the following methods:
a constructor that will receive two int parameters (base, height)
set/get for its attributes
setCenter(float x, float y), that will set the new center and print:
Rectangle moved to [,]
draw(), that will print the following message and draw the triangle depending on the size of the base and height:
Drawing Rectangle at [,]
****
****
****
//example of base =4 and height =3
Use polymorphism to make sure each object is drawn correctly!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!