Polymorphic Graphics System Assignment Answers
Your question:
Assignment Help Answers with Step-by-Step Explanation:
#include <cmath>
using namespace std;
}
void erase() const {
erase();
draw();
void draw() const override {
cout << "Drawing a circle." << endl;
};
class Triangle : public Figure {
void erase() const override {
cout << "Erasing a triangle." << endl;
fig->draw();
}
Triangle tri = new Triangle;
fig = tri;
// Testing with Circle
Circle cir = new Circle;
myDraw(cir);
return 0;
b. With Virtual Functions:
In this part, the `erase` and `draw` functions are declared as virtual in the `Figure` class. This allows dynamic binding, and the correct version of the function is called based on the actual type of the object. The output will show that the derived class versions of `erase` and `draw` are called.