How to Make Array of Object in C++

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 problems.

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 on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment