用C++求解类与对象问题

定义一个Dog类,包含属性年龄Age和体重weight,包含public成员函数获取年龄GetAge(),获取体重GetWeight(),设置年龄SetAge(),设置体重SetWeight(),显示dog的信息Show(),构造函数有缺省构造函数和带参数构造函数,缺省构造函数设置Age和weight均为0。



```c++
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

class Dog{
public:
    Dog(){
        m_Age = 0;
        m_Weight = 0;
    }
    Dog(int age, int weight){
        m_Age = age;
        m_Weight = weight;
    }

    int GetAge(){
        return m_Age;
    }

    int GetWeight(){
        return m_Weight;
    }

    void SetAge(int age){
        m_Age = age;
    }

    void SetWeight(int weight){
        m_Weight = weight;
    }

    void Show(){
        std::cout << "Age:" << m_Age << std::endl;
        std::cout << "Weight:" << m_Weight << std::endl;
    }
private:
    int m_Age;
    int m_Weight;
};

int main(void)
{
    Dog d;

    d.SetAge(25);
    d.SetWeight(100);
    d.Show();
    system("pause");
    return 0;
}

```