定义一个Dog类,包含age,weight等属性,以及对这些属性操作的方法。实现并测试这个类。

时间:2025-02-14 07:47:34

定义一个Dog类,包含age,weight等属性,以及对这些属性操作的方法。实现并测试这个类。

【输入形式】

程序参考的输入(提示“Input Age and Weight:”):

Input Age and Weight:3 20
【输出形式】

程序参考的输出:

Dog Age:3 years

Dog Weight:20kg
【样例输入】

Input Age and Weight:3 20

【样例输出】

Dog Age:3 years

Dog Weight:20kg

#include <iostream>
using namespace std;
class dog
{
    int age, weight;
public:
    void setdog(int Age, int Weight);
    void display();
};
void dog::setdog(int Age, int Weight)
{
    age = Age;
    weight = Weight;
}
void dog::display()
{
    cout << "Dog Age:" << age << "years" << endl;
    cout << "Dog Weight:" << weight << "kg" << endl;
    return;
}
int main()
{
    dog d;
    int age, weight;
    cout << "Input Age and Weight:" << endl;
    cin >> age >> weight;
    (age, weight);
    ();
    return 0;
}