1个回答
展开全部
#include <iostream>
#include <string>
using namespace std;
class Dog
{
public:
Dog() {age = 1; sex = "male"; weight = 1.0;}
Dog(int _age, string _sex, double _weight):age(_age), sex(_sex), weight(_weight) {}
~Dog(){}
void setDog(int _age, string _sex, double _weight)
{
age = _age;
sex = _sex;
weight = _weight;
}
void showDog()
{
cout<<"age = "<<age<<", sex = "<<sex.c_str()<<", weight = "<<weight<<endl;
}
private:
int age;
string sex;
double weight;
};
int main()
{
Dog d1, d2(10, "female", 20.0);
d1.showDog();
d2.showDog();
d1.setDog(8, "female", 50);
d1.showDog();
cin.get();
return 0;
}
#include <string>
using namespace std;
class Dog
{
public:
Dog() {age = 1; sex = "male"; weight = 1.0;}
Dog(int _age, string _sex, double _weight):age(_age), sex(_sex), weight(_weight) {}
~Dog(){}
void setDog(int _age, string _sex, double _weight)
{
age = _age;
sex = _sex;
weight = _weight;
}
void showDog()
{
cout<<"age = "<<age<<", sex = "<<sex.c_str()<<", weight = "<<weight<<endl;
}
private:
int age;
string sex;
double weight;
};
int main()
{
Dog d1, d2(10, "female", 20.0);
d1.showDog();
d2.showDog();
d1.setDog(8, "female", 50);
d1.showDog();
cin.get();
return 0;
}
追问
运行了之后有五个错误诶
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
亚果会
2024-04-11 广告
2024-04-11 广告
Goma Greens是一家专注于提供高品质有机蔬果的企业。我们致力于为消费者带来新鲜、健康、无污染的食材,以满足现代人对健康生活的追求。我们的产品均来自精心挑选的有机农场,通过严格的品质控制,确保每一份食材都达到最高标准。此外,我们还提供...
点击进入详情页
本回答由亚果会提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询