Estructura rectángulo

Aquí se define la estructura rectángulo. Tiene dos vértices principales opuestos, a partir de los cuales se definen los otros dos. Tiene un área y un formato con el que se despliegan sus datos.

#include <cmath>

struct rectangulo : FiguraGeom{
float x1,y1,x2,y2,x3,y3,x4,y4;

rectangulo(){  //Constructor
x1=0;
x2=0;
y1=0;
y2=0;
area=0.0;
}

rectangulo(float xx1, float yy1, float xx2, float yy2){  //Constructor
x1=xx1;
x2=xx2;
y1=yy1;
y2=yy2;
y3=y1;
x3=x2;
x4=x1;
y4=y2;
area = abs((x1-x2)*(y1-y2));
}

void muestra(){
cout << “Rectangulo: (“<<x1<<“,”<<y1<<“),(“<<x2<<“,”<<y2<<“)”<<“(“<<x3<<“,”<<y3<<“),(“<<x4<<“,”<<y4<<“)”<<“; area= “<<area<<endl;
}

};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s