Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use C++ to write the following code. md=view&content_id-_7881 31-1&course_id--20819_1 Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files.
Use C++ to write the following code.
md=view&content_id-_7881 31-1&course_id--20819_1 Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard - files. > Course Content > Lectures >Demo Program 2: class Rectangle in three In this lab, we will use class inheritance to write a new class called Box. The class Box inherits class Rectangle with public inheritance. The class Box has one extra data member: private: int height; Write the following seven public functions for class Box: 1) Override the print function to output the length, width, and height of a box. 2) Write a setHeight function to set the height according to the parameter. The valid value for the height should be non-negative. Use 0 for an invalid value. 3) Write a getHeight function to return the height. 4) Write a default constructor to initialize length, widt h, and height to 0. 5) Write an overloaded constructor to initialize length, width, and height according to the parameters. 6) Write a function getVolume to calculate and return the volume of a Box object. 7) Write a function equals to check if two Box objects have the same dimension. Return true if they are equal in length, width, and height:; otherwise, return false. Separate the Box class definition and implementation in Box, h and Box.epp. In the function main, write statements to declare objects of class Box and test all the member functions of your derived class
Step 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