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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#include<iostream>
#include<iomanip>
#include<string>
#include<iomanip>
using namespace std;
class CPoint2D
{
public:
void printData();
double m_x;
double m_y;
};
class Box
{
public:
Box();
int boxid;
int getDepth(), getWidth(), getHeight(), getVolume();
string getType();
void setData();
CPoint2D m_LL; // lower left point
CPoint2D m_TR; // top right point
private:
int heightstore, absheight, width, depth, height, volume, localmaxx, localminy, localminx, localmaxy;
string type;
};
Box::Box()
{
boxid = 0;
heightstore =0;
absheight = 0;
width = 0;
depth = 0;
height = 0;
volume = 0;
localmaxx = 0;
localminy = 0;
localminx = 0;
localmaxy = 0;
}
void getInput() // grab input of all 5 boxes and store in placeholder variables
{
static int xholder[2], yholder[2], heightstore[1];
for (int i=0;i<4;i++)
{
cout << "\n\ntEnter X, Y: " << endl;
cin >> xholder[i] >> yholder[i];
}
cout << "\n\n\tEnter height: " << endl;
cin >> heightstore[1];
}
void Box::setData()
{
// setting values
for (int i=0;i<4;i++)
{
boxid = i;
}
width = m_TR.m_x - m_LL.m_x;
depth = m_TR.m_y - m_LL.m_y;
height = absheight;
volume = getVolume();
}
int Box::getWidth()
{
width = m_TR.m_x - m_LL.m_x;
return width;
}
int Box::getDepth()
{
depth = m_TR.m_y - m_LL.m_y;
return depth;
}
int Box::getHeight()
{
height = heightstore;
return height;
}
string Box::getType()
{
if (width == depth && depth == height)
{type = "Square";}
else
{type = "Rectangular";}
return type;
}
int Box::getVolume()
{
volume = depth * height * width;
return volume;
}
void printData(Box BoxObjects5[5])
{
{
cout << left << setw(25) << "Box#";
cout << left << setw(25) << "Type";
cout << right << setw(25) << "Volume";
for (int i=0;i<4;i++)
{
cout << left << setw(25) << BoxObjects5[i].boxid;
cout << left << setw(25) << BoxObjects5[i].getType();
cout << right << setw(25) << BoxObjects5[i].getVolume();
}
}
}
int main()
{
Box BoxObjects5[5];
CPoint2D newobject;
getInput();
for (int i=0;i<5;i++)
{
BoxObjects5[i].setData();
BoxObjects5[i].getWidth();
BoxObjects5[i].getDepth();
BoxObjects5[i].getHeight();
BoxObjects5[i].getVolume();
cout << "\n\n\t" << endl;
}
newobject.printData();
cout<<"\n\n\t"<<endl;
cout<<system("PAUSE");
return 0;
};
|