c++课件Lecture67.pptVIP

  • 2
  • 0
  • 约2.69万字
  • 约 88页
  • 2018-05-02 发布于河南
  • 举报
c课件Lecture6

Lecture 67: Classes Contents Characteristics of OOP The definition and declaration of class Accessing manners Member of class Constructor Copy-constructor Destructor Class combination Static members OOP Language Main Viewpoint: OOP Language can describe the existing things (object) in the nature and their relations directly. Characteristics: Belonging to advanced language. Looking on the impersonal things as objects with some attributes and behaviors. Describing the objects with same attributes and behaviors as a Class. Realizing code reuse through inheritance and polymorphism. Example of structure: struct Date{ int year; int month; int day; }; void print(Date s){ cout.fill(0); coutsetw(4)s.year-setw(2)s.month-setw(2)s.day\n; cout.fill( ); } bool isLeapYear(Date d){ return (d.year % 4==0 d.year % 100!=0)||(d.year % 400==0);} #includeiostream #includeiomanip using namespace std; void main(){ Date d; d.year = 2000; d.month = 12; d.day = 6; if(isLeapYear(d)) print(d); } Example of class: class person{ char Name[20]; int Age; char Sex; public: void Register(char *, int, char); char *GetName(){return Name;} int GetAge(){return Age;} char GetSex(){return Sex;} void show() {coutGetName()\tGetAge()\t GetSex()endl;} }; void person::Register(char * name, int age, char sex) { strcpy(Name,name); Age=age; Sex=sex; } #includeiostream #include string using namespace std; void main() { char name[20],sex; int age; cinnameagesex; person per1; per1.Register(name,age,sex); per1.show();} OOP Language(continue) Basic concept of OOP Class Object Encapsulation and Concealment Inheritance and Reuse Polymorphism Class of OOP Object collection with the same attributes and behaviors. Providing abstract description for all objects belongs to the same class, which comprised attributes and behaviors. Class of OOP Relation between class and object: Class is an abstraction of objects with the same attributes and behaviors

文档评论(0)

1亿VIP精品文档

相关文档