类的运用(一)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include using namespace std; class Dog{ public : Dog( int Age, int Weight); //构造函数 Dog(Dog&gou); //复制构造函数 int setAge( int Age); int setWeight( int Weight); int getAge(); int getWeight(); ~Dog(){ cout<< "~Dog" < } //析构函数 private : int age,weight; }; Dog::Dog( int Age, int Weight){ age=Age; weight=Weight; } Dog::Dog(Dog&gou){ age=gou.age; weight=gou.weight; cout<< "OK,success" < } int Dog::setAge( int Age){ age=Age; } int Dog::setWeight( int Weight){ weight=Weight; } int Dog::getAge(){ return age; } int Dog::getWeight(){ return weight; } int main(){ int age,weight; Dog dog(5,30); Dog b=dog; cout< cout<< "Jack is " < " years old,and " < " pounds weight!" < cin>>age>>weight; dog.setAge(age); dog.setWeight(weight); cout<< "Now,Jack is " < " years old,and " < " pounds weight!" < return 0; }

【类的运用(一)】



本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1338324,如需转载请自行联系原作者

    推荐阅读