6_3 coordinate point

Source: Internet
Author: User

[Cpp]
//
// Main. cpp
// 6_3.cpp
//
// Created by JI Zilong on 13-4-10.
// Copyright (c) 2013 Ji Zilong. All rights reserved.
//
# Include <iostream>
# Include <cmath>
Class CPoint
{
Private:
Double x; // abscissa
Double y; // ordinate
Public:
CPoint (double xx = 0, double yy = 0 );
Double Distance (CPoint p) const; // Distance between two points (one point is the current point, and the other point is the parameter p)
Double Distance0 () const; // distance to the origin
CPoint component ricaxis (char style) const; // The values of 'X', 'y', and 'O' for the style are x axis, y axis, and symmetric at the origin.
Void input (); // enter coordinate points in the form of x and y.
Void output (); // output coordinate points in the form of (x, y)
};
CPoint: CPoint (double xx, double yy)
{
X = xx;
Y = yy;
}
Void CPoint: input ()
{
Std: cout <"pelw.input x, y" <std: endl;
Std: cin> x> y;

}
Void CPoint: output ()
{
Std: cout <"(" <x <"," <y <")" <std: endl;
}
Double CPoint: Distance (CPoint p) const // This is a common member function.
{
Double d;
D = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return d;
}
Double CPoint: Distance0 () const
{
Double d;
D = sqrt (x * x + y * y );
Return d;
}
CPoint: Invalid ricaxis (char style) const
{
CPoint p;
P. x = x;
P. y = y; // copy the constructor to write p (* this)
Switch (style)
{
Case 'X ':
P. y =-y;
Break;
Case 'y ':
P. x =-x;
Break;
Case 'O ':
P. x =-x;
P. y =-y;
Break;
Default:
Break;
}
Return p;
}
Int main ()
{
Double distance;
CPoint a, B, p;
Std: cout <"Enter the coordinate a of the vertex ";
A. input ();
Std: cout <"Enter point B coordinates ";
B. input ();
Distance = a. Distance (B );
Std: cout <"the distance between two points is:" <distance <std: endl;
Distance = a. Distance0 ();
Std: cout <"The distance from a to the origin is:" <distance <std: endl;
P = a. equalricaxis ('x ');
Std: cout <"a's symmetry on the X axis is :";
P. output ();
P = a. equalricaxis ('y ');
Std: cout <"a's symmetry points on the Y axis are :";
P. output (); p = a. tricricaxis ('O ');
Std: cout <"a's point of symmetry about the origin is :";
P. output ();
Return 0;
}
Running result:

//
// Main. cpp
// 6_3.cpp
//
// Created by JI Zilong on 13-4-10.
// Copyright (c) 2013 Ji Zilong. All rights reserved.
//
# Include <iostream>
# Include <cmath>
Class CPoint
{
Private:
Double x; // abscissa
Double y; // ordinate
Public:
CPoint (double xx = 0, double yy = 0 );
Double Distance (CPoint p) const; // Distance between two points (one point is the current point, and the other point is the parameter p)
Double Distance0 () const; // distance to the origin
CPoint component ricaxis (char style) const; // The values of 'X', 'y', and 'O' for the style are x axis, y axis, and symmetric at the origin.
Void input (); // enter coordinate points in the form of x and y.
Void output (); // output coordinate points in the form of (x, y)
};
CPoint: CPoint (double xx, double yy)
{
X = xx;
Y = yy;
}
Void CPoint: input ()
{
Std: cout <"pelw.input x, y" <std: endl;
Std: cin> x> y;

}
Void CPoint: output ()
{
Std: cout <"(" <x <"," <y <")" <std: endl;
}
Double CPoint: Distance (CPoint p) const // This is a common member function.
{
Double d;
D = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return d;
}
Double CPoint: Distance0 () const
{
Double d;
D = sqrt (x * x + y * y );
Return d;
}
CPoint: Invalid ricaxis (char style) const
{
CPoint p;
P. x = x;
P. y = y; // copy the constructor to write p (* this)
Switch (style)
{
Case 'X ':
P. y =-y;
Break;
Case 'y ':
P. x =-x;
Break;
Case 'O ':
P. x =-x;
P. y =-y;
Break;
Default:
Break;
}
Return p;
}
Int main ()
{
Double distance;
CPoint a, B, p;
Std: cout <"Enter the coordinate a of the vertex ";
A. input ();
Std: cout <"Enter point B coordinates ";
B. input ();
Distance = a. Distance (B );
Std: cout <"the distance between two points is:" <distance <std: endl;
Distance = a. Distance0 ();
Std: cout <"The distance from a to the origin is:" <distance <std: endl;
P = a. equalricaxis ('x ');
Std: cout <"a's symmetry on the X axis is :";
P. output ();
P = a. equalricaxis ('y ');
Std: cout <"a's symmetry points on the Y axis are :";
P. output (); p = a. tricricaxis ('O ');
Std: cout <"a's point of symmetry about the origin is :";
P. output ();
Return 0;
}
Running result:

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.