C and C++ Programming Resources

Custom Search

Information/Data Protection

Example of data protection in a very simple program.

/*******************************************************
*     MYCPLUS Sample Code - http://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 <iostream.h>


class rectangle {              // A simple class
   int height;
   int width;
public:
   int area(void);             // with two methods
   void initialize(int, int);
};


int rectangle::area(void)      //Area of a rectangle
{
   return height * width;
}


void rectangle::initialize(int init_height, int init_width)
{
   height = init_height;
   width = init_width;
}



struct pole {
   int length;
   int depth;
};





main()
{
rectangle box, square;
pole flag_pole;


// box.height = 12;
// box.width = 10;
// square.height = square.width = 8;


   box.initialize(12, 10);
   square.initialize(8, 8);


   flag_pole.length = 50;
   flag_pole.depth = 6;


   cout << "The area of the box is " <<
                       box.area() << "\n";
   cout << "The area of the square is " <<
                       square.area() << "\n";
// cout << "The funny area is " <<
//                     area(square.height, box.width) << "\n";
// cout << "The bad area is " <<
//                     area(square.height, flag_pole.depth) << "\n";
}



// Result of execution
//
// The area of the box is 120
// The area of the square is 64

Tags: ,

There are No Comments to this post. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response or TrackBack from your own site.


Leave a Reply

You must be logged in to post a comment.