#include<iostream>usingnamespace std;classDog{public:Dog(int initialAge =0,int initialWeight =5);~Dog();intGetAge(){return itsAge;}voidSetAge(int age){itsAge =age;}intGetWeight(){return itsWeight;}voidSetWeight(int weight){itsAge=weight;}private:int itsAge,itsWeight;};
Dog::Dog(int initialAge,int initialWeight){
itsAge=initialAge;
itsWeight=initialWeight;}
Dog::~Dog(){}intmain(){
Dog Jack(2,10);
cout<<"Jack is a Dog who is ";
cout<<Jack.GetAge()<<" years old and ";
cout<<Jack.GetWeight()<<" pounds weight.\n";
Jack.SetAge(7);
Jack.SetWeight(20);
cout<<"Now Jack is ";
cout<<Jack.GetAge()<<" years old and";
cout<<Jack.GetWeight ()<<" pounds weight.";return0;}![在这里插入图片描述](https://img-blog.csdnimg.cn/20201123224918378.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1MjU3NDk1,size_16,color_FFFFFF,t_70#pic_center)