六周任务3

来源:互联网 发布:淘宝接单大厅 编辑:程序博客网 时间:2024/05/16 19:03
#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;  }      运行结果:  
感受:这里的选择结构有点困难,用时过长了,加油。。。。

原创粉丝点击