--"In the real world, everything is the object." objects can be tangible or intangible.
The goal of writing a program is to describe and solve real-world problems, and the first step is to faithfully reflect the real-world objects and classes in the program.
Encapsulating the abstract data and functions together constitutes a "class" in C + +.
The main features of object-oriented programming are abstraction, encapsulation, inheritance and polymorphism.
Object-oriented programming is a basic module unit that composes a program with "class".
Abstract in object-oriented approach refers to the process of summarizing specific problems (objects), extracting the common properties of a class of objects and describing them.
In general, the abstraction of a problem should include two aspects: Data abstraction and behavioral abstraction (or function abstraction, code abstraction).
The former describes the properties or state of a class of objects (with what), that is, the characteristics of such objects that are different from those of the object, which describes the common behavior or functional characteristics of a class of objects (what can be done).
Case: 1, with C + + variables and functions can be the abstract of the clock described as follows:
Data abstraction: int Hour,int minute,int Second
Function abstraction: ShowTime (), Settimez ()
2, the abstract after the person is described as follows:
Data abstraction: String name,string sex,int Age
Function abstraction: Eat (), walk (), work (), study ()
Encapsulation is the combination of abstract data and behavior (or function) to form an organic whole, that is, to combine the function code of data and operational data into a "class" where the data and functions are members of the class.
The C + + syntax clock class can be defined as follows:
Class Clock//class keyword category name
{//Boundary
Public://external interface
void settime (int newh,int newm,int NewS); Behavior, code members
void ShowTime (); Behavior, code members
Private://Specific access rights
int Hour,minute,second; Properties, data members
}; Boundary
The programming steps of the C + + language consist of about three modules: 1, the definition of Class 2, the concrete implementation of the member functions of the Class 3, the main function main ().
< a >c++ of programming ideas