c19封装.cpp
#include <iostream>
#include <string.h>
using namespace std;
// 封装:将行为和属性作为一个整体来表现生活中的事物
// 人: 行为: 吃饭 属性: 姓名、年龄
struct person
{
char name[20];
int age;
void person_eat()
{
cout << name<< "在吃饭" << age<< "岁了" << endl;
}
};
// 狗: 行为:吃饭 属性:姓名、年龄
struct dog
{
char name[20];
int age;
void dog_eat()
{
cout << name << "zai chi fan " << endl;
}
};
int main()
{
struct person p1;
strcpy(p1.name,"张三");
p1.age = 19;
p1.person_eat();
struct dog p2;
strcpy(p2.name,"王才");
p2.age = 2;
p2.dog_eat();
return 0;
}