C++ Declare a class Box. A box as you all know is something a cubical container. It has following attributes •Length •Width •Height In addition to these, a box can be made of different materials e.g. wood, card, metal etc. Further, more a box can have different colors. Declare them also as member variables of class. Provide a default Constructor, a parameterized Constructor for the Box that takes all necessary values as arguments with the material as optional (if it is omitted the Box is considered to be made of Card – default value for the material. Provide getters for all attributes and setters for each too except for the material (material of box cannot be changed after when it has been created!!!). Provide a function getVolume() that calculates and returns the value of the volume of the Box. Also provide another function getSurfaceArea(),that calculates and returns the surface area of a Box. Provide a print function that Prints the following about the Box Length: Width: Height: Material: Color: Volume: Surface Area: Inside main, allocate a block of memory for 5 objects (using array). Read the necessary values from the user to populate array. Call functions Print() and Volume to display the data of boxes you just have saved in array. Read the index and the new height from the user, ask the user to provide index of the box to change its height by creating a function update(Box b[], int size, int index, double height). Update the height of the Box present on the index provided by user, save the updated height right there, and print it again.
C++ Declare a class Box. A box as you all know is something a cubical container. It
has following attributes •Length
•Width
•Height
In addition to these, a box can be made of different materials e.g. wood, card, metal etc. Further, more a box can have different colors. Declare
them also as member variables of class. Provide a default Constructor, a parameterized Constructor for the Box
that takes all necessary values as arguments with the material as optional
(if it is omitted the Box is considered to be made of Card – default value
for the material. Provide getters for all attributes and setters for each too except for the
material (material of box cannot be changed after when it has been
created!!!). Provide a function getVolume() that calculates and returns the value of
the volume of the Box. Also provide another function getSurfaceArea(),that calculates and
returns the surface area of a Box. Provide a print function that Prints the following about the Box
Length:
Width:
Height:
Material:
Color:
Volume:
Surface Area:
Inside main, allocate a block of memory for 5 objects (using array). Read the necessary values from the user to populate array. Call functions Print() and Volume to display the data of boxes you just
have saved in array. Read the index and the new height from the user, ask the user to
provide index of the box to change its height by creating a function
update(Box b[], int size, int index, double height). Update the height of
the Box present on the index provided by user, save the updated height
right there, and print it again.
Step by step
Solved in 6 steps with 7 images