#include <iostream>
using namespace std;
class Dog{
private:
char* name;
int age;
int weight;
public:
Dog(){name="";age=0;weight=0;}
Dog(char* name, int age, int weight){
this->name=name;
this->age=age;
this->weight=weight;
}
Dog(const Dog& d) {
this->name =d.name;
this->age=d.age;
this->weight=d.weight;
}
inline void setName(char* name) {this->name=name;}
inline void setAge(int age) {this->age=age;}
inline void setWeight(int weight) {this->weight=weight;}
void Show(){
printf_s("Name: %-15sAge: %-10dWeight: %-10d\n", name, age, weight);
}
};
int _tmain(int argc, _TCHAR* argv[]){
Dog d1("Eddie",5,20);
Dog d2;
d1.Show();
d2.setName("Hobo");
d2.setAge(3);
d2.setWeight(23);
d2.Show();
Dog d3(d1);
d3.Show();
system("pause");
return 0;
}
【C++程序设计】P123_4-8 Dog类
最新推荐文章于 2024-03-14 19:48:27 发布