Purchase Solution

Constructor, Object and Accessor Functions in C++

Not what you're looking for?

Ask Custom Question

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
{
Private:
Int h, w, d; // height width depth

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

Sbox::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)
{
this->h=h;
this->w=w;
this->d=d;
}
else {
this->h=0;
this->w=0;
this->d=0;
}
}

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

Purchase this Solution

Solution Summary

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

Solution Preview

assess function is as follows:

public:
Sbox(int h=0, int w=0, int d=0)
{
height = h;
width = w;
depth = d;
}
...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.