Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Define a rectangular class whose data members are the coordinates of two diagonal points: X 1, X2, y 1, y2. They are all plastic. The function is to find the perimeter and surface.
Define a rectangular class whose data members are the coordinates of two diagonal points: X 1, X2, y 1, y2. They are all plastic. The function is to find the perimeter and surface.
Rectangular. h

# Miscellaneous note once

# include & ltmath.h & gt

Triangle-like

{

Private:

int x 1,x2,y 1,y2;

int a,b; //Length and width

Public:

crect angle(void);

CRectangle(int x 1,int y 1,int x2,int y2);

~ crect angle(void);

int calLength(); //Calculate the perimeter

int calArea();

};

Rectangular.cpp

# include & ltstdio.h & gt

# contains "Rectangle.h"

CRectangle::CRectangle(void)

{

x 1 = x2 = y 1 = y2 = 0;

}

CRectangle::~CRectangle(void)

{

}

crect angle::crect angle(int x 1,int y 1,int x2,int y2){

This-> x 1 = x 1;

This-> x2 = x2

This-> y 1 = y 1;

This-> y2 = y2

a = ABS(x 1-x2);

b = ABS(y 1-y2);

}

int CRectangle::calArea(){

Return a * b;;

}

int CRectangle::calLength(){

Returns 2 * (a+b);

}

int main(){

crect angle * rec = new crect angle( 1,3,-2,6);

printf("%d,%d ",rec-& gt; calArea(),rec-& gt; calLength());

}