Question
I need help solving this basic C++ question. I need help fixing my code. Question: Design a class called a box that represents a box.
I need help solving this basic C++ question. I need help fixing my code.
Question:
Design a class called a box that represents a box. Box classes have variables such as the length of the box, width, and height. 1. Member variables shall be dedicated members. 2. Define the creator of the Box Class. The creator may receive all of the data and may not receive any. 3. Add accessor and creator 4. Add an empty function, which indicates whether the box is empty or not. It also adds the getVolume () member function to compute the volume. Include a print function that outputs the current state of the Box Object to the console. 5. Create multiple BOX objects from the main () and invoke the accessor and set up.
and this is the code I made so far... (It's not running yet)
=====================================================
#include
using namespace std;
class Box
{
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;
}
int 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;
}
private:
int length;
int width;
int height;
};
int main()
{
Box a, b;
a.setter(0, 0, 0);
cout << "Box #1"< a.print(a.getLength(), a.getWidth(), a.getHeight()); cout << "Volume: " << b.setter(3, 2, 4); cout << "Box #2" << endl; b.print(b.getLength(), b.getWidth(), b.getHeight()); cout <<"Volume: " << } ===================== Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started