C++——平时学习简单练习——
Dog类定义一个Dog类,包含age,weight等属性,以及对这些属性操作的方法。实现并测试这个类
程序参考的输入(提示“Input Age and Weight:”):
Input Age and Weight:3 20
程序参考的输出:
Dog Age:3 years
Dog Weight:20kg
代码:
#include
using namespace std;
class Date
{
public:
Date()
{
cout<<“Input Age and Weight:”;
cin>>a>>w;
}
void showdog()
{
cout<<“Dog Age:”<<a<<" years"<<endl;
cout<<“Dog Weight:”<<w<<“kg”<<endl;
}
private:
int a,w;
};
int main()
{
Date d;
d.showdog();
}