Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++ Specific Requirements For this In Class Exercise you will create a cus

ID: 3865709 • Letter: U

Question

Using C++

Specific Requirements

For this In Class Exercise you will create a custom class called Box which will represent a cardboard box in code.

For the purposes of this assignment, a Box is defined by the following three attributes:

1. Height 2. Length 3. Width

These attributes should have a data type of double and an access modifier of private, ensuring that only members of the Box class can access and/or modify their values.

The Box class must also specify the following Behaviours:

A default Constructor function that utilizes an initialization list

A parameterized Constructor that has parameters that match the attributes listed above

Constant Accessor functions for each of the attributes listed above

Mutator functions for each of the attributes listed above (no validation required for this

assignment)

An additional FindVolume() function that will calculate and return the volume of the Box

The FindVolume() function should accept three double parameters: a height, length, and a width. For the purposes of this assignment, all Boxes are assumed to be rectangular. Therefore, the Volume calculation should be height*length*width.

Be sure

• • • • •

to label the following sections in your code with block comments:

Class Declaration

Section/Class Implementation

Section Constructors
Accessors
Mutators

Additional Functionality

Explanation / Answer

#include <iostream>

using namespace std;

class Box

{

private: // access modifier

double length; // Length of a box

double breadth; // Breadth of a box

double height; // Height of a box

  

double FindVolume(double l, double b, double h) // Function to calculate volume of the box

{

length =l;

breadth =b;

height =h;

double volume = length*breadth*height;

cout<<"Volume of the box is:"<<volume;

return volume;

}

};

int main()

{

Box Box1; // Declare Box1 of type Box

Box Box2; // Declare Box2 of type Box

// volume of the box 1

Box1.FindVolume(10.0,20.0,30.0);

// volume of the box 2

Box2.FindVolume(10.0,11.0,12.0);

return 0;

}

When the above code is compiled and executed, it produces the following result:

Volume of Box1 : 6000

Volume of Box2 : 1320

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote