Question
Define a class hierarchy formed of a parent class Furniture and two child classes Table and Bed. Declare and define each of the three classes
Define a class hierarchy formed of a parent class Furniture and two child classes Table and Bed. Declare and define each of the three classes with a header (.h) file and a corresponding source (.cpp) file. The parent class should contain the following members: Three private floating-point numbers indicating the dimensions of the piece of furniture (width, height, and depth). A private string containing a unique name. A public constructor that takes the name of the piece of furniture as an argument. A public function ReadDimensions, used to read the values of the width, height, and depth from the keyboard. The function should show an error message if any of the entered values is less than 0. A public virtual function Print(), with no arguments and a void return value. This function should print the dimensions and name. The Table child class should have the following members: A private string indicating the type of wood used for the table, with two possible valid values: Pine and Oak. A public constructor that takes the unique name of the table as the first argument, passed directly to the constructor of the parent class, and the string corresponding to the wood type as the second argument. The constructor should print an error message if an invalid size string is passed. A public function Print() that overrides the function with the same name in the parent class. This function prints common furniture information by invoking the parent class function, and continues printing information specific to a table (the wood type). The Bed child class should have the following members: A private string field specifying the size of the bed, with four possible valid values: Twin, Full, Queen, and King. A public constructor that takes the unique name of the bed as the first argument, passed directly to the constructor of the parent class, and the string corresponding to the bed size as the second argument. The constructor should print an error message if an invalid size string is passed. A public function Print() that overrides the function with the same name in the parent class. This function prints common furniture information by invoking the parent class function, and continues printing information specific to a bed (the size string). In addition to the header (.h) files and a corresponding source (.cpp) files for each of the classes, provide an additional file main.cpp, which will include the main program. The main program should instantiate one object of type Table and another object of type Bed. Its properties should be populated based on values read from the user, and then printed with invocations to functions Print(). Provide a Makefile that compiles the programs. Create a zipped directory assign2 for your programs.
This is an example of the execution of the program Creating table.. . Enter name: MyTable Enter wood type (Pine, Oak): Pine Enter width: 1 Enter height: 2 Enter depth: 3 Creating bed... Enter name: MyBed Enter size (Twin, Full, Queen, King): Queen Enter width: 5 Enter height: 6 Enter depth: 7 Printing objects .. . MyTable: width = 1, height 2, depth 3 Pine wood MyBed: width 5, height 6, depth 7 Queen sizeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started