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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
#include <stdio.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <vector>
using namespace std;
class Box
{
private:
int m_volume;
int m_width;
int m_depth;
int m_height;
string m_type;
int m_sumvolume;
int local_maxx;
int local_maxy;
int local_minx;
int local_miny;
public:
Box();
int getDepth();
int xcoords[4];
int ycoords[4];
int getWidth();
int getHeight(int heightstore);
int getVolume();
string getType();
void print1Box();
void setData(int heightstore);
void printData();
void setMoreData();
};
Box::Box()
{
m_volume = 0;
xcoords[4] = 0;
ycoords[4] = 0;
local_maxx = 0;
local_maxy = 0;
local_miny = 0;
local_minx = 0;
m_width = 0;
m_depth = 0;
m_height =0;
string m_type = "";
int m_sumvolume = 0;
}
void Box::setData(int heightstore)
{
for (int j=0; j<4; j++)
{
cout << "\n\n\tEnter X, Y: " << endl;
cin >> xcoords[j] >> ycoords[j];
}
cout << "\n\n\tEnter Height: " << endl;
cin >> heightstore;
m_height = heightstore;
m_width = xcoords[2] - xcoords[0]; // Width
m_depth = ycoords[1] - ycoords[0]; // Depth
m_volume = getVolume();
}
void Box::setMoreData() //track local max and min values for X and Y
{
for (int j=0;j<4;j++) // 4 x Coords
{
if (xcoords[j] > xcoords[j+1])
{
local_maxx = xcoords[j];
xcoords[j] = xcoords[j+1];
xcoords[j+1] = local_maxx;
}
if (ycoords[j] > ycoords[j+1])
{
local_maxy = ycoords[j];
ycoords[j+1]= ycoords[j+1];
ycoords[j+1] = local_maxy;
}
if (xcoords[j] < xcoords[j+1])
{
local_minx = xcoords[j];
xcoords[j] = xcoords[j+1];
xcoords[j+1] = local_minx;
}
if (ycoords[j] < ycoords[j+1])
{
local_miny = ycoords[j];
ycoords[j+1]= ycoords[j+1];
ycoords[j+1] = local_miny;
}
}
}
void Box::print1Box()
{
cout << left << setw(25) << "Box#" << left << setw(25) << "Box Type" << right << setw(25) << "Volume(cu/units)" << endl;
cout << left << setw(25) << "No. 1" << left << setw(25) << m_type << right << setw(25) << m_volume << endl;
}
void Box::printData()
{
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++)
{
cout << left << setw(25) << i << left << setw(25) << m_type << right << setw(25) << m_volume << endl;
}
}
}
}
string Box::getType()
{
if (m_width == m_depth && m_depth == m_height)
{
m_type = "Square";
}
else
{
m_type = "Rectangular";
}
return m_type;
}
int Box::getWidth()
{
return m_width;
}
int Box::getDepth()
{
return m_depth;
}
int Box::getHeight(int heightstore)
{
return m_height;
}
int Box::getVolume()
{
m_volume = m_width * m_depth * m_height;
return m_volume;
}
class BoxCollection
{
private:
int Boxes[5];
int maxX;
int maxY;
public:
BoxCollection();
void getMaxX(int Boxes[5], int xcoords[5], int ycoords[5]);
};
void BoxCollection::getMaxX(int Boxes[5], int xcoords[5], int ycoords[5])
{
int temp;
for (int i=0; i<5; i++)
{
for (int j =0; j<4; j++)
{
if (xcoords[j]>xcoords[j+1])
{
temp = xcoords[j];
xcoords[j]=xcoords[j+1];
xcoords[j+1]=temp;
}
}
}
};
int main()
{
int heightstore;
int z;
int r;
z =5;
r = 37;
heightstore = 0;
Box Boxes[5]; //declaring 5 objects of type box in "Boxes" array
for (int i=0; i<5;i++)
{
Boxes[i].setData(heightstore);
Boxes[i].getWidth();
Boxes[i].getDepth();
Boxes[i].getHeight(z);
Boxes[i].getType();
Boxes[i].getVolume();
Boxes[i].print1Box();
Boxes[i].setMoreData();
}
for (int i=0; i<1;i++)
{
cout << "\n\n\t" <<endl;
Boxes[i].printData();
}
/* BoxCollection Objects[5];
for (int i=0; i<5; i++)
{
Objects[i].getMaxX();
Objects[i].getMaxY();
Objects[i].getMinX();
Objects[i].getMinY();
}
*/
//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" << endl;
cout << "Press the enter key to continue ...";
cin.get();
return EXIT_SUCCESS;
}
/*
Results go here!
*/
/* vector<int> myBoxVector(3,0); // { 0, 0, 0 }
vector<int> my2ndboxVector(4,0); // { 0, 0, 0, 0 }
myBoxVector.push_back(10); // { 0, 0, 0, 0, 10 }
myBoxVector.pop_back();
for (int i=0; i<5; i++)
{
myBoxVector[i] = i; // {0, 1, 2, 3, 4}
}
cout << "third element: " << myBoxVector[3] << endl;
cout << "last element: " << myBoxVector.back() << endl;
myBoxVector.erase(myBoxVector.begin() +2, myBoxVector.begin() +4);
for (int i=0; i<32; i++)
{
newBoxVector.push_back(i);
cout << "#" << i << " size: " << newBoxVector.size();
cout <<", capacity: " << newBoxVector.capacity() << endl;
}
cout << "----" << endl;
vector <int> newVector; //{0,1,2}
*/
|