定义一个Dog类,包含age,wight等属性,以及对这些属性操作的办法。实现并测试这个类。
#include <iostream>
using namespace std;
class Dog{
public:
Dog(int initialAge=0,int initialWeight=5);
~Dog();
int getAge(){
return age;
}
void setAge(int age){
this->age=age;
}
int getWeight(){
return weight;
}
void setWeight(int weight){
this->weight=weight;
}
private:
int age,weight;
};
Dog::Dog(int initialAge,int initialWeight){
age=initialAge;
weight=init

这篇博客介绍了如何在C++中定义一个Dog类,包括age和weight属性以及对应的getter和setter方法。通过示例代码展示了如何创建Dog对象并修改其属性,从而测试类的功能。
最低0.47元/天 解锁文章
1847

被折叠的 条评论
为什么被折叠?



