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
|
#include <iostream>
#include <string>
using namespace std;
class Box
{
public:
Box();
int getDepth(int x[4],int y[4]);
int getMaxX(int x[4]);
int getMaxY(int y[4]);
int getMinX(int x[4]);
int getMinY(int y[4]);
string getType(string type, int x[4], int y[4]){return type;}
int getVolume(int width, int height, int depth);
int getWidth(int x[4], int y[4]);
void setData(int x[4], int y[4], int z[4]);
private:
int width;
int depth;
int height;
int Volume;
string type, temp;
};
Box::Box()
{
width = 5; // initialize the data members of the class object here
depth = 14;
height = 1;
}
int Box::getDepth(int x[4], int y[4])
{
for (int i=0;i<4;i++)
{
while (x[i+1]-x[i]==0) //While x values remain constant, y values will determine depth of box
{
depth = y[i+1]-y[i];
}
}
}
int Box::getMaxX(int x[4]) // Highest Value of X from the 4 X and Y pairs
{
for (int i=0;i<4;i++)
{
for (int j = 0; j<3;j++)
{
temp = maxX[j];
maxX[j]=maxX[j+1];
maxX[j+1] = temp;
}
}
}
int Box::getMaxY(int y[4]) // Highest Value of YX from the 4 X and Y pairs
{
for (int i=0;i<4;i++)
{
for (int j = 0; j<3;j++)
{
temp = maxY[j];
maxY[j]=maxY[j+1];
maxY[j+1] = temp;
}
}
}
int Box::getMinX(int x[4]) // Lowest Value of X from the 4 X and Y pairs
{
for (int i=0;i<4;i++)
{
for (int j = 0; j<3;j++)
{
while (x[j]>=x[j+1])
{
temp = minX[j];
minX[j]=minX[j+1];
minX[j+1] = temp;
}
}
}
}
int Box::getMinY(int y[4],minY[]) //Lowest Value of Y the 4 X and Y pairs
{
for (int i=0;i<4;i++)
{
for (int j=0; j<3; j++)
{
while (y[j]>=y[j+1])
{
temp = minY[j];
minY[j]=minY[j+1];
minY[j+1] = temp;
}
}
}
}
string Box::getType(string type, int x[4],int y[4]) //If sides are equal, Cube, otherwise, Rectangle
{
for (int i=0;i<4;i++)
{
if (depth == width)
{
type = "Cube";
}
else
type = "Rectangle";
}
}
int Box::getVolume(int width, int height, int depth)
{
Volume = width * height * depth;
}
int Box::getWidth(int x[4], int y[4])
{
for (int i=0;i<4;i++)
{
while (y[i+1]-y[i]==0) //While y values remain constant, x values will determine width of box
{
width = x[i+1]-x[i];
}
}
}
void Box::setData(int x[4], int y[4], int z[4])
{
for (int i=0;i<4;i++) //taking 4 sets of x and y inputs for coodinates and storing to x[i],y[i],z[i] for object r
{
cout<<"Enter x and y separated by spaces: " <<endl;
cin>>x[]>>y[];
cout<<"Enter z: "<<endl;
cin>>z[];
}
}
int main()
{
Box r([x[4],y[4],z[1]); // declaring array of x and y coordinates of object r
{
for (i = 0; i<4; i++)
{
width = x[i];
depth = y[i];
height = z[i];
}
}
cout<<"Width of r: " << r.getWidth()<<endl;
cout<<"Depth of r: " << r.getDepth()<<endl;
cout<<"Box r is a: " << r.getType()<<endl;
r.set_width(3);
r.set_depth(5);
//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
}
/*
Results go here!
*/
|