by Dinesh Thakur Category: Classes in C++

 

#include <iostream.h>

#include <conio.h>
#include <string.h>
const int size=10;
class airlines
{
         public:
                           char flight_no[size];
                           char source[size];
                           char dest[size];
                           int fare;
         public:
                          airlines( char* fl,char* s,char* d,int f)
                     {
                          strcpy(flight_no,fl);
                          strcpy( source,s);
                          strcpy( dest,d);
                          fare=f;
                     }
                          void describe()
                      {
                           cout<<"\n" ;
                           cout<<"Flight Number :"<<flight_no<<endl;
                           cout<<"Source : "<<source<<endl;
                           cout<<"Destination : "<<dest<<endl;
                           cout<<"Fare : "<<fare<<endl;
                      }
};
                void main( )
          {
                     clrscr();
                     airlines a1(" AI007", "Delhi", "Bombay" ,6000);
                     airlines a2(" AI008", "Delhi", "Madras" ,8000);
                     a1.describe();
                     a2.describe();
                     getch();
          }

multiple objects for a class



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles