Tuesday, 21 February 2012

Example of Class in c++



/*class in c++*/


#include<iostream>


using namespace std;
    class book
    {
      private:   //private function member cnt use by other class
          int bookno;
         char name[];
      public:   //public function member use by other class
         void GetData()
           {
              cout<<"enter the detail"<<endl;
              cout<<"enter book no."<<endl;
             
cin>>bookno;
              cout<<"enter author name"<<endl;
              cin>>name;
           }
  void DisplayData()
  {
    cout<<"entered record is:"<<endl;
    cout<<"book no"<<bookno<<endl;
    cout<<"author name"<<name<<endl;
   }
 };
   int main()
    {
       class book obj;  //create an object for class
      obj.GetData();
       obj.DisplayData();
       return 0;
    }//end of main

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}