六周任务3

#include <iostream>
#include <cmath>

using namespace std;

enum SymmetricStyle { axisx , axisy , point };

class CPoint
{
private :
 double x ;
 double y ;

public :
 CPoint( double xx = 0 , double yy = 0 );//构造函数声明

 double Distance ( CPoint p ) const ;//求两点距离函数声明

 double Distance0() const ;//求点到原点距离函数声明

 CPoint SymmetricAxis ( SymmetricStyle ) const ;//求对称点

    void input() ;//按x , y的形式输入点

 void output() ;//按(x,y)输出点的值

};

CPoint::CPoint( double xx , double yy )
{
 x = xx ;
 y = yy ;
}

void  CPoint::input()
{
 cout << "按 x , y 的形式输入坐标点" << endl ;
  cin >> x >> y ;
}

void  CPoint::output()
{
cout<< "点的坐标为:" <<"("<< x <<","<< y <<")"<< endl ;
}

double  CPoint::Distance0() const
{
 double H ;
  
 H = sqrt ( x * x + y * y ) ;
 return H;
}

double CPoint::Distance ( CPoint p ) const
{
 double h ;
 h = sqrt ((x - p.x)*(x - p.x) + (y - p.y)*(y - p.y)) ; 
 return h ;
}

int main()
{
 CPoint cp1 , cp2 ;

 cp2.input() ;
 cp1.input() ;
 cp1.output() ;

 cout << "点到原点的距离为:" << cp1.Distance0()<< endl ; 

 cout << "两点之间的距离为:" << cp1.Distance ( cp2 )<< endl ;

 cp1.SymmetricAxis( axisx );
 cout<< endl ;
 cp1.SymmetricAxis( axisy );
 cout<< endl ;
 cp1.SymmetricAxis( point );

 system ("pause") ;

 return  0 ;
}

CPoint CPoint::SymmetricAxis(SymmetricStyle style)  const  // 返回对称点   
{  
    switch(style)  //利用switch语句选择
    {  
    case axisx:  
        cout<<"点("<<x<<","<<y<<")"<<"关于y轴对称的点为:";   
        cout<<"("<<-x<<","<<y<<")";  
        break;  
    case axisy:  
        cout<<"点("<<x<<","<<y<<")"<<"关于x轴对称的点为:";  
        cout<<"("<<x<<","<<-y<<")";  
       break;  
    case point:  
        cout<<"点("<<x<<","<<y<<")"<<"关于原点对称的点为:";  
        cout<<"("<<-x<<","<<-y<<")";  
        break;  
    }  
    return 0;  
}  
 

   运行结果: 
 
感受:这里的选择结构有点困难,用时过长了,加油。。。。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值