Crect (region) in MFC)

Source: Internet
Author: User

Write a crect class to indicate a rectangle. The member variables of this rectangle class are x1, Y1, X2, Y2, And the coordinates in the upper left corner and lower right corner of the rectangle. Complete the following member functions:
1. crect (); // constructor without Parameters
2. crect (double X1 _, double Y1 _, double X2 _, double Y2 _); // constructor with four parameters (coordinates in the upper left and lower right corner of the rectangle)
3. bool issquare (); // determines whether the rectangle is square.
4. Double area (); // calculate the area of the rectangle.
5. bool intersecting (crect rect); // determines whether the rectangle and the other rectangle are intersecting, that is, the current rectangle and the rect have overlapping parts.

 

 

Implementation:

# Include <iostream. h>
Class crect {
PRIVATE:
Double x1;
Double X2;
Double Y1;
Double Y2;
Public:
Crect ();
Crect (double X1 _, double Y1 _, double X2 _, double Y2 _);
Bool issquare ();
Double area ();
Bool intersecting (crect rect );
};
Crect: crect ()
{X1 = Y1 = 0;
X2 = Y2 = 1;
}
Crect: :( double X1 _, double Y1 _, double X2 _, double Y2 _)
{X1 = x1 _;
Y1 = Y1 _;
X2 = X2 _;
Y2 = Y2 _;
}
Bool crect: issquare ()
{If (x2-x1) = (y2-y1 ))
Return true;
Else return false;
}
Double crect: Area ()
{Return (x2-x1) * (y2-y1 ));
}
Bool intersecting (crect rect );
{If (rect. X1 <X2 | rect. Y1 <Y2 | rect. X2> X1 | rect. Y2> Y1)
Return true;
Else return false;
}
Int main ()
{Double x1, x2, Y1, Y2;
Cout <"Please input two endpoints:" <Endl;
Cin> x1> Y1> X2> Y2;
Crect C1 (x1, Y1, X2, Y2 );
Crect C2;
If (c1.issquare ())
Cout <"The rect is a square! "<Endl;
Else cout <"The rect is not a square! "<Endl;
Cout <"the area of the rect is:" <c1.area () <Endl;
If (c1.intersecting (C2 ))
Cout <"rect C1 intersecting with rect C2! "<Endl;
Else cout <"rect C1 not intersecting with rect C2! "<Endl;
Return 0;
}

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.