Combination of Classes

Source: Internet
Author: User
Tags gety

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&GT;&GT;X1&GT;&GT;Y1&GT;&GT;X2&GT;&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.