ytuoj-Rectangle class Definition (object Copy object)

Source: Internet
Author: User

Title Description

Defines a rectangular class that includes the lower-left and upper-right coordinates, defines the member functions that include the necessary constructors, the functions that enter the coordinates, and the functions that calculate and output the rectangular area. Requires that the test function given in the hint be used and must not be altered.

Input

Four numbers, representing the coordinates of the lower-left and upper-right vertices of the rectangle, such as input 3.7 0.4 6.5 4.9, representing the lower left corner coordinates (3.7, 0.4), and the upper-right coordinate (6.5, 4.9).

Output

There are 3 lines in the output (refer to the main function in the hint (hint)):
First line: Rectangle object determined by the input coordinates area of the P1
Second line: Rectangle object copied from object P2 area
Third line: direct initialization of the resulting rectangular object P3 area

Sample input
3.7 0.4 6.5 4.9
Sample output
12.612.610
Tips

int main ()

{

Rectangle P1;

P1.input ();

P1.output ();

Rectangle P2 (p1);

P2.output ();

Rectangle P3 (1,1,6,3);

P3.output ();

return 0;

}

The code is as follows:

#include <iostream> #include <cmath>using namespace Std;class rectangle{public:    Rectangle (Double a=0, Double b=0,double c=0,double d=0);    Rectangle (Rectangle &p);    void input ();    void output ();p rivate:    double x1;    Double Y1;    Double X2;    Double y2;}; Rectangle::rectangle (double a,double b,double c,double d) {    x1=a;    y1=b;    X2=c;    Y2=d;} void Rectangle::input () {    double a,b,c,d;    cin>>a>>b>>c>>d;    X1=a;    y1=b;    X2=c;    Y2=d;} Rectangle::rectangle (Rectangle &p) {    x1=p.x1;    Y1=p.y1;    x2=p.x2;    Y2=p.y2;} void Rectangle::output () {    cout<<fabs ((x2-x1) * (y2-y1)) <<endl;} int main () {    Rectangle p1;    P1.input ();    P1.output ();    Rectangle P2 (p1);    P2.output ();    Rectangle P3 (1,1,6,3);    P3.output ();    return 0;}


Operation Result:

Learning experience:

Before learning the constructor of the time did not pay attention to the object to assign value to the object operation, but this week the first project has a two objects related to the operation, and then imitate that to do, the results even compile can not pass, and finally chose to ask the mother, the original function Rectangle::rectangle ( Rectangle &p) less A & (of course, the definition of the internal function is different, using the this pointer), has not found the big use of &, now finally know the t.t.

ytuoj-Rectangle class Definition (object Copy object)

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.