Académique Documents
Professionnel Documents
Culture Documents
#include <iostream>
#include <string>
#include <iomanip>
Shape::Shape()
{
area =0;
length = 0;
width =0;
xmax =0;
xmin =0;
ymax =0;
ymin =0;
}
int Shape::getArea()const
{
return area;
}
int Shape::getLength()const
{
return length;
}
int Shape::getWidth()const
{
return width;
}
int Shape::getMaxX()const
{
return xmax;
}
int Shape::getMaxY()const
{
return ymax;
}
int Shape::getMinX()const
{
return xmin;
}
int Shape::getMinY()const
{
return ymin;
}
string Shape::getType()const
{
return type;
}
void Shape::setData(int ar, int l, int w, int xmx, int xmi, int ymx, int ymi, string tp)
{
area = ar;
length = l;
width = w;
xmax = xmx;
xmin = xmi;
ymax = ymx;
ymin = ymi;
type = tp;
}
//overload to enter data
istream& operator>>(istream &input, Shape &newShape)
{
int ix[4], iy[4];
input>>ix[0];
input.ignore(1);
input>>iy[0];
input.ignore(1);
input>>ix[1];
input.ignore(1);
input>>iy[1];
input.ignore(1);
input>>ix[2];
input.ignore(1);
input>>iy[2];
input.ignore(1);
input>>ix[3];
input.ignore(1);
input>>iy[3];
input.ignore(1);
int mxX = -9999, mxY = -9999, miX = 9999, miY = 9999;
for(int i =0; i<4; i++)
{
if(ix[i]>mxX)
{
mxX=ix[i];
}
if(ix[i]<miX)
{
miX=ix[i];
}
if(iy[i]>mxY)
{
mxY=iy[i];
}
if(iy[i]<miY)
{
miY=iy[i];
}
}
newShape.xmax = mxX;
newShape.ymax = mxY;
newShape.xmin = miX;
newShape.ymin = miY;
newShape.length = mxY-miY;
newShape.width = mxX-miX;
newShape.area = newShape.length*newShape.width;
if (newShape.length==newShape.width) {
newShape.type ="Square";
} else {
newShape.type ="Rectangle";
}
return input;
}
//prototype
void load(Shape arr[]);
int print12(Shape arr[]);
int print3(Shape arr[]);
// main function
int main()
{
//declare an array to hold objects of type Shape
Shape s[10];
//global function1
load(s);
//global function2
int a_area = print12(s);
//global function3
int u_area = print3(s);
//reasult 4
float rate = (float)a_area / u_area * 100;
if (rate >= 90)
cout << "The layout is efficient, it uses " << setprecision(1) << rate << "% of the
space." << endl;
else
cout << "The layout is not efficient, it wastes " << fixed << setprecision(1) <<
100 - rate << "% of the space." << endl;
return 0;
}
*/