C++ program : To show the working of array of objects




#include<iostream.h>
#include<conio.h>
class record
{
   int rollno;
   char name[50];
   public:
   void get()
   {
      cout<<"\t Enter the Details\n Rollno : ";
      cin>>rollno;
      cout<<"Name : ";
      cin>>name;
   }
   void show()
   {
      cout<<"\t Record\n Rollno : "<<rollno<<"\n Name : "<<name;
   }
};

int main()
{
   clrscr();
   int x,L=1,k=0;
   record ob[20];
   do{
      cout<<"\t SELECT OPTION\n1.Add student record\n2.Show all record\n3.Exit";
      cin>>x;
      switch(x)
      {
         case 1: ob[k++].get(); break;
         case 2: for(int i=0;i<k;i++)
               ob[i].show();
            break;
         case 3: L=0; break;
      }
      getch();
   }while(L);
   return 0;
}


// Special Thanks to Gostkiller (  Midhul  )...

Class diagram 

(click image to view large)

 

 



0 comments:

Post a Comment