SlideShare a Scribd company logo
1 of 13
C++
OBJECTS
Objects
 In C++, the class variables are called objects.
 An object is an instance of the class.
 Class is the passive entity while object is an
active entity.
Creating an object of a Class
 Declaring a variable of a class type creates an object. You can have
many variables of the same type (class).
 The memory space for the objects is allocated when they are
declared.
 When an object is created, space for that object is allocated in
primary memory.
 Space for member variables is allocated separately for each object.
Syntax
class_name object_name;
 Example: Things t1;
 To create multiple objects: Things t1,t2,t3;
 There can be multiple objects created from one class.
Objects…
 The objects can also be created when a class is defined by
placing their names immediately after the closing braces
like
Class Things
{
private:
… … …;
public:
… … …;
}t1,t2,t3;
Accessing Class Members
Operators to access class members
Identical to those for structs
Dot member selection operator (.)
Object
Reference to object
With objects we can access the public members of a
class using a dot operator.
Example:
#include <iostream.h>
class Box
{
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height;// Height of a box
};
Void main( )
{
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
double volume = 0.0; // Store the volume of a box here
// box 1 specification
Box1.height = 5.0;
Box1.length = 6.0;
Box1.breadth = 7.0;
// box 2 specification
Box2.height = 10.0;
Box2.length = 12.0;
Box2.breadth = 13.0;
// volume of box 1
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
// volume of box 2
volume = Box2.height * Box2.length * Box2.breadth;
cout << "Volume of Box2 : " << volume <<endl;
}
When the above code is compiled and executed, it produces the following result:
Volume of Box1 : 210
Volume of Box2 : 1560
Array of Objects
 Arrays of variables of type class are called arrays of objects.
Example:
class Employee
{
char name[20];
float age;
public:
void getdata(void);
void putdata(void);
};
For example:
Employee manager[3]; //array of manager
Employee worker[15]; // array of worker
Employee peon[2]; // array of peon
 The array manager contains three objects.
 The array worker contains 15 objects.
 The array peon contains two objects.
 They all contains the objects of the Employee class.
Objects as function argument
 Object can be used as a function argument. This can be done in two
method ways:
• A copy of the entire object is passed to the function.
• Only the address of the object is transferred to the function.
 The first method is called pass-by-value.
 The second method is called pass-by-reference.
 Pass-by-reference method is more effective.
 A function can also return an object.
//value.cpp
#include <iostream.h>
class test
{
int a;
public:
void set(test x)
{
x.a=5;
cout<<"a="<<x.a;
}
void show(test y)
{
cout<<"a="<<y.a;
}
};
void main()
{
test t;
t.set(t);
t.show(t);
}
//reference.cpp
#include <iostream.h>
class test
{
int a;
public:
void set(test *x)
{
x->a=5;
cout<<"a="<<x->a;
}
void show(test *y)
{
cout<<"a="<<y->a;
}
};
void main()
{
test t;
t.set(&t);
t.show(&t);
Please wait...
LOADING
Object

More Related Content

Viewers also liked

Organizational communication
Organizational communication Organizational communication
Organizational communication kashifdtm
 
Analisis vectrial
Analisis vectrialAnalisis vectrial
Analisis vectrialEAFB
 
Transister Tester Project Report with Circuit Diagram
Transister Tester Project Report with Circuit DiagramTransister Tester Project Report with Circuit Diagram
Transister Tester Project Report with Circuit DiagramTeam Kuk
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์แบบเสนอโครงร่างโครงงานคอมพิวเตอร์
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์Fah Fah
 
Resolving Conflict At Work Place
Resolving Conflict At Work PlaceResolving Conflict At Work Place
Resolving Conflict At Work PlaceRajesh Patel
 
Fu 2 semana del 23 al 27 de enero
Fu 2 semana del 23 al 27 de eneroFu 2 semana del 23 al 27 de enero
Fu 2 semana del 23 al 27 de eneroDelfina Moroyoqui
 
OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Kaggle boschコンペ振り返り
Kaggle boschコンペ振り返りKaggle boschコンペ振り返り
Kaggle boschコンペ振り返りKeisuke Hosaka
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
How to Master Difficult Conversations at Work – Leader’s Guide
How to Master Difficult Conversations at Work – Leader’s GuideHow to Master Difficult Conversations at Work – Leader’s Guide
How to Master Difficult Conversations at Work – Leader’s GuidePiktochart
 

Viewers also liked (16)

Taller1
Taller1Taller1
Taller1
 
Organizational communication
Organizational communication Organizational communication
Organizational communication
 
Analisis vectrial
Analisis vectrialAnalisis vectrial
Analisis vectrial
 
Transister Tester Project Report with Circuit Diagram
Transister Tester Project Report with Circuit DiagramTransister Tester Project Report with Circuit Diagram
Transister Tester Project Report with Circuit Diagram
 
Vibhuti_Kumar
Vibhuti_KumarVibhuti_Kumar
Vibhuti_Kumar
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์แบบเสนอโครงร่างโครงงานคอมพิวเตอร์
แบบเสนอโครงร่างโครงงานคอมพิวเตอร์
 
Resolving Conflict At Work Place
Resolving Conflict At Work PlaceResolving Conflict At Work Place
Resolving Conflict At Work Place
 
Fu 2 semana del 23 al 27 de enero
Fu 2 semana del 23 al 27 de eneroFu 2 semana del 23 al 27 de enero
Fu 2 semana del 23 al 27 de enero
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Kaggle boschコンペ振り返り
Kaggle boschコンペ振り返りKaggle boschコンペ振り返り
Kaggle boschコンペ振り返り
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
How to Master Difficult Conversations at Work – Leader’s Guide
How to Master Difficult Conversations at Work – Leader’s GuideHow to Master Difficult Conversations at Work – Leader’s Guide
How to Master Difficult Conversations at Work – Leader’s Guide
 

Similar to Object

5.CLASSES.ppt(MB)2022.ppt .
5.CLASSES.ppt(MB)2022.ppt                       .5.CLASSES.ppt(MB)2022.ppt                       .
5.CLASSES.ppt(MB)2022.ppt .happycocoman
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in javaRaja Sekhar
 
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88Mahmoud Samir Fayed
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Boro
 
Object oriented design
Object oriented designObject oriented design
Object oriented designlykado0dles
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++Prof Ansari
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3mohamedsamyali
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMambikavenkatesh2
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfstudy material
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 

Similar to Object (20)

Class and object
Class and objectClass and object
Class and object
 
5.CLASSES.ppt(MB)2022.ppt .
5.CLASSES.ppt(MB)2022.ppt                       .5.CLASSES.ppt(MB)2022.ppt                       .
5.CLASSES.ppt(MB)2022.ppt .
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
java classes
java classesjava classes
java classes
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
OOP C++
OOP C++OOP C++
OOP C++
 
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Object oriented design
Object oriented designObject oriented design
Object oriented design
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
Class and object
Class and objectClass and object
Class and object
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Object

  • 2. Objects  In C++, the class variables are called objects.  An object is an instance of the class.  Class is the passive entity while object is an active entity.
  • 3. Creating an object of a Class  Declaring a variable of a class type creates an object. You can have many variables of the same type (class).  The memory space for the objects is allocated when they are declared.  When an object is created, space for that object is allocated in primary memory.  Space for member variables is allocated separately for each object.
  • 4. Syntax class_name object_name;  Example: Things t1;  To create multiple objects: Things t1,t2,t3;  There can be multiple objects created from one class.
  • 5. Objects…  The objects can also be created when a class is defined by placing their names immediately after the closing braces like Class Things { private: … … …; public: … … …; }t1,t2,t3;
  • 6. Accessing Class Members Operators to access class members Identical to those for structs Dot member selection operator (.) Object Reference to object With objects we can access the public members of a class using a dot operator.
  • 7. Example: #include <iostream.h> class Box { public: double length; // Length of a box double breadth; // Breadth of a box double height;// Height of a box }; Void main( ) { Box Box1; // Declare Box1 of type Box Box Box2; // Declare Box2 of type Box double volume = 0.0; // Store the volume of a box here // box 1 specification Box1.height = 5.0; Box1.length = 6.0; Box1.breadth = 7.0; // box 2 specification Box2.height = 10.0; Box2.length = 12.0; Box2.breadth = 13.0; // volume of box 1 volume = Box1.height * Box1.length * Box1.breadth; cout << "Volume of Box1 : " << volume <<endl; // volume of box 2 volume = Box2.height * Box2.length * Box2.breadth; cout << "Volume of Box2 : " << volume <<endl; } When the above code is compiled and executed, it produces the following result: Volume of Box1 : 210 Volume of Box2 : 1560
  • 8. Array of Objects  Arrays of variables of type class are called arrays of objects. Example: class Employee { char name[20]; float age; public: void getdata(void); void putdata(void); };
  • 9. For example: Employee manager[3]; //array of manager Employee worker[15]; // array of worker Employee peon[2]; // array of peon  The array manager contains three objects.  The array worker contains 15 objects.  The array peon contains two objects.  They all contains the objects of the Employee class.
  • 10. Objects as function argument  Object can be used as a function argument. This can be done in two method ways: • A copy of the entire object is passed to the function. • Only the address of the object is transferred to the function.  The first method is called pass-by-value.  The second method is called pass-by-reference.  Pass-by-reference method is more effective.  A function can also return an object.
  • 11. //value.cpp #include <iostream.h> class test { int a; public: void set(test x) { x.a=5; cout<<"a="<<x.a; } void show(test y) { cout<<"a="<<y.a; } }; void main() { test t; t.set(t); t.show(t); } //reference.cpp #include <iostream.h> class test { int a; public: void set(test *x) { x->a=5; cout<<"a="<<x->a; } void show(test *y) { cout<<"a="<<y->a; } }; void main() { test t; t.set(&t); t.show(&t);