WEEK 1-Project 3-plane coordinate points

Source: Internet
Author: User

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

 

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.