제6 주 프로젝트 1

/*
* Copyright (c)2013,            
* All rightsreserved.
*     : array.cpp
*       :      
*     :2014    4   1   
*    : v1.0
*     : 
*/

#include <iostream>
#include <cmath>
#include <cstdlib>
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   //        (      ,      p)
{
    return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
double CPoint::Distance0() const           //       
{
    return sqrt(x*x+y*y);
}
CPoint CPoint::SymmetricAxis(char style) const//style 'x','y' 'o'     x , y ,     
{
    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;
    break;
    }
return p;
}
void CPoint::input() // x,y        
{
    cout<<"      (x)    (y)  :"<<endl;
    cin>>x>>y;
}
void CPoint::output() // (x,y)        
{
    cout<<"      :("<<x<<","<<y<<")";
}
int main()
{
    CPoint a,b,c;
    int chose;
    b.input();
    a.input();
    a.output();
    while(1)
    {
        cout<<"         :"<<endl;
        cout<<"1.           2.        "<<endl;
        cout<<"3.  x          4.  y   "<<endl;
        cout<<"5.      "<<endl;
        cin>>chose;
        switch(chose)
        {
            case 1:
            cout<<"       :"<<a.Distance1(b)<<endl;
            break;
            case 2:
            cout<<"         :"<<a.Distance0()<<endl;
            break;
            case 3:
            c=a.SymmetricAxis('x');
            c.output();
            break;
            case 4:
            c=a.SymmetricAxis('y');
            c.output();
            break;
            case 5:
            c=a.SymmetricAxis('o');
            c.output();
            break;
            default:
            cout<<"    ,     "<<endl;
            cin>>chose;
        }
    }
return 0;
}


 
 
 
 
두 점 사이 의 거 리 를 만 들 때 는 정말 많은 시간 이 걸 렸 고, 다른 사람의 조언 으로 마침내 완성 되 었 다.쉽 지 않 은 데...뭔 가 돌아 가 는 것 같 아.

좋은 웹페이지 즐겨찾기