プロジェクト1-体験常メンバー関数
3027 ワード
/*
* :
*Copyright(c)2013,
*All rights reserved.
* :
* :
* :2014 4 1
* :v0.1
* :
* :
* : , 、 、 。
* :
* :
* :
* :
* :
*/
#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
double x; //
double y; //
public:
CPoint(double xx=0,double yy=0);
double Distance1(CPoint p) const; // ( , p)
double Distance0() const; //
CPoint SymmetricAxis(char style) const;//style 'x','y' 'o' x , y ,
void input(); // x,y
void output(); // (x,y)
};
CPoint::CPoint(double xx, double yy)
{
x=xx;
y=yy;
}
double CPoint::Distance1(CPoint p) const
{
double a,b,d,m;
a=p.x-x;
b=p.y-y;
m=a*a+b*b;
d=sqrt(m);
return d;
}
double CPoint::Distance0() const
{
double c;
c=sqrt(x*x+y*y);
return c;
}
CPoint CPoint::SymmetricAxis(char style) const
{
CPoint p;
switch(style)
{
case 'x':
p.x=x;
p.y=-y;
break;
case 'y':
p.x=-x;
p.y=y;
break;
case 'o':
p.x=-x;
p.y=-y;
}
return p;
}
void CPoint::input()
{
cout<<" :"<<endl;
cin>>x>>y;
}
void CPoint::output()
{
cout<<x<<","<<y<<endl;
}
int main()
{
CPoint t,k,l;
t.input();
cout<<" :";
t.output();
cout<<" :";
cout<<t.Distance0()<<endl;
cout<<" X :"<<endl;
k=t.SymmetricAxis('x');
k.output();
cout<<" Y :"<<endl;
k=t.SymmetricAxis('y');
k.output();
cout<<" :"<<endl;
k=t.SymmetricAxis('o');
k.output();
cout<<" :"<<endl;
l.input();
cout<<" :"<<endl;
cout<<t.Distance1(l)<<endl;
return 0;
}
結果: