double x,y; public: Point(){}; Point(double X,double Y){x=X,y=Y;} double r(); double theta();
double distance(Point& p); };
double Point::r(){ return sqrt(x*x+y*y); }
double Point::theta(){ int m=0.5*3.1415926 ,n; while((n-y/x>0.0001)||(n-y/x<-0.0001)){ m=m/2; n=tan(m); } return m;}
double Point::distance(Point& p){ return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)); }
/********** End **********/ void main() {
Point A(5,5),B(1,1);
cout<<\极半径为\极角为\cout<<\两点间距离为\ }
第四题
/*------------------------------------------------------- 【程序设计】
---------------------------------------------------------
题目:
定义一个点类Point,包括x坐标和y坐标(int)。定义一个CRect类,代表一个矩形, 要求CRect类中有代表矩形的左上角坐标(x1,y1)和右下角坐标(x2,y2)点类的对象, 要求CRect类中有两个成员函数RectHeight()和RectWidth(),通过这两个函数能得到 矩形的高和宽。(高和宽必须为非负数) 输出结果见样张.JPG
-------------------------------------------------------*/ #include
using namespace std;
/**********Program**********/ class Point{ intx,y; public: Point(){} Point(intX,int Y){x=X;y=Y;} void setP(intX,int Y){x=X;y=Y;} intgetX(){return x;} intgetY(){return y;} };
class CRect{ Point p,q; intx,y; public: CRect(){}
CRect(Point ppp,Pointqqq); void SetR(Point ppp,Pointqqq); double RectHeight(); double RectWidth(); };
CRect::CRect(Point ppp,Pointqqq):p(ppp),q(qqq) {
p.setP(ppp.getX(),ppp.getY()); q.setP(qqq.getX(),qqq.getY()); }
void CRect::SetR(Point ppp,Pointqqq) {
p.setP(ppp.getX(),ppp.getY()); q.setP(qqq.getX(),qqq.getY()); }
double CRect::RectHeight() {return fabs(p.getY()-q.getY());} double CRect::RectWidth() {return fabs(p.getX()-q.getX());}
/********** End **********/ int main() {
Point p1(1,9),p2(8,5),p3,p4; //p1-左上角坐标 1-x坐标 9-y坐标 p2-右下角坐标 8-x坐标 5-y坐标 CRectcr(p1,p2),cr1;
cout< cr1.SetR(p3,p4); //p3-左上角坐标 cout< return 0; } p4-右下角坐标