Question: c++ program question: Shape Container - Interface Class, Inheritance, Polymorphism(Dynamic Binding) and Exception handling Description of program: You will use the following Shape interface to

c++ program question: Shape Container - Interface Class, Inheritance, Polymorphism(Dynamic Binding) and Exception handling

Description of program:

You will use the following Shape interface to implement a Circle, Triangle, and Rectangle classes. Among the method(s) required by the interface...

  • Circles have a radius
  • Triangle have a base and height
  • Rectangle have a length and a width
  • You will be passed a file name contain shape data from the command line. Some kind of Executive class should read the file and use a ShapeContainer (see below) to store pointers to various shapes, using the specifications for each shape given in the file. The file also contains commands to print the area of a given shape and to exit the program. When a print command is issued, the information about the shape and it's area should be printed.

c++ program question: Shape Container - Interface Class, Inheritance, Polymorphism(Dynamic Binding) and

Exception handling Description of program: You will use the following Shape interface to implement a Circle, Triangle, and Rectangle classes. Among the method(s) requiredby the interface... Circles have a radius Triangle have a base and

Shape Interface You may NOT add any public methods to this class #include class Shape public: virtual double area () const = 0; virtual std::string shapeName() const = 0; virtual -Shape() {} ShapeContainer You may NOT add any public methods to this class #include "Shape.h" #include class ShapeContainer public: ShapeContainer(int size); //initialize pointers in m_arrayofShapes to nullptr -ShapeContainer(); double area (int index) const; //throws a std::runtime_error if index is invalid, meaning out of range OR index has nullptr std::string shapeName (index) const; //throws a std::runtime error if index is invalid, meaning out of range OR index has nullptr void add (Shape* shapePtr, int index); //throws a std:: runtime error if index is invalid OR if shapePtr is nullptr void remove(int index); //throws a std::runtime_error if the index is invalid OR there is no object to delete private: Shape** marrayofShapes; int m size; File Format The first item in the file will be the size of the shape container, which cannot change despite how many adds are in the file. Following that will be lines containing one of the three following commands in any order: 1. ADD is the index in the container to put the shape will be CIR, TRI, or REC for Circle, Triangle, and Rectangle respectively will the be radius, base and height, or length and width, of a Circle, Triangle, or Rectangle respectively 2. DELETE Deletes the shape at a given index The index may be out of range or not yet set, in which case you must catch and handle the exception to gracefully recover and continue on 3. PRINT Prints the name and area of the shape at a given index, as shown below The index may be out of range or not yet set, in which case you must catch and handle the exception to gracefully recover and continue on 4. EXIT Ends the program ADD O CIR 5.5 ADD 1 TRI 2.5 6.6 PRINT O ADD 2 REC 10.5 20.25 PRINT 99 PRINT 2 EXIT Sample run: Shape at index 0: Circle area = 95.0331 Shape at index 99: Does not exist Shape at index 2: Rectangle area = 212.625 Exiting... Shape Interface You may NOT add any public methods to this class #include class Shape public: virtual double area () const = 0; virtual std::string shapeName() const = 0; virtual -Shape() {} ShapeContainer You may NOT add any public methods to this class #include "Shape.h" #include class ShapeContainer public: ShapeContainer(int size); //initialize pointers in m_arrayofShapes to nullptr -ShapeContainer(); double area (int index) const; //throws a std::runtime_error if index is invalid, meaning out of range OR index has nullptr std::string shapeName (index) const; //throws a std::runtime error if index is invalid, meaning out of range OR index has nullptr void add (Shape* shapePtr, int index); //throws a std:: runtime error if index is invalid OR if shapePtr is nullptr void remove(int index); //throws a std::runtime_error if the index is invalid OR there is no object to delete private: Shape** marrayofShapes; int m size; File Format The first item in the file will be the size of the shape container, which cannot change despite how many adds are in the file. Following that will be lines containing one of the three following commands in any order: 1. ADD is the index in the container to put the shape will be CIR, TRI, or REC for Circle, Triangle, and Rectangle respectively will the be radius, base and height, or length and width, of a Circle, Triangle, or Rectangle respectively 2. DELETE Deletes the shape at a given index The index may be out of range or not yet set, in which case you must catch and handle the exception to gracefully recover and continue on 3. PRINT Prints the name and area of the shape at a given index, as shown below The index may be out of range or not yet set, in which case you must catch and handle the exception to gracefully recover and continue on 4. EXIT Ends the program ADD O CIR 5.5 ADD 1 TRI 2.5 6.6 PRINT O ADD 2 REC 10.5 20.25 PRINT 99 PRINT 2 EXIT Sample run: Shape at index 0: Circle area = 95.0331 Shape at index 99: Does not exist Shape at index 2: Rectangle area = 212.625 Exiting

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!