Defina una clase de rectángulo cuyos miembros de datos sean las coordenadas de dos puntos diagonales: X1, X2, y1, y2. Son todos de plástico. La función es encontrar el perímetro y la superficie.
#Pragma once
# include & ltmath.h & gt
En forma de triángulo
{
Privado:
int x1, x2, y1, y2;
int a, b; //largo y ancho
Público:
ángulo correcto(vacío);
CRectangle(int x1, int y1, int x2, int y2);
~ ángulo correcto(vacío);
int calLength(); //Calcular perímetro
int calArea();
};
Rectángulo. # include & ltstdio.h & gt
#Include "Rectangle.h"
CRectangle::CRectangle(void)
{
x 1 = x2 = y 1 = y2 = 0;
}
CRectangle::~CRectangle(void)
{
}
ángulo correcto::ángulo correcto(int x 1, int y1, int x2, int y2){
Esto->x 1 = x 1;< /p >
Esto->x2 = x2
Esto->y 1 = y 1;
Esto->y2 = y2
a = ABS(x 1-x2);
b = ABS(y 1-y2
}
int CRectangle:: calArea(){
Devuelve a * b;
}
int CRectangle::calLength(){
Devuelve 2 *( a+b);
}
int main(){
ángulo correcto * rec = nuevo ángulo correcto(1, 3, -2, 6) ;
printf("%d, %d ", rec-& gt; calArea(), rec-& gt; calLength()
}
;