/*
* 程式的著作權和版本聲明部分
* Copyright (c) 2011, 煙台大學電腦學院學生
* All rights reserved.
* 檔案名稱:
* 作 者: 張傳新
* 完成日期: 2012 年 3 月 26 日
* 版 本 號: 1
* 對任務及求解方法的描述部分
* 輸入描述:
* 問題描述:
* 程式輸出:
* 問題分析:……
* 演算法設計:……
*/
#include<iostream>#include<cmath>using namespace std;enum SymmetricStyle { axisx,axisy,point};//分別表示按x軸, y軸, 原點對稱class CPoint{private: double x; // 橫座標 double y; // 縱座標public: CPoint(double xx=1,double yy=2):x(xx),y(yy){} double Distance(CPoint p) const; // 兩點之間的距離(一點是當前點,另一點為參數p) double Distance0() const; // 到原點的距離 CPoint SymmetricAxis(SymmetricStyle style); // 返回對稱點 void input(); //以x,y 形式輸入座標點 void output(); //以(x,y) 形式輸出座標點};void main(){ CPoint a1; CPoint a2; a1.input(); a1.output(); a1.Distance0(); a1.Distance(a2); a1.SymmetricAxis(axisx); a1.SymmetricAxis(axisy); a1.SymmetricAxis(point); system("pause");} void CPoint::input() //以x,y 形式輸入座標點{ char a; cout<<"請以“x,y ”形式輸入座標點:"<<endl; cin>>x>>a>>y; if(a!=',') { exit(0); }}void CPoint::output() //以(x,y) 形式輸出座標點{ cout<<"("<<x<<","<<y<<")"<<endl;}double CPoint::Distance0() const // 到原點的距離{ cout<<"到原點的距離為:"<<endl; cout<<sqrt(x*x+y*y)<<endl; return 0;}double CPoint::Distance(CPoint p) const // 兩點之間的距離(一點是當前點,另一點為參數p){ cout<<"與預設點的距離為:"<<endl; cout<<sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y))<<endl; return 0;}CPoint CPoint::SymmetricAxis(SymmetricStyle style) // 返回對稱點{ if(style == axisx) { y = -y; } if(style == axisy) { x = -x; } if(style == point) { x = -x; y = -y; } switch(style) { case axisx:cout<<"關於x軸的對稱點為:("<<x<<","<<y<<")"<<endl;break; case axisy:cout<<"關於y軸的對稱點為:("<<x<<","<<y<<")"<<endl;break; case point:cout<<"關於原點的對稱點為:("<<x<<","<<y<<")"<<endl;break; default:break; } return 0;}
運行結果:
經驗積累:
1.本程式用到了枚舉,我又複習了一遍,效果不錯。
2.以前對於this指標理解略有偏差,但經過同學指點,終於會了。
上機感言:
賀老師的作業真不錯,不僅讓我以前不會的學會了,而且讓我剛學的也略有小成。
說實話剛看到這個題,頭都大了,但這次我突然冷靜下來,決定一個人悶頭做,而且
告誡自己把程式分成幾塊來做,果然這種方法很起作用,雖然用時不短但我成功了
心裡好爽,哈哈。。希望以後還能繼續保持這種心態。。加油!