坐标

 1 #ifndef HEADER_PPOINT//头文件卫士
 2 #define HEADER_PPOINT
 3 class PPoint
 4 {
 5     double x,y;//直角坐标或极坐标
 6 public:
 7     PPoint(double ix,double iy);//设置坐标
 8     double xOffset();//设置轴分量x
 9     double yOffset();//设置y轴分量
10     double angle();//极坐标弧角
11     double radius();//极坐标半径
12 };
13 #endif//HEADER_PPOINT
14 //---------------------------------------
15 #include"ppoint.h"
16 #include<iostream>
17 using namespace std;
18 int main()
19 {
20     for(double x,y;cout<<"Enter x and y:\n"&&cin>>x>>y&&x>=0;)//
21     {
22         PPoint p(x,y);
23         cout<<"angle="<<p.angle()<<",radius="<<p.radius()<<",xOffset="<<p.xOffset()<<",yOffset"<<p.yOffset()<<"\n";
24     }
25 }
26 //-------------------------------
27 #include"ppoint.h"
28 #include<cmath>
29 using namespace std;
30 PPoint::PPoint(double ix,double iy)
31 {
32     x=ix,y=iy;
33 }
34 double PPoint::xOffset()
35 {
36     return x;
37 }
38 double PPoint::yOffset()
39 {
40     return y;
41 }
42 double PPoint::angle()
43 {
44     return (180/3.14159)*atan2(y,x);//atan2得到的是弧度
45 }
46 double PPoint::radius()
47 {
48     return sqrt(x*x+y*y);
49 }

 

posted @ 2013-04-29 11:12  herizai  阅读(105)  评论(0编辑  收藏  举报