Answered step by step
Verified Expert Solution
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 classes: Shape, Triangle and Rectangle.
The first class is the class Shape. The Shape class has two float type properties: centerx and centery The Shape class also has the following methods:
a constructor Shape that will set centerx and centery to zero.
setget functions for the two attributes
You need to implement two additional functions for Shape:
setCenterfloat x float y that will set the new center and print:
Figure moved to
draw that will print:
Drawing Figure at
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
setget for its attribute
setCenterfloat 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
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
setget for its attributes
setCenterfloat 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 and height
Use polymorphism to make sure each object is drawn correctly!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started