Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a class hierarchy formed of a parent class Furniture and two child classes Table and Bed 1. (100 points) Define a class hierarchy formed

Define a class hierarchy formed of a parent class Furniture and two child classes Table and Bedimage text in transcribed

image text in transcribed

1. (100 points) 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 ReadDimentions, 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 wood type 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 bed size 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 bed size). 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: My Table 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 size

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

1- Solve the following Equation: I) x22cy22c=0

Answered: 1 week ago