定义一个Dog 类,包含age、weight等属性,以及对这些属性进行操作的方法GetAge(),SetAge (),GetWeight(),SetWeight () (分别用来设置和输出dog的年龄和体重)。定义名为jack的Dog类对象。根据输入设置jack的信息。
输入格式:
输入在一行中给出age和weight的2个值,例如:8 30
输出格式:
输出两行数据,第一行初值,第二行是根据输入修改的age和weight,例如,
8 30
输入样例:
在这里给出一组输入。例如:
8 30
输出样例:
在这里给出相应的输出。例如:
8 30
c++解析:
using namespace std; #include#include class Dog { public: int age = 0, weight = 0; void GetAge() { cout << this->age; } void SetAge(int a) { this->age = a; } void GetWeight() { cout << this->weight; } void SetWeight(int b) { this->weight = b; } }; int main() { Dog jack; int a, b; cin >> a >> b; jack.SetAge(a); jack.SetWeight(b); jack.GetAge(); cout << " "; jack.GetWeight(); }



