< a >c++ of programming ideas

Source: Internet
Author: User

--"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.