Question: Hi need help with c++ program using inheritance, interface, polymorphism. Need to use a shape interface to implement circle, triangle and rectangle classes. The methods
Hi need help with c++ program using inheritance, interface, polymorphism.
Need to use a shape interface to implement circle, triangle and rectangle classes. The methods that are needed for the interface are that circles have radius, triangles have a base and height, and rectangle have a length and a width. It will be passed a file containing shape data from the command line. An 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.
The format of the file looks like this:
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:
- 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
- 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 recover and continue on
- 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 recover and continue on
- EXIT
- Ends the program
sample file:
5 ADD 0 CIR 5.5 ADD 1 TRI 2.5 6.6 PRINT 0 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
