Re-write the derived classes from given code to override a pure virtual function in the base class to compute the area of the shapes. Re-write the application from before to create and store input shapes as base class pointers. In addition, modify the application to allow the user to create and store any number of shapes (use an STL class to store the base class pointers, i.e. vector<Shape *> shapes). After the user has finished creating shapes, compute and print the area for all the shapes in a single loop using only the base class pointers with dynamic binding.
VirtualPrint.C (program demonstrating how you can use dynamic binding to output parent and child information using base class pointers)
using namespace std;
// Parent class
// Overloaded output stream operator
friend ostream &operator<<( ostream &…
View original post 85 mots de plus