SlideShare a Scribd company logo
3
Most read
11
Most read
13
Most read
Array of Object & Pointer to Object
Made by: Patel Arpita V.
 Array is a collection of variable of same data types.
 Similarly, array of class objects means a collection of
objects of same types.
 Hence, an array having class type element is known as
array of object.
 syntax:
Class_name object_name [size];
#include<iostream.h>
#include<conio.h>
class employee
{
int age;
char name[20], post[20];
double salary;
public:
void getdata();
void putdata();
};
void employee::getdata()
{
cout<<"Name : ";
cin>>name;
cout<<"Age : ";
cin>>age;
cout<<"Post : ";
cin>>post;
cout<<"Salary : ";
cin>>salary;
}
void employee::putdata()
{
cout<<"Name : "<<name;
cout<<"nAge : "<<age;
cout<<"nPost : "<<post;
cout<<"nSalary : "<<salary;
}
int main()
{
int i;
clrscr();
employee emp[2];
for(i=1; i<2; i++)
{
cout<<"Get details :-n";
emp[i].getdata();
}
for(i=1; i<2; i++)
{
cout<<“nEmployee"<<i<<" :-n";
emp[i].putdata();
}
getch();
return 0;
}
array of object pointer in c++
 What is Pointer?
-Pointer means the variable that stores the address
of another variable.
 A pointer can point to an object created by class.
 Example: abc ob;
Here abc=class and ob=object of class abc.
 we can define pointer of type abc as below:
abc *ptr;
 Object pointers are useful in creating objects at run
time.
 We can also use an object pointer to access the public
members of class.
 We can access to member function of abc in two ways:
1)by using (.) dot operator
ex:- (*ptr).show();
2)by using () arrow operator
ex:- ptrshow();
 Example of Pointer to
object:
#include<iostream.h>
#include<conio.h>
class abc
{
int a,b,ADD;
public:
void getdata()
{
cout<<"Enter the values:" ;
cin>>a>>b;
}
void display()
{
ADD=a+b;
cout<<"Sum="<<ADD;
}
};
int main()
{
clrscr();
abc *ob;
(*ob).getdata();
ob->display();
getch();
return 0;
}
array of object pointer in c++
 Example:
abc *ptr =new abc[10];
here, abc=class
ptr=pointer
new=memory management operator
 Example of array of object pointer:
#include<iostream.h>
#include<conio.h>
class abc
{
int code;
float price;
public:
void getdata(int a,int b)
{
code=a;
price=b;
}
void show()
{
cout<<"nCode:"<<code;
cout<<"nPrice:"<<price;
}
};
const int size=2;
int main()
{
clrscr();
abc *ptr=new abc[size];
abc *d=ptr;
int x,i;
float y;
for(i=1;i<size;i++)
{
cout<<"Input the value code & price:"<<i<<"n";
cin>>x>>y;
ptr->getdata(x,y);
ptr++;
}
for(i=1;i<size;i++)
{
cout<<"nitem:"<<i;
d->show();
d++;
}
getch();
return 0;
}
array of object pointer in c++
array of object pointer in c++
array of object pointer in c++

More Related Content

What's hot (20)

PPT
Function overloading(c++)
Ritika Sharma
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPT
Class and object in C++
rprajat007
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPTX
Inline function
Tech_MX
 
PPTX
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
PPTX
Scope rules : local and global variables
sangrampatil81
 
PPT
Operator Overloading
Nilesh Dalvi
 
PPTX
Data types in java
HarshitaAshwani
 
PPTX
Pointers in c++
sai tarlekar
 
PDF
Constructors and destructors
Nilesh Dalvi
 
PPTX
This pointer
Kamal Acharya
 
PPTX
classes and objects in C++
HalaiHansaika
 
PDF
Object oriented approach in python programming
Srinivas Narasegouda
 
PPTX
class and objects
Payel Guria
 
PPTX
Operators and expressions in C++
Neeru Mittal
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Pointer in C++
Mauryasuraj98
 
PPTX
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
PPTX
Operators in java presentation
kunal kishore
 
Function overloading(c++)
Ritika Sharma
 
INLINE FUNCTION IN C++
Vraj Patel
 
Class and object in C++
rprajat007
 
07. Virtual Functions
Haresh Jaiswal
 
Inline function
Tech_MX
 
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
Scope rules : local and global variables
sangrampatil81
 
Operator Overloading
Nilesh Dalvi
 
Data types in java
HarshitaAshwani
 
Pointers in c++
sai tarlekar
 
Constructors and destructors
Nilesh Dalvi
 
This pointer
Kamal Acharya
 
classes and objects in C++
HalaiHansaika
 
Object oriented approach in python programming
Srinivas Narasegouda
 
class and objects
Payel Guria
 
Operators and expressions in C++
Neeru Mittal
 
Classes, objects in JAVA
Abhilash Nair
 
Pointer in C++
Mauryasuraj98
 
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Operators in java presentation
kunal kishore
 

Similar to array of object pointer in c++ (20)

PPTX
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
PPT
Presentation
manogallery
 
PPTX
OOP-Lecture-05 (Constructor_Destructor).pptx
SirRafiLectures
 
PDF
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
DOC
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
PPT
Csharp4 arrays and_tuples
Abed Bukhari
 
PPTX
OO in JavaScript
Gunjan Kumar
 
PPTX
ActionScript3 collection query API proposal
Slavisa Pokimica
 
PPTX
11. session 11 functions and objects
Phúc Đỗ
 
PPTX
Data Binding Intro (Windows 8)
Gilbok Lee
 
PPT
Tips and Tricks of Developing .NET Application
Joni
 
PPT
Java căn bản - Chapter10
Vince Vo
 
PPSX
What's new in C# 6 - NetPonto Porto 20160116
Paulo Morgado
 
PDF
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
Andres Almiray
 
PDF
Classes and objects
Kamal Acharya
 
PDF
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
PDF
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
PPT
Arrays
archikabhatia
 
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Presentation
manogallery
 
OOP-Lecture-05 (Constructor_Destructor).pptx
SirRafiLectures
 
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
Csharp4 arrays and_tuples
Abed Bukhari
 
OO in JavaScript
Gunjan Kumar
 
ActionScript3 collection query API proposal
Slavisa Pokimica
 
11. session 11 functions and objects
Phúc Đỗ
 
Data Binding Intro (Windows 8)
Gilbok Lee
 
Tips and Tricks of Developing .NET Application
Joni
 
Java căn bản - Chapter10
Vince Vo
 
What's new in C# 6 - NetPonto Porto 20160116
Paulo Morgado
 
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Andres Almiray
 
Classes and objects
Kamal Acharya
 
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
Ad

Recently uploaded (20)

PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Design Thinking basics for Engineers.pdf
CMR University
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Ad

array of object pointer in c++

  • 1. Array of Object & Pointer to Object Made by: Patel Arpita V.
  • 2.  Array is a collection of variable of same data types.  Similarly, array of class objects means a collection of objects of same types.  Hence, an array having class type element is known as array of object.  syntax: Class_name object_name [size];
  • 3. #include<iostream.h> #include<conio.h> class employee { int age; char name[20], post[20]; double salary; public: void getdata(); void putdata(); }; void employee::getdata() { cout<<"Name : "; cin>>name; cout<<"Age : "; cin>>age; cout<<"Post : "; cin>>post; cout<<"Salary : "; cin>>salary; } void employee::putdata() { cout<<"Name : "<<name; cout<<"nAge : "<<age; cout<<"nPost : "<<post; cout<<"nSalary : "<<salary; } int main() { int i; clrscr(); employee emp[2]; for(i=1; i<2; i++) { cout<<"Get details :-n"; emp[i].getdata(); } for(i=1; i<2; i++) { cout<<“nEmployee"<<i<<" :-n"; emp[i].putdata(); } getch(); return 0; }
  • 5.  What is Pointer? -Pointer means the variable that stores the address of another variable.
  • 6.  A pointer can point to an object created by class.  Example: abc ob; Here abc=class and ob=object of class abc.  we can define pointer of type abc as below: abc *ptr;  Object pointers are useful in creating objects at run time.
  • 7.  We can also use an object pointer to access the public members of class.  We can access to member function of abc in two ways: 1)by using (.) dot operator ex:- (*ptr).show(); 2)by using () arrow operator ex:- ptrshow();
  • 8.  Example of Pointer to object: #include<iostream.h> #include<conio.h> class abc { int a,b,ADD; public: void getdata() { cout<<"Enter the values:" ; cin>>a>>b; } void display() { ADD=a+b; cout<<"Sum="<<ADD; } }; int main() { clrscr(); abc *ob; (*ob).getdata(); ob->display(); getch(); return 0; }
  • 10.  Example: abc *ptr =new abc[10]; here, abc=class ptr=pointer new=memory management operator
  • 11.  Example of array of object pointer: #include<iostream.h> #include<conio.h> class abc { int code; float price; public: void getdata(int a,int b) { code=a; price=b; } void show() { cout<<"nCode:"<<code; cout<<"nPrice:"<<price; } }; const int size=2; int main() { clrscr(); abc *ptr=new abc[size]; abc *d=ptr; int x,i; float y; for(i=1;i<size;i++) { cout<<"Input the value code & price:"<<i<<"n"; cin>>x>>y; ptr->getdata(x,y); ptr++; } for(i=1;i<size;i++) { cout<<"nitem:"<<i; d->show(); d++; } getch(); return 0; }