[Cpp]
/*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
* Author: Yang shaoning
* Completion date: January 1, April 9, 2013
* Version: v1.0
* Input Description: None
* Problem description :.
* Program output :.
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
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 Distance () 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 ()
{
Char c;
Cin> x> c> y;
If (c! = ',')
{
Cout <"input error, please enter again ";
Exit (0 );
}
}
Void CPoint: output () // output coordinate point in the form of (x, y)
{
Cout <"(" <x <"," <y <")" <endl;
}
Double CPoint: Distance (CPoint p) const // Distance between two points (one point is the current point, and the other point is the parameter p)
{
Double s;
S = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return s;
}
Double CPoint: Distance () const // Distance to the origin
{
Double s;
S = sqrt (x * x + y * y );
Return s;
}
CPoint: SymmetricAxis (char style) const // take 'x', 'y', and 'O' as the x axis, y axis, and origin symmetry respectively.
{
CPoint p (x, y );
Switch (style)
{
Case 'X ':
P. y =-y;
Break;
Case 'y ':
P. x =-x;
Break;
Case 'O ':
P. x =-x;
P. y =-y;
Break;
}
Return p;
}
Int main ()
{
CPoint p, p1, p2;
Cout <"Enter the first vertex ;";
P1.input ();
Cout <"enter the second vertex ;";
P2.input ();
Cout <"distance between two locations:" <p1.Distance (p2); // copy the constructor
Cout <"distance to the origin" <p1.Distance () <endl;
P = p1.20.ricaxis ('x ');
P. output ();
P = p1.20.ricaxis ('y ');
P. output ();
P = p1.20.ricaxis ('O ');
P. output ();
Return 0;
}
/*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
* Author: Yang shaoning
* Completion date: January 1, April 9, 2013
* Version: v1.0
* Input Description: None
* Problem description :.
* Program output :.
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
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 Distance () 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 ()
{
Char c;
Cin> x> c> y;
If (c! = ',')
{
Cout <"input error, please enter again ";
Exit (0 );
}
}
Void CPoint: output () // output coordinate point in the form of (x, y)
{
Cout <"(" <x <"," <y <")" <endl;
}
Double CPoint: Distance (CPoint p) const // Distance between two points (one point is the current point, and the other point is the parameter p)
{
Double s;
S = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return s;
}
Double CPoint: Distance () const // Distance to the origin
{
Double s;
S = sqrt (x * x + y * y );
Return s;
}
CPoint: SymmetricAxis (char style) const // take 'x', 'y', and 'O' as the x axis, y axis, and origin symmetry respectively.
{
CPoint p (x, y );
Switch (style)
{
Case 'X ':
P. y =-y;
Break;
Case 'y ':
P. x =-x;
Break;
Case 'O ':
P. x =-x;
P. y =-y;
Break;
}
Return p;
}
Int main ()
{
CPoint p, p1, p2;
Cout <"Enter the first vertex ;";
P1.input ();
Cout <"enter the second vertex ;";
P2.input ();
Cout <"distance between two locations:" <p1.Distance (p2); // copy the constructor
Cout <"distance to the origin" <p1.Distance () <endl;
P = p1.20.ricaxis ('x ');
P. output ();
P = p1.20.ricaxis ('y ');
P. output ();
P = p1.20.ricaxis ('O ');
P. output ();
Return 0;
}
Result:
Feel: Let's take a look at the replication constructor.