Friday, 6 February 2015

Array of Object in C++

Structure of the Problem Requirements 

We used array because we can't have too much variables names for integers(reduce the readability of code if declare variable for each integer  ), Secondly we can put values sequentially in array. Now consider if we need to create hundred object then ?. To handle this situation we need to create array of object. Just like arrays , array of object also used to simplify the large problem.

Source Code

#include<iostream>
using namespace std;
class LEP_Member
{
   public:
char names [25];
int batch_no;
void Emp_names ()
{
cout<<" \n Enter the Name of Employe \n ";
cin>>names;
cout<<" \n Enter the Batch No \n ";
cin>>batch_no;
}
void display ()
{
cout<<" \n Employe Name : "<<names;
cout<<" \n Employe Batch : "<<batch_no;
}
};

int main ()
{
cout<<" \t \t \t Array of Object \n \n ";
LEP_Member LEP [5];
for ( int i = 0; i < 5;i++ )
{
LEP[i].Emp_names();
}
for ( int i = 0; i < 5;i++)
{
LEP[i]. display();
}
}

Output of the Program

Array of Object in C++

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment