Information Hiding

Example of a program with a little information?hiding contained in it.

/*******************************************************
*     MYCPLUS Sample Code - https://www.mycplus.com     *
*                                                     *
*   This code is made available as a service to our   *
*      visitors and is provided strictly for the      *
*               purpose of illustration.              *
*                                                     *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/
#include 

class one_datum {
   int data_store;
public:
   void set(int in_value);
   int get_value(void);
};


void one_datum::set(int in_value)
{
   data_store = in_value;
}


int one_datum::get_value(void)
{
   return data_store;
}


main()
{
one_datum dog1, dog2, dog3;
int piggy;


   dog1.set(12);
   dog2.set(17);
   dog3.set(-13);
   piggy = 123;


// dog1.data_store = 115;      This is illegal in C++
// dog2.data_store = 211;      This is illegal in C++


   cout 
M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post