#究竟是哪里
#出现错误呢
已经改了2h了
我是个废物点心
感谢
#include
#include
using namespace std;
class Dog {
public://公共访问权限
//构造函数
Dog::Dog(string nname,int nage,string nsex,string ncolor,int nweight) : name(nname), age(nage), sex(nsex), color(ncolor), weight(nweight) {}
//默认构造函数
Dog() : name("dog"), age(0), sex("female"), color("white"), weight(6) { };
//void setDog(string name, int age, string sex, string color, int weight);
//void showDog() { //输出对象的各个属性
//cout <<" " <
void setName(string nname) { name = nname; }//设置姓名(写)
string getNmae() { return name; }//获取姓名(读)
void setAge(string nage) { age=nage; }//设置年龄
string getAge() { return age; }//获取年龄
void setSex(string nsex) { sex = nsex; }//设置性别
string getSex() { return sex; }//获取性别
void setColor(string ncolor) { color = ncolor; }//设置颜色
string getColor() { return color; }//获取颜色
void setWeight(string nweight){weight=nweight}//设置体重
string getWeight() { return weight; }//获取体重
void eat() { cout<" is eating" <//吃的函数(方法)
void play() { cout << nname << " is playing" << endl; }
void sleep() { cout << nname << " is sleeping" << endl; }
private://私人访问权限
string name; int age; string sex; string color; int weight;
};
int main() {
Dog d1; //用默认构造函数实例化 Dog类的一个具体对象 d1
Dog d2("阿黄", 3, "male", "黄", 15);//用构造函数实例化一个对象d2
//d1.showDog(); //对象d1调用showDog函数,实现输出d1的属性
//d2.showDog(); //对象d2调用showDog函数,实现输出d1的属性
d1.setName("旺财"); //对象d1调用setName函数,修改d1的name属性值
d1.eat(); //对象d1调用eat函数
//d2.sleep();//对象d2调用eat函数
system("pause");
return 0;
}
#include <string>
#include <iostream>
using namespace std;
class Dog {
public://公共访问权限
//构造函数
Dog(string nname,int nage,string nsex,string ncolor,int nweight) : name(nname), age(nage), sex(nsex), color(ncolor), weight(nweight) {}
//默认构造函数
Dog() : name("dog"), age(0), sex("female"), color("white"), weight(6) { };
//void setDog(string name, int age, string sex, string color, int weight);
//void showDog() { //输出对象的各个属性
//cout <<" " <<name<<" " <<age<<" "<<sex<<" " <<color<<" " <<weight<< endl; }
void setName(string nname) { name = nname; }//设置姓名(写)
string getNmae() { return name; }//获取姓名(读)
void setAge(int nage) { age=nage; }//设置年龄
int getAge() { return age; }//获取年龄
void setSex(string nsex) { sex = nsex; }//设置性别
string getSex() { return sex; }//获取性别
void setColor(string ncolor) { color = ncolor; }//设置颜色
string getColor() { return color; }//获取颜色
void setWeight(int nweight){weight=nweight;}//设置体重
int getWeight() { return weight; }//获取体重
void eat() { cout<<name<<" is eating"<<endl; } //吃的函数(方法)
void play() { cout << name << " is playing" << endl; }
void sleep() { cout << name << " is sleeping" << endl; }
private://私人访问权限
string name;
int age;
string sex;
string color;
int weight;
};
int main() {
Dog d1; //用默认构造函数实例化 Dog类的一个具体对象 d1
Dog d2("阿黄", 3, "male", "黄", 15);//用构造函数实例化一个对象d2
//d1.showDog(); //对象d1调用showDog函数,实现输出d1的属性
//d2.showDog(); //对象d2调用showDog函数,实现输出d1的属性
d1.setName("旺财"); //对象d1调用setName函数,修改d1的name属性值
d1.eat(); //对象d1调用eat函数
//d2.sleep();//对象d2调用eat函数
system("pause");
return 0;
}