Explore BrainMass

Explore BrainMass

    Constructor, Object and Accessor Functions in C++

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Given below is a c++ class called Sbox used in shipping. We can declare an object of type Sbox to hold the dimensions of a shipping box, a height, width and depth. We define a height (h), width (w) and depth (d) for the three sides of a box. For shipping, it is required the height to be no greater than 45 inches. The width cannot be anymore than 75% of the box's height. The depth must be less than the height.

    Class Sbox
    Int h, w, d; // height width depth

    10. Write a constructor function that
    A) defines an object with default value of 0s
    Sbox ()

    { h=0; w=0; d=0;}

    b) define an object with the initial values for h, w, and d. check for the constraints listed earlier
    Sbox::Sbox (int h, int w, int d)
    if (h<45 && (w<h* 0.75) && d<h)
    else {

    11. Write accessor funtions for height, width, and depth.
    Also, what exactly is an accessor function?

    © BrainMass Inc. brainmass.com March 5, 2021, 1:01 am ad1c9bdddf

    Solution Preview

    assess function is as follows:

    Sbox(int h=0, int w=0, int d=0)
    height = h;
    width = w;
    depth = d;

    Solution Summary

    The solution gives complete C++ code of accessor funtions for height, width, and depth.