Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago