Volume of a box with classes

I've been working on this program to learn about using classes. In the requirements it says this;

-create a get and set for height, width, length.
-A default parameterized constructor = 1
-A method to resize the box
-A method to get the volume of the box
-A method to convert the object to a string

My Questions:
The 3 parts I am confused by are the default parameter constructor, the re-size the box and the method to convert to string. I also am unsure of what to use the getLength/Width/Height for.

This is the main file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "box_class.h"
#include <iostream>
using namespace std;

     
int main()
{
double length;
    double width;
    double height;
    double volume;
    Box box;
    
cout << "Please Enter a Length for your box: " ;
cin >> length;
box.setLength(length);
cout << "Please Enter a Width for your box: " ;
cin >> width;
box.setWidth(width);
cout << "Please Enter a Height for your box: " ;
cin >> height;
box.setHeight(height);
//cout << "\n\n" << box.getParameters();
volume = box.getVolume();
cout << "\n\nThe Volume of your box is: " << volume;
box.getParameters();
return 0;
}


This is the class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>

using namespace std;

class Box
{
    public:
double length;//length of the box
double height;//height of the box
double width;//with of the box
//Declare Member functions
double getVolume(void);
string getParameters(void);
  void setLength(double leng);
void setWidth(double wid);
void setHeight(double hei);
double getLength(double length );
double getWidth(double width );
double getHeight(double height );
};//end class 

//member function definitions

double Box::getVolume(void)//get volume will cal and output the volume when called
{
return length * width * height;
}
void Box::setLength(double leng)
{
length = leng;
}
double Box::getLength(double length)
{
return length;
}
void Box::setWidth(double wid)
{
width = wid;
}
double Box::getWidth(double width)
{
return width;
}
void Box::setHeight(double hei)
{
height = hei;
}
double Box::getHeight(double height)
{
return height;
}
string Box::getParameters(void)
{
cout << "\nLength :" << getLength(length) << endl <<
"Width :" << getWidth(width) << endl <<
"Height :" << getHeight(height) << endl; 
}
Last edited on
Topic archived. No new replies allowed.