A. Calculating the rectangular area |
Time limit:1000 MS |
Memory limit:32768 K |
Total submit:95 (users) |
Total accepted:68 (users) |
Special Judge: No |
|
Description |
There is a known sort of point definition. Define a rectangular class, as described below: Contains four properties: lower left corner, top right corner two points, area, perimeter. Area, the perimeter is determined by the lower left corner, two points in the upper right corner; the member function has (1) a constructor and a copy constructor (2) calculates the area of the rectangle (3) calculates the perimeter |
Input |
There are multiple sets of data. Each set of data contains four data x1,y1,x2,y2, representing the lower-left corner of the rectangle and the horizontal ordinate of the upper-right corner, respectively. |
Output |
Area and perimeter of a rectangle |
Sample Input |
-1-1 2 3 -5-6 0-1 |
Sample Output |
12 14 25 20 |
Hint |
Knowledge points: Combinations of classes |
#include <iostream>
using namespace Std;
Class Point
{
Private
int x, y;
Public
Point (int xx=0,int yy=0): X (xx), Y (yy) {}
Point (Point &p);
int Getx () {return x;}
int gety () {return y;}
};
Point::p oint (Point &p)
{
x=p.x;
Y=P.Y;
}
Class Rectangle
{
Private
Point P1,p2;
int Ss,cs;
Public
Rectangle (point np1,point np2);
Rectangle (Rectangle &l);//You can only declare a copy constructor can be processed in a constructor if it encounters an area and a perimeter of two quantities simultaneously
int Getcs () {return Cs;}
int Getss () {return Ss;}
};
Rectangle::rectangle (Point np1,point np2):p 1 (NP1), p2 (NP2)
{
int X=p1.getx ()-p2.getx ();
int y=p1.gety ()-p2.gety ();
Cs=x+x+y+y;
Ss=x*y;
}
Rectangle::rectangle (Rectangle &l):p 1 (L.P1), p2 (L.P2)
{
Cs=l.cs;
SS=L.SS;
}
int main ()
{
int x1,y1,x2,y2;
while (CIN>>X1>>Y1>>X2>>Y2)
{
Point Newp1 (X1,y1), NEWP2 (X2,Y2);
Rectangle Rectangle (NEWP1,NEWP2);
Cout<<-rectangle.getcs ();
cout<<Rectangle. GETSS () <<endl; can only be handled by the object here class handling is not right
}
return 0;
}
Combination of Classes