第7週のプロジェクトの1(2)2点の間の距離を求めます

940 ワード

/*Copyright (c)2016,              
 *All rights reserved.
 *    :main.cpp
 *      :   
 *    :2016 4 9 
 *     :v1.0
 *
 *    :        ,                
 */
#include<iostream>
#include<cmath>
using namespace std;
class Cpoint
{
private:
    double x;//   
    double y;//   
public:
    Cpoint(double xx=0,double yy=0):x(xx),y(yy){}
    double getX()
    {
        return x;
    }
    double getY()
    {
        return y;
    }
};
class Line
{
public:
    Line(Cpoint xp1,Cpoint xp2);
    void putl()
    {
        cout<<"       :"<<len<<endl;
    }
private:
    Cpoint p1,p2;
    double len;
};
Line::Line(Cpoint xp1,Cpoint xp2)
{
    p1=xp1;
    p2=xp2;
    len=sqrt((p1.getX()-p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));
}
int main()
{
    Cpoint myp1(1,1),myp2(4,5);
    Line line(myp1,myp2);
    line.putl();
    return 0;
}