CPP教学材料-电子课件-第 章a5.pptVIP

  • 5
  • 0
  • 约1.84万字
  • 约 77页
  • 2021-03-23 发布于云南
  • 举报
20XX年复习资料;C++面向对象程序设计教程;5.1 继承与派生;5.1.1 继承与派生的概念;实例说明为什么要使用继承;// 声明类Person(人) class Person { protected: // 数据成员 char name[18]; // 姓名 int age; // 年龄 char sex[3]; // 性别 public: // 公有函数 Person(char nm[], int ag, char sx[]): age(ag) { strcpy(name, nm); strcpy(sex, sx); } // 构造函数 void SetName(char nm[]) { strcpy(name, nm); }// 设置姓名 void SetAge(int ag) { age = ag;; } // 设置年龄 void SetSex(char sx[]) { strcpy(sex, sx); } // 设置性别 const char *GetName() const { return name; } // 返回姓名 int GetAge() const { return age; } // 返回年龄 const char *GetSex() const { return sex; } // 返回性别 void S

文档评论(0)

1亿VIP精品文档

相关文档