codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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; }
Private
[
?
]
Run code
Submit