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

I have one question regarding the bool function ================================

ID: 3701189 • Letter: I

Question

I have one question regarding the bool function

=================================

#include <iostream>

using namespace std;

class Box{

private:

int length;

int width;

int height;

public:

Box() : length(0), width(0), height(0) {}

Box(int l, int w, int h): length(l), width(w), height(h) {}

int getLength(){

return length;

}

int getWidth(){

return width;

}

int getHeight(){

return height;

}

void setter(int l, int w, int h){

length = l;

width = w;

height = h;

}

bool empty(){

if (length == 0 || width == 0 || height == 0)

return true;

return false;

}

int getVolume(int length, int width, int height){

int volume = length * width * height;

return volume;

}

void print(int length, int width, int height){

cout << "Length " << length << endl;

cout << "Width: " << width << endl;

cout << "Length: " << length << endl;

}

};

int main(){

Box a, b;

a.setter(0, 0, 0);

cout << "Box #1"<<endl;

a.print(a.getLength(), a.getWidth(), a.getHeight());

cout << "Volume: "<<a.getVolume(a.getLength(), a.getWidth(), a.getHeight())<<endl;

b.setter(3, 2, 4);

cout << "Box #2" << endl;

b.print(b.getLength(), b.getWidth(), b.getHeight());

cout <<"Volume: "<<a.getVolume(a.getLength(), a.getWidth(), a.getHeight())<<endl;

}

==================================

I have problem understanding this bool function of my code.

bool empty(){

if (length == 0 || width == 0 || height == 0)

return true;

return false;

}

what is return true; next return false;

I'm a begginer of C++, can you explain easily?

Thanks,

Explanation / Answer

here i have expalined the working of the particuler section of the code as asked..

===============================================================

//bool is a data type defined in <cstdbool> header file..

//this is th defintion for bool fuction..since the function return type is bool it returns a boll value(i.e true or false) to the calling function in main class.

bool empty()

{

//if length or width or height is zero it returns true

if (length == 0 || width == 0 || height == 0)

return true;

//else return false to calling function

return false;

}


===============================================================

KIndly Check and Verify Thanks..!!!