Thursday, November 28, 2013

C++: An example (source code) of class with member functions.

// C++ Source code
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

class flight
{
long flightCode;
   char description[25];

   public:
    void addInfo()
      {
       cin>>flightCode;
         gets(description);
      }

      void showInfo()
      {
         cout<<endl<<"*** OUTPUT ***"<<endl;
       cout<<flightCode<<":"<<description<<endl;
      }
};

void main()
{
flight f;
   f.addInfo();
   f.showInfo();

   getch();
}

OUTPUT

1234.5678
Welcome to my C++ Source Codes Page

*** OUTPUT ***
1234:Welcome to my C++ Source Codes Page

No comments:

Post a Comment