Download presentation
Presentation is loading. Please wait.
Published byBarnaby Nicholas Richard Modified over 8 years ago
1
7.7.7.7. Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance
2
2 2 OOP (Object Oriented Programming) OOP? (Object Oriented Programming) - -To recognize all of the data as an object, an object can be operated independently, while other objects, also available as a component to the progra m. Programming available as a component of other objects Abstraction, 추상화 Encapsulation, 캡슐화 Informationhiding, 데이터 은닉 Inheritance, 상속 Polymorphism, 다형
3
3 10 /2 01 3 Class: Object Types A C++ class is an object type. Objects are structures that allocate memory during program execution An objects is instance of some class and is created during runtime by special statements When you create the definition of a class you are defining the attributes and behavior of a new type. Attributes are data members. Behavior is defined by methods.
4
4 4 CLASS The composition of the class -The class is blueprint of the object. -The class is composed member variables(or fields) and member functions(or methods) -Member variable represents the properties of object -Member function represents the behavior of object
5
5 5 CLASS CLASS Declaration class ClassName (The first character of ClassName is uppercase) { AccessControl Keyword: MemberVariables; MemberFunctions; }; ClassName ObjectName; ObjectName.MemberFunction
6
6 6 [ practice 1 Class ]
7
7 7 [ explain 1 Class ]
8
8 8 [ practice 2 Public & Private ]
9
9 9
10
10 [ practice 2 Public & Private ]
11
11 10 /2 01 4 Special Member Functions Constructors: called when a new object is created (instantiated). can be many constructors, each can take different arguments. Destructor: called when an object is eliminated only one, has no arguments.
12
12 [ practice 3 Constructor & Destructor ]
13
13 [ practice 3 Constructor & Destructor…continue ]
14
14 [ explain 3 Constructor & Destructor ]
15
15 [ practice 4 Various Ojects ]
16
16 [ explain 4 Various Ojects ]
17
17 [ practice 5 Do you want to attack a monster? ]
18
18 [ practice 5 Do you want to attack a monster? ]
19
19 [ practice 5 Do you want to attack a monster? ]
20
20 [ explain 5 Do you want to attack a monster? ]
21
21 11 /2 01 4 this-pointer this returns always a reference to the current object. Example: Circle::Circle(double radius) { this -> radius = radius; } radius of the current (new) object constructor’s argument
22
22 11 /2 01 4 this-pointer class AAA{ private: int a; char c; double d; void set(AAA *pa) { cin >> pa -> a; cin >> pa -> c; cin >> pa -> d; class AAA{ private: int a; char c; double d; void set() //void set(AAA *this) { cin >> this -> a; cin >> this -> c; cin >> this -> d;
23
23 [ practice 6 this pointer ]
24
24 [ explain 6 this pointer ]
25
25 11 /2 01 4 Inheritance You can create a new class that inherits from an existing class. The new class is a specialization of the existing class (called subclass). You can add new members and methods. You can replace methods. Motivation: Reuse of existing code
26
26 11 /2 01 4 Inheritance Example: You have a class that represents “circles". Create a new class that represents “cylinders". Most of the behavior and attributes are the same, but a few are different/new (height of cylinder, different area computation, volume)
27
27 11 /2 01 4 Inheritance Example A Cylinder is a extended (specialized) form of a Circle. radius height Circle Cylinder
28
28 [ practice 7 inheritance ]
29
29 [ practice 7 inheritance…continue ]
30
30 [ explain 7 inheritance ]
31
Thank you
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.