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

PPTX
Inheritance in java
PPT
Function overloading(c++)
PPTX
classes and objects in C++
PPTX
07. Virtual Functions
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPT
Operator Overloading
PPTX
Constructor in java
PPTX
Constructor in java
Inheritance in java
Function overloading(c++)
classes and objects in C++
07. Virtual Functions
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Operator Overloading
Constructor in java
Constructor in java

What's hot (20)

PPTX
Constructor in java
PPTX
Classes, objects in JAVA
PPT
C++ classes tutorials
PPTX
Java program structure
PDF
Constructors and Destructors
PPTX
Types of Constructor in C++
PPTX
Inheritance in c++
PPTX
Abstract class in c++
PDF
Constructors and destructors
PPTX
Java package
PPTX
Inline Functions and Default arguments
PPTX
Member Function in C++
PDF
PPTX
Data types in c++
PPTX
Static Data Members and Member Functions
PPTX
OPERATOR OVERLOADING IN C++
PPTX
JAVA AWT
PPTX
Functions in c++
PPT
Class and object in C++
PPT
Basic concept of OOP's
Constructor in java
Classes, objects in JAVA
C++ classes tutorials
Java program structure
Constructors and Destructors
Types of Constructor in C++
Inheritance in c++
Abstract class in c++
Constructors and destructors
Java package
Inline Functions and Default arguments
Member Function in C++
Data types in c++
Static Data Members and Member Functions
OPERATOR OVERLOADING IN C++
JAVA AWT
Functions in c++
Class and object in C++
Basic concept of OOP's
Ad

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

PPTX
C++ - UNIT_-_IV.pptx which contains details about Pointers
PPTX
Array of objects.pptx
PPT
Data structure and problem solving ch05.ppt
PPTX
pointers.pptx
PDF
polymorphism in c++ with Full Explanation.
PPTX
Structured Languages
DOC
Brief Summary Of C++
PPTX
Pointer in C++
PPT
Classes cpp intro thomson bayan college
PPT
C++ Programming Course
PPT
Ccourse 140618093931-phpapp02
PPTX
OOPS 22-23 (1).pptx
TXT
Advance C++notes
PPTX
9781337102087 ppt ch12
PDF
C++ computer language chapter 4 pointers.pdf
PPT
C96e1 session3 c++
PPTX
Pointer and polymorphism
PDF
oopm 2.pdf
PPT
Pointers_in_c.pptfffgfggdggffffrreeeggttr
C++ - UNIT_-_IV.pptx which contains details about Pointers
Array of objects.pptx
Data structure and problem solving ch05.ppt
pointers.pptx
polymorphism in c++ with Full Explanation.
Structured Languages
Brief Summary Of C++
Pointer in C++
Classes cpp intro thomson bayan college
C++ Programming Course
Ccourse 140618093931-phpapp02
OOPS 22-23 (1).pptx
Advance C++notes
9781337102087 ppt ch12
C++ computer language chapter 4 pointers.pdf
C96e1 session3 c++
Pointer and polymorphism
oopm 2.pdf
Pointers_in_c.pptfffgfggdggffffrreeeggttr
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Construction Project Organization Group 2.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPT
Project quality management in manufacturing
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Well-logging-methods_new................
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Welding lecture in detail for understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
OOP with Java - Java Introduction (Basics)
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Construction Project Organization Group 2.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Project quality management in manufacturing
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
bas. eng. economics group 4 presentation 1.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Well-logging-methods_new................
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Foundation to blockchain - A guide to Blockchain Tech
Model Code of Practice - Construction Work - 21102022 .pdf
Welding lecture in detail for understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Digital Logic Computer Design lecture notes
Embodied AI: Ushering in the Next Era of Intelligent Systems
Operating System & Kernel Study Guide-1 - converted.pdf

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; }