SlideShare una empresa de Scribd logo
1 de 19
DEV BHOOMI GROUP OF 
INSTITUTIONS 
SAHARANPUR 
Name : Saurabh Chauhan 
Class : M.C.A. 1ST (2013-15) 
Roll no : 1358614017 
Topic : Classes and Object. 1 
Sub To : Mr. Rakesh Kumar 
Sub By : Saurabh Chauhan
C++ CLASSES 
& 
OBJECT 
WELCOME :
OUTLINE : 
 Introduction of the class : 
 Characteristics of the class : 
 Format of the class : 
 Define a class type : 
 Implementing class methods : 
 Introduction of an Object : 
 Declaration of an object : 
 Reasons for OOP : 
 Thank you : 
3
INTRODUCTION OF THE CLASS : 
 A class is binding the data and methods. 
 A class is a collection of objects of similar type. 
 A class is an object factory (or producer ) that 
produces similar objects. 
 A class is just like an image and model and can say 
a template. 
 A class does not exists physically because it’s a 
image only in our mind 
 But object exists physically because a object is a 
real world entity i.e. a pen , a chair , a desk , a dog , 
a bike , a car ,a men etc 
 The class and object both are sub method of the 
OOP’s methodology 
4
WHY DO WE NEED TO HAVE CLASS ? 
Characteristics of the class : 
 Structures are public by default and classes are 
private by default. 
 Data more secure in the class. 
 Class reduce the complexity. 
 We can easy and well programming, if we use the 
class in our program . 
5
CLASSES IN C++ 
 A class definition begins with the keyword class. 
 The body of the class is contained within a set of 
braces, { } ; (notice the semi-colon). 
class class_name 
{ 
…. 
…. 
…. 
}; 
Any valid 
identifier 
Class body (data member 
+ methods)
CLASSES IN C++ 
 Within the body, the keywords private: and public: 
specify the access level of the members of the 
class. 
 the default is private. 
 Usually, the data members of a class are declared 
in the private: section of the class and the member 
functions are in public: section.
CLASSES IN C++ 
 Format : 
class class_name 
{ 
private: 
… 
… 
… 
public: 
… 
… 
… 
}; 
private members data 
or variables or 
characteristics 
Public members or methods 
Or behavior
DEFINE A CLASS TYPE 
Header 
class class_name 
{ 
access specifier : 
data ; 
access specifier : 
methods ; 
... 
class Rectangle 
{ 
private: 
int width; 
int length; 
public: 
void set(int w, int l); 
int area(); 
}; 9 
}; 
Body
IMPLEMENTING CLASS METHODS 
 Class implementation: writing the code of 
class methods. 
 There are two ways: 
1. Member functions defined outside class 
 Using Binary scope resolution operator (::) 
 “Ties” member name to class name 
 Uniquely identify functions of particular class 
 Different classes can have member functions with 
same name 
 Format for defining member functions 
ReturnType ClassName::MemberFunctionName( 
){ 
… 
}
IMPLEMENTING CLASS METHODS 
2. Member functions(method) defined inside class 
 Do not need scope resolution 
operator, class name; 
class Circle 
{ 
private: 
double r,ar; 
public: 
void area () 
{ 
cin<<r ; 
ar=r*r*3.14; 
} 
cout<<“n a area of circle -”<<ar; 
}; 
Method 
Defined 
inside 
class
// this is a program of area of circle 
// methods (Defined outside class) 
class Circle 
{ 
private: 
double r,ar; 
public: 
void area(); // mehtod 
}; 
void circle ::area 
{ 
cout<<“n enter the radius of the circle :”; 
cin>>r; 
ar=r*r*3.14; 
cout<<“area of the circle :”<<ar; 
} 
Method 
Defined outside class
13 
OBJECT 
 Object: 
 a variable or an instance of a class 
 Objects may represent any entity ,such as a person , a cat 
a chair , a pen , a place , a bank account , a customer , a table 
of data ,etc. 
 for ex ,bike is an object .its characteristics are :its color 
is black ,Its engine is of 500cc ,Its company is Suzuki .Its 
behavior is to starting the engine ,changing the 
gear ,using the break, etc. 
 Declaration of an Object 
 Initiation of an Object
14 
WHAT IS AN OBJECT? 
OBJECT 
Operations 
Data 
set of methods 
(public member functions) 
internal state 
(values of private data members)
EXAMPLE: A “RABBIT” OBJECT 
 You could (in a game, for example) create an object 
representing a rabbit 
 It would have data: 
 How hungry it is 
 How frightened it is 
 Where it is 
 And methods: 
 eat, hide, run, dig
CONCEPT: CLASSES DESCRIBE OBJECTS 
 Every object belongs to (is an instance of) a class 
 An object may have fields, or variables 
 The class describes those fields 
 An object may have methods 
 The class describes those methods 
 A class is like a template, or cookie cutter
17 
DECLARATION OF AN OBJECT 
class Rectangle 
{ 
private: 
int width; 
int length; 
public: 
void set(int w, int l); 
int area(); 
}; 
main() 
{ 
Rectangle r1; 
Rectangle r2; 
r1.set(5, 8); 
cout<<r1.area()<<endl; 
r2.set(8,10); 
cout<<r2.area()<<endl; 
}
REASONS FOR OOP 
1. Simplify programming 
2. Interfaces 
 Information hiding: 
 Implementation details hidden within classes 
themselves 
3. Software reuse 
 Class objects included as members of 
other classes
THANK YOU

Más contenido relacionado

La actualidad más candente

class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 

La actualidad más candente (20)

Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
C++ classes
C++ classesC++ classes
C++ classes
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
 
class and objects
class and objectsclass and objects
class and objects
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 

Destacado

Tugas Aliyah
Tugas AliyahTugas Aliyah
Tugas Aliyah
Aliyahra
 
Tugas keisha
Tugas  keisha Tugas  keisha
Tugas keisha
keishaa17
 

Destacado (20)

098ca session7 c++
098ca session7 c++098ca session7 c++
098ca session7 c++
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Tugas Aliyah
Tugas AliyahTugas Aliyah
Tugas Aliyah
 
Fake Ayatollah khomeini's Teachings Are exposed
Fake Ayatollah khomeini's Teachings Are  exposedFake Ayatollah khomeini's Teachings Are  exposed
Fake Ayatollah khomeini's Teachings Are exposed
 
Pendudukan jepang di indonesia
Pendudukan jepang di indonesiaPendudukan jepang di indonesia
Pendudukan jepang di indonesia
 
πεταλούδες
πεταλούδεςπεταλούδες
πεταλούδες
 
Tugas keisha
Tugas  keisha Tugas  keisha
Tugas keisha
 
2014 การศึกษาเรียนรู้เรื่อง present-time-อารีรัตน์_การเพียร_5-5
2014 การศึกษาเรียนรู้เรื่อง present-time-อารีรัตน์_การเพียร_5-52014 การศึกษาเรียนรู้เรื่อง present-time-อารีรัตน์_การเพียร_5-5
2014 การศึกษาเรียนรู้เรื่อง present-time-อารีรัตน์_การเพียร_5-5
 
แบบทดสอบเตรียมความพร้อม ทดสอบก่อนเรียน2588
แบบทดสอบเตรียมความพร้อม ทดสอบก่อนเรียน2588แบบทดสอบเตรียมความพร้อม ทดสอบก่อนเรียน2588
แบบทดสอบเตรียมความพร้อม ทดสอบก่อนเรียน2588
 
11.แบบทดสอบวัดผลสัมฤทธิ์ทางการเรียนก่อนเรียน40ข้อ 7 pages
11.แบบทดสอบวัดผลสัมฤทธิ์ทางการเรียนก่อนเรียน40ข้อ 7 pages11.แบบทดสอบวัดผลสัมฤทธิ์ทางการเรียนก่อนเรียน40ข้อ 7 pages
11.แบบทดสอบวัดผลสัมฤทธิ์ทางการเรียนก่อนเรียน40ข้อ 7 pages
 
Tugas keisha
Tugas  keishaTugas  keisha
Tugas keisha
 
Η εφημερίδα της Β΄τάξης
Η εφημερίδα της Β΄τάξης Η εφημερίδα της Β΄τάξης
Η εφημερίδα της Β΄τάξης
 
pancasila
pancasilapancasila
pancasila
 
PAI
PAIPAI
PAI
 
Speaking ability – ตามมาฐานที่ชัดเจน2558
Speaking ability – ตามมาฐานที่ชัดเจน2558Speaking ability – ตามมาฐานที่ชัดเจน2558
Speaking ability – ตามมาฐานที่ชัดเจน2558
 
Fatwa's About Why Shia is Kafir or (Infidels) ? Part-1 From Shia Books
Fatwa's About Why Shia is Kafir or (Infidels) ? Part-1 From Shia BooksFatwa's About Why Shia is Kafir or (Infidels) ? Part-1 From Shia Books
Fatwa's About Why Shia is Kafir or (Infidels) ? Part-1 From Shia Books
 
The shias and the belief of the finality of the prophet-hood and insult of th...
The shias and the belief of the finality of the prophet-hood and insult of th...The shias and the belief of the finality of the prophet-hood and insult of th...
The shias and the belief of the finality of the prophet-hood and insult of th...
 
To καλοκαίρι και οι διακοπές
To καλοκαίρι και οι διακοπέςTo καλοκαίρι και οι διακοπές
To καλοκαίρι και οι διακοπές
 
เฉลย เรียนวันจันทร์ที่20-25 กันยายน2557ข้อสอบภาษาอังกฤษม.5-ปลายภาค255740ข้อ
เฉลย เรียนวันจันทร์ที่20-25 กันยายน2557ข้อสอบภาษาอังกฤษม.5-ปลายภาค255740ข้อเฉลย เรียนวันจันทร์ที่20-25 กันยายน2557ข้อสอบภาษาอังกฤษม.5-ปลายภาค255740ข้อ
เฉลย เรียนวันจันทร์ที่20-25 กันยายน2557ข้อสอบภาษาอังกฤษม.5-ปลายภาค255740ข้อ
 
Exposed Nawaz Sharif (Pml-n) Part-1
Exposed Nawaz Sharif (Pml-n) Part-1Exposed Nawaz Sharif (Pml-n) Part-1
Exposed Nawaz Sharif (Pml-n) Part-1
 

Similar a C++ And Object in lecture3

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 

Similar a C++ And Object in lecture3 (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
Classes
ClassesClasses
Classes
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
C++ classes
C++ classesC++ classes
C++ classes
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Class and object
Class and objectClass and object
Class and object
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
class c++
class c++class c++
class c++
 
Class and objects
Class and objectsClass and objects
Class and objects
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
 
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptxCHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

C++ And Object in lecture3

  • 1. DEV BHOOMI GROUP OF INSTITUTIONS SAHARANPUR Name : Saurabh Chauhan Class : M.C.A. 1ST (2013-15) Roll no : 1358614017 Topic : Classes and Object. 1 Sub To : Mr. Rakesh Kumar Sub By : Saurabh Chauhan
  • 2. C++ CLASSES & OBJECT WELCOME :
  • 3. OUTLINE :  Introduction of the class :  Characteristics of the class :  Format of the class :  Define a class type :  Implementing class methods :  Introduction of an Object :  Declaration of an object :  Reasons for OOP :  Thank you : 3
  • 4. INTRODUCTION OF THE CLASS :  A class is binding the data and methods.  A class is a collection of objects of similar type.  A class is an object factory (or producer ) that produces similar objects.  A class is just like an image and model and can say a template.  A class does not exists physically because it’s a image only in our mind  But object exists physically because a object is a real world entity i.e. a pen , a chair , a desk , a dog , a bike , a car ,a men etc  The class and object both are sub method of the OOP’s methodology 4
  • 5. WHY DO WE NEED TO HAVE CLASS ? Characteristics of the class :  Structures are public by default and classes are private by default.  Data more secure in the class.  Class reduce the complexity.  We can easy and well programming, if we use the class in our program . 5
  • 6. CLASSES IN C++  A class definition begins with the keyword class.  The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name { …. …. …. }; Any valid identifier Class body (data member + methods)
  • 7. CLASSES IN C++  Within the body, the keywords private: and public: specify the access level of the members of the class.  the default is private.  Usually, the data members of a class are declared in the private: section of the class and the member functions are in public: section.
  • 8. CLASSES IN C++  Format : class class_name { private: … … … public: … … … }; private members data or variables or characteristics Public members or methods Or behavior
  • 9. DEFINE A CLASS TYPE Header class class_name { access specifier : data ; access specifier : methods ; ... class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); }; 9 }; Body
  • 10. IMPLEMENTING CLASS METHODS  Class implementation: writing the code of class methods.  There are two ways: 1. Member functions defined outside class  Using Binary scope resolution operator (::)  “Ties” member name to class name  Uniquely identify functions of particular class  Different classes can have member functions with same name  Format for defining member functions ReturnType ClassName::MemberFunctionName( ){ … }
  • 11. IMPLEMENTING CLASS METHODS 2. Member functions(method) defined inside class  Do not need scope resolution operator, class name; class Circle { private: double r,ar; public: void area () { cin<<r ; ar=r*r*3.14; } cout<<“n a area of circle -”<<ar; }; Method Defined inside class
  • 12. // this is a program of area of circle // methods (Defined outside class) class Circle { private: double r,ar; public: void area(); // mehtod }; void circle ::area { cout<<“n enter the radius of the circle :”; cin>>r; ar=r*r*3.14; cout<<“area of the circle :”<<ar; } Method Defined outside class
  • 13. 13 OBJECT  Object:  a variable or an instance of a class  Objects may represent any entity ,such as a person , a cat a chair , a pen , a place , a bank account , a customer , a table of data ,etc.  for ex ,bike is an object .its characteristics are :its color is black ,Its engine is of 500cc ,Its company is Suzuki .Its behavior is to starting the engine ,changing the gear ,using the break, etc.  Declaration of an Object  Initiation of an Object
  • 14. 14 WHAT IS AN OBJECT? OBJECT Operations Data set of methods (public member functions) internal state (values of private data members)
  • 15. EXAMPLE: A “RABBIT” OBJECT  You could (in a game, for example) create an object representing a rabbit  It would have data:  How hungry it is  How frightened it is  Where it is  And methods:  eat, hide, run, dig
  • 16. CONCEPT: CLASSES DESCRIBE OBJECTS  Every object belongs to (is an instance of) a class  An object may have fields, or variables  The class describes those fields  An object may have methods  The class describes those methods  A class is like a template, or cookie cutter
  • 17. 17 DECLARATION OF AN OBJECT class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); }; main() { Rectangle r1; Rectangle r2; r1.set(5, 8); cout<<r1.area()<<endl; r2.set(8,10); cout<<r2.area()<<endl; }
  • 18. REASONS FOR OOP 1. Simplify programming 2. Interfaces  Information hiding:  Implementation details hidden within classes themselves 3. Software reuse  Class objects included as members of other classes