[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: