啪啪拉拉噼里啪啦

          初學者天堂資料匯集

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            16 隨筆 :: 73 文章 :: 16 評論 :: 0 Trackbacks

          #include<iostream.h>
          #include<math.h>

          class Point
          { public:
          Point(int xx=0,int yy=0) {X=xx;Y=yy;} //構造函數的定義
          Point(Point &P);                      //拷貝構造函數定義
          int GetX() {return X;}                //得到X的值。
          int GetY() {return Y;}                //得到Y的值
          private:
           int X,Y;

          };
          Point :: Point(Point &P)  //拷貝構造函數的實現
          {  X=P.X;
             Y=P.Y;
           cout<<"point拷貝構造函數的調用"<<endl;
           cout<<"Point"<<endl;
          }
          //類的組合
          class Distance
          { public:
               Distance(Point XP1,Point XP2);
            double GetDis(){return Dist;}
          private:
            Point P1,P2;
            double Dist;
            double x,y;
          };
          //組合類的構造函數
          Distance::Distance(Point XP1,Point XP2):P1(XP1),P2(XP2)
          { cout<<"Distance 構造函數調用"<<endl;
             x=double(P1.GetX()-P2.GetX());
             y=double(P1.GetY()-P2.GetY());
            Dist=sqrt(x*x+y*y);
          }

          void main()
          { Point myp1(1,1), myp2(4.5);
            Distance myd(myp1,myp2);
            cout<<"the distance is"<<endl;
            cout<<myd.GetDis()<<endl;
           
          }

          posted on 2005-04-03 17:27 噼里啪啦的世界 閱讀(186) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 黎城县| 桂阳县| 洛宁县| 新密市| 和平县| 开平市| 中阳县| 安顺市| 通化市| 铁力市| 城固县| 泗洪县| 屯昌县| 旬邑县| 壶关县| 平湖市| 新竹县| 大关县| 商南县| 准格尔旗| 新野县| 潜江市| 玉环县| 阳原县| 五大连池市| 温宿县| 鹰潭市| 高尔夫| 黄梅县| 芮城县| 绥德县| 将乐县| 怀化市| 迭部县| 涞源县| 锡林郭勒盟| 彰化市| 安泽县| 德庆县| 绵竹市| 宁晋县|