### Enter X Y and Height

Hello,

So I am creating 5 objects of type Box, each with an x, y, and z component. I then attempt to calculate the Volume of each box and print it out for each box, taking vertices points in for each box, then getting the width, height and depth; I think my problem is in my get functions. Here is my output, I appreciate your time:

 ``` Enter X, Y, & Height: 5 4 3 Enter X, Y, & Height: 5 1 1 Enter X, Y, & Height: 0 5 5 Enter X, Y, & Height: 5 5 5 Enter X, Y, & Height: 3 1 1 Box# Box Type Volume(cu/units) 1 Rectangular 0022F738 2 Rectangular 0022F738 3 Rectangular 0022F738 4 Rectangular 0022F738 5 Rectangular 0022F738 Enter X, Y, & Height: ```
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296`` ``````#include #include #include #include using std::cout; using std::endl; using std::string; using std::cin; using std::fixed; using std::left; using std::right; using std::setw; class Box { private: int Boxes[5]; int Width[5]; int Depth[5]; int Height[5]; int Volume[5]; int minX; int maxX; int maxY; int minY; string type; public: int x[5]; int y[5]; int z[5]; Box::Box() { int Boxes[5]; Boxes[0]=0; Boxes[1]=1; Boxes[2]=2; Boxes[3]=3; Boxes[4]=4; } Box(int x[5], int y[5], int z[5]) { for (int i = 0; i<5;i++) { Width[5] = x[i]; Depth[5] = y[i]; Height[5] = z[i]; Volume[5] = Volume[i]; } } Box(int w, int d, int h, string t, int v) { Width[5] = w; Depth[5] = d; Height[5] = h; type = t; Volume[5] = v; } Box(int w, int d, int h, string t, int v, int mix, int max, int miy, int may) { Width[5] = w; Depth[5] = d; Height[5] = h; type = t; Volume[5] = v; maxX = max; minX = mix; maxY = may; minY = miy; } void Box::setData() { for (int i=0; i<5; i++) { cout << "\n\n\tEnter X, Y, & Height: " << endl; cin >> x[i] >> y[i] >> z[i]; Height[i] = z[i]; Width[i] = x[i]; Depth[i] = y[i]; Volume[i] = x[i] * y[i] * z[i]; } } int getDepth(); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); string getType(); int getVolume(); int getWidth(); int getHeight(); void printData(); }; /* Box::Box(int w, int d) { width = w; depth = d; } */ void Box::printData() { int Boxnumbers[5]; cout << fixed; cout.precision(2); cout << left << setw(25) << "Box#" << left << setw(25) << "Box Type" << right << setw(25) << "Volume(cu/units)" << endl; { for (int i=0;i<5;i++) { for (int j=0;j<4;j++) { Boxnumbers[i] = i+1; } cout << left << setw(25) << Boxnumbers[i] << left << setw(25) << type << right << setw(25) << Volume << endl; } } } int Box::getDepth() { for (int i=0; i<5; i++) { return Depth[i]; } } /* int Box::getMaxX(int earray[24][24]) // Highest Value of X from the 4 X and Y pairs { for (int i=0;i<24;i++) { for (int j = 0; j<23;j++) { temp = maxX[j]; maxX[j]=maxX[j+1]; maxX[j+1] = temp; } } return maxX; } */ /* int Box::getMaxY(int x[20], int y[20]) // Highest Value of Y from the 4 X and Y pairs { for (int x=0;x<24;x++) { for (int y = 0; y<23;y++) { cout<<"insert the value "<> earray[x][y]; } int maxY; int minY; maxY = earray[24][0]; minY = earray[0][24]; int e = 0; while (e<24) { if (earray[24][0]>maxY) { maxY = earray[e][24]; } else if (earray[e][24]> earray[x][y]; } int minX; int maxX; int e = 0; maxX = earray[e][24]; minX = earray[0][24]; while (e<24) { if (earray[e][24]maxX) { maxX = earray[e][24]; } e++; } } return minX; } int Box::getMinY(int x[20], int y[20]) //Lowest Value of Y the 4 X and Y pairs { for (int i=0;i<100;i++) { for (int j=0; j<150; j++) { while (i == i+1) { if (j<=j+1) { minY = j; } else { minY = j+1; } } } } return minY; } */ string Box::getType() { for (int i=0; i<5; i++) { if (Width[i] == Depth[i] && Depth[i] == Height[i]) { type = "Square"; } else { type = "Rectangular"; } } return type; } int Box::getVolume() { for (int i=0; i<5; i++) { return Volume[i]; } } int Box::getWidth() { for (int i=0; i<5; i++) { return Width[i]; } } int Box::getHeight() { for (int i=0; i<5; i++) { return Height[i]; } } int main() { Box Boxes[5]; Box *xpointer; xpointer = &Boxes[0]; for (int i=0; i<5;i++) { Boxes[i].setData(); Boxes[i].getWidth(); Boxes[i].getDepth(); Boxes[i].getHeight(); Boxes[i].getType(); Boxes[i].getVolume(); Boxes[i].printData(); } //declare an array of 5 objects of type Box //call a function to load the user input into each object //call a function to print results for part #1 and #2 //call a function to print results for part #3 //print the results for part #4 cout << "\n\n\t" <

Cleaned it up a bit but still getting nonsense results for Volume.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169`` ``````//----------------------------------------------------------------------------// // Name: // // Student ID: // // Assignment: #2 // //----------------------------------------------------------------------------// #include #include #include #include using std::cout; using std::endl; using std::string; using std::cin; using std::fixed; using std::left; using std::right; using std::setw; class Box { private: int Width[5]; int Depth[5]; int Height[5]; int Volume[5]; int minX; int maxX; int maxY; int minY; string type; public: Box::Box() { int Boxes[5]; Boxes[0]=0; Boxes[1]=1; Boxes[2]=2; Boxes[3]=3; Boxes[4]=4; Width[0] = 0; Depth[0] = 0; Height[0] = 0; Volume[0] = 0; } void Box::setData() { for (int i=0; i<5; i++) { cout << "\n\n\tEnter X, Y, & Height: " << endl; cin >> Depth[i] >> Width[i] >> Height[i]; Volume[i] = Depth[i] * Width[i] * Height[i]; } } int getDepth(); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); string getType(); int getVolume(); int getWidth(); int getHeight(); void printData(); }; /* Box::Box(int w, int d) { width = w; depth = d; } */ void Box::printData() { int Boxnumbers[5]; cout << fixed; cout.precision(2); cout << left << setw(25) << "Box#" << left << setw(25) << "Box Type" << right << setw(25) << "Volume(cu/units)" << endl; { for (int i=0;i<5;i++) { for (int j=0;j<4;j++) { Boxnumbers[i] = i+1; } cout << left << setw(25) << Boxnumbers[i] << left << setw(25) << type << right << setw(25) << Volume << endl; } } } string Box::getType() { for (int i=0; i<5; i++) { if (Width[i] == Depth[i] && Depth[i] == Height[i]) { type = "Square"; } else { type = "Rectangular"; } } return type; } int Box::getVolume() { for (int i=0; i<5; i++) { return Volume[i]; } } int Box::getWidth() { for (int i=0; i<5; i++) { return Width[i]; } } int Box::getHeight() { for (int i=0; i<5; i++) { return Height[i]; } } int main() { Box Boxes[5]; Box *xpointer; xpointer = &Boxes[0]; for (int i=0; i<5;i++) { Boxes[i].setData(); Boxes[i].getWidth(); Boxes[i].getDepth(); Boxes[i].getHeight(); Boxes[i].getType(); Boxes[i].getVolume(); Boxes[i].printData(); } //declare an array of 5 objects of type Box //call a function to load the user input into each object //call a function to print results for part #1 and #2 //call a function to print results for part #3 //print the results for part #4 cout << "\n\n\t" <
 ``1234567`` ``````int Box::getVolume() { for (int i=0; i<5; i++) { return Volume[i]; } }``````
You define the member functions of the class in the class itself like this: `Box::Box()` , which is incorrect. When you define a function in the class itself, you can skip the `Box::` part. `Box::Box()` is used when you declare the functions in the class, and define them outside the class.