返回列表 發帖
本帖最後由 Alen 於 2010-12-25 11:47 編輯
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;

  4. class Milk
  5. {
  6. public:
  7.         
  8.         int Box;
  9.         int Bottle;

  10. public:
  11.         Milk(int _Box, int _Bottle) //建構子(CONSTRUCTOR)
  12.         {
  13.                 Box = _Box;
  14.                 Bottle = _Bottle;
  15.         }

  16.         Milk operator+(const Milk& a) // use member function
  17.         {
  18.                 Milk c(0,0);
  19.                 c.Bottle = Bottle + a.Bottle;
  20.                 c.Box = Box + a.Box;
  21.                 return c;

  22.         }

  23.         Milk operator-(const Milk& a) // use member function
  24.         {
  25.                  Milk c(0,0);
  26.                 c.Bottle = Bottle - a.Bottle;
  27.                 c.Box = Box - a.Box;
  28.                 return c;

  29.         }
  30. };

  31. int main()
  32. {
  33.         Milk A(2,10);
  34.         Milk B(5,3);        
  35.         
  36.         Milk C(0,0);

  37.         C = A - B;

  38.         cout << C.Box << "," <<C.Bottle;

  39.         //cout << C;
  40.         system("Pause");
  41.         return 0;
  42. }
複製代碼
我是來去無蹤的..

                                ..士豪(Alen)黑輪

TOP

返回列表