subject

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 radiusTriangle have a base and heightRectangle have a length and a widthYou 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. Shape InterfaceYou 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() {}};ShapeContainerYou 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** m_arrayOfShapes; int m_size;}File FormatThe 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:ADDis the index in the container to put the shapewill be CIR, TRI, or REC for Circle, Triangle, and Rectangle respectivelywill the be radius, base and height, or length and width, of a Circle, Triangle, or Rectangle the shape at a given indexThe 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 onPRINTPrints the name and area of the shape at a given index, as shown belowThe 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 onEXITEnds the program5ADD 0 CIR 5.5ADD 1 TRI 2.5 6.6PRINT 0ADD 2 REC 10.5 20.25PRINT 99PRINT 2 EXITSample run:Shape at index 0: Circle area = 95.0331Shape at index 99: Does not existShape at index 2: Rectangle area = 212.625Exiting...

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:00, savjk74
Which of the following “invisible” marks represents an inserted tab?
Answers: 1
image
Computers and Technology, 23.06.2019 18:00, yedida
File account. java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
image
Computers and Technology, 24.06.2019 11:00, soystersoce
Under the home tab, where can a user find options to change the bullet style of an outline? in the slides group in the font group in the paragraph group in the drawing group
Answers: 1
image
Computers and Technology, 24.06.2019 15:30, lizziesuks
What is the function of compilers and interpreters? how does a compiler differ from an interpreter?
Answers: 2
You know the right answer?
You will use the following Shape interface to implement a Circle, Triangle, and Rectangle classes. A...

Questions in other subjects:

Konu
Computers and Technology, 30.08.2019 02:50