Class of Segment

Source: Internet
Author: User

Class Line
{
Double x1, y1;
Double x2, y2;
Public
Line (double x1, double y1, double x2, double y2)
{
this->x1 = x1;
this->x2 = x2;
this->y1 = y1;
This->y2 = y2;
}
Double getx1 () {return x1;}
Double getx2 () {return x2;}
Double Gety1 () {return y1;}
Double Gety2 () {return y2;}
void Show ()
{
cout << "length=" << length (*this);
Length (line L) This is a pointer to the line class length (line) that needs to pass the member variable of the This object
THIS->GETX2 ();
}

};

Double Length (line L)
{

return sqrt ((L.GETX1 ()-L.GETX2 ()) * (L.GETX1 ()-l.getx2 ()) +
(L.gety1 ()-L.gety2 ()) * (L.gety1 ()-L.gety2 ()));
}

int _tmain ()
{
Line R1 (1.0, 8.0, 5.0, 2.0);
R1.show ();
return 0;
}

Class of Segment

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.