[ create a new paste ] login | about

Link: http://codepad.org/uDhzu09L    [ raw code | output | fork ]

C++, pasted on Jun 27:
#include <iostream.h>
class goods{
         private:
               static int totalWeight;
               int weight;
         public:
               goods(int w)
               {
               weight=w;
               totalWeight+=w;
         }
         goods(goods& gd)
         {
               weight=gd.weight;
                totalWeight+=weight;
         }
         ~goods()
         {
               totalWeight-=weight;
         }
         int getwg()
         {
               return weight;
         }
         static int getTotal()
         {
               return totalWeight;
         }
   };
   int goods::totalWeight=0;
   int main()
   {
         int w;
         cout<<"The initial weight of goods:"<<goods::getTotal()<<endl;
         cin>>w;   //输入25
         goods g1(w);
         cin>>w;   //输入60
         goods g2(w);
         cout<<"The total weight of goods:"<<goods::getTotal()<<endl;
        return 0;
   }


Output:
1
2
The initial weight of goods:0
The total weight of goods:269078144


Create a new paste based on this one


Comments: