Question: For lab 6 , you need to: Create a drawing application so the user can add different kinds of shapes to a canvas. All these
For lab you need to:
Create a drawing application so the user can add different kinds of shapes to a canvas. All these shapes have a few things in common, like background color, border and so on
As your exercise,
Create a new class. Shape and let two classes: Rectangle and Circle derive from the Shape class.
For each class you should implement the member functions in the implementation file.
Add a function to base class. The function is draw Let two derived classes override this function.
Back to the main file, create a function called showShape Pass a Shape object as the argument and draw shape for implementation.
Use Polymorphic Collection I am not sure what this is Create a vector of Shape, put a rectangle and a circle into it loop over the vector, and draw a rectangle and a circle on the console. Use late or dynamic binding which I also need help understanding
Rewrite this code using unique pointer instead.
Here are the UMLs.
Shape UML:
background: string
getBackground
setBackground
void draw
Rectangle UML:
width: int
heigth: int
Rectangle
Rectangleint width, int height
void draw
int getArea
Circle UML:
radius: float
Circle
Circlefloat radius
float getArea
void draw
I want to try to get the following code to work.
vector uniqueShapes;
Since this is a vector of unique Shape pointers, it cannot use rectangle or circle pointers.
I was accidentally trying to downcast a shape to a rectangle and a circle which is illegal
uniqueptr rectanglePtr makeunique ;
uniqueptr circlePtr makeunique ;
uniqueShapes.pushbackrectanglePtr;
uniqueShapes.pushbackcirclePtr;
The four lines above are what is causing the problem. It says something about trying to access a deleted function.
uniqueShapes.pushbackmakeunique ;
uniqueShapes.pushbackmakeunique ;
for int i ; i uniqueShapes.size; i
showShapeshapesati;
What am I doing wrong?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
