定义一个dog类(c++)
定义一个dog类,包含age,weight等属性,以及对这些属性的操作的方法。实现并测试这个类。...
定义一个dog类,包含age,weight等属性,以及对这些属性的操作的方法。实现并测试这个类。
展开
展开全部
#include <cstdlib>
#include<iostream>
using namespace std;
class dog
{
private:
int m_age;
int m_weight;
public:
dog():m_age(0),m_weight(0){}
void setAge(int i){m_age=i;}
void setWeight(int i){m_weight=i;}
int age(){return m_age;}
int weight(){return m_weight;}
};
int main()
{
dog d;
cout<<d.age()<<" "<<d.weight()<<endl;
return 0;
}
#include<iostream>
using namespace std;
class dog
{
private:
int m_age;
int m_weight;
public:
dog():m_age(0),m_weight(0){}
void setAge(int i){m_age=i;}
void setWeight(int i){m_weight=i;}
int age(){return m_age;}
int weight(){return m_weight;}
};
int main()
{
dog d;
cout<<d.age()<<" "<<d.weight()<<endl;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include
<cstdlib>
#include<iostream>
using
namespace
std;
class
dog
{
private:
int
m_age;
int
m_weight;
public:
dog():m_age(0),m_weight(0){}
void
setAge(int
i){m_age=i;}
void
setWeight(int
i){m_weight=i;}
int
age(){return
m_age;}
int
weight(){return
m_weight;}
};
int
main()
{
dog
d;
cout<<d.age()<<"
"<<d.weight()<<endl;
return
0;
}
<cstdlib>
#include<iostream>
using
namespace
std;
class
dog
{
private:
int
m_age;
int
m_weight;
public:
dog():m_age(0),m_weight(0){}
void
setAge(int
i){m_age=i;}
void
setWeight(int
i){m_weight=i;}
int
age(){return
m_age;}
int
weight(){return
m_weight;}
};
int
main()
{
dog
d;
cout<<d.age()<<"
"<<d.weight()<<endl;
return
0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询