20 February, 2013

C++ Program To Display Object Details Using Access Modifiers.

This Post Contains A C++ Program To Display Object Details Using Access Modifiers With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Access Modifiers' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.

# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Display Object Details Using Access Modifiers.

# include < iostream.h >
# include < conio.h >

class ABC
{
        private : int Num;
     
        protected : int data;

        public : void getdata()
                    {
                           cout  <<  "  Enter 1st Number  :  ";
                           cin  >>  Num;
                           cout  <<  "  Enter 2nd Number  :  ";
                           cin  >>  data;
                    }
                    void putdata()
                    {
                           cout  <<  "  The 1st Number Entered Is  :  "  <<  Num;
                           cout  <<  "  The 2nd Number Entered Is  :  "  <<  data;
                    }
};


void main()
{
       clrscr();

       ABC obj;
       obj.getdata();
       obj.putdata();

       getch();
}

Output :

Enter 1st Number  :  10

Enter 2nd Number  :  20

The 1st Number Entered Is  :  10

The 2nd Number Entered Is  :  20
      




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.