OBJECTS AND CLASSES


               Object oriented programming (OOP) is a particular conceptual approach to designing programs, and
               C++ has enhanced C with features that ease the way to applying that approach. The most important 
               OOP features are these:      
                                              • Abstraction           
                               • Encapsulation and data hiding              
                              • Polymorphism       
                               • Inheritance            
                              • Reusable code
                The class is the single most important C++ enhancement for implementing these 
                features and tying together. 
 
               3.1 Procedural and Object-Oriented Programming:
 
               Although we have explored the OOP perspective on programming ever so often, we've usually stuck 
               pretty close to the standard  procedural approach of  languages  such as C, Pascal, and BASIC. 
               Let's  look  at an  example that clarifies  how the OOP outlook differs from that of procedural   
               programming. You first concentrate on the procedures you will follow and then think about how to
               represent the data.You begin by thinking about the data. Furthermore, you think about the data 
               not only in terms of how  to represent it, but also in terms of how it's to be used. You   
               concentrate on  the object,as the user  perceives it,thinking about the  need  to describe the  
               object   the  object and the operations that will describe the user's interaction with the data.
               After   you develop a description of that interface,you move on to  decide how to implement the
               interface  and  data  storage.  Finally, you put together a program to use your new design.
 
               Abstraction:Abstraction is the crucial step of representing information in terms of 
               its interface with the user. That is, you abstract the essential operational features of a problem
               and express a solution in   those terms. The interface describes how the user initializes,updates,
               and displays the data. From abstraction,it is a short step to the user-defined type, which in C++ 
               is a class design that implements that interface.
 
               Class: The class is the C++ vehicle for translating an abstraction to a user-defined 
               type.  It combines data representation and methods for manipulating that data  into one neat  package.
               An object has the same relationship to a class that a variable has to a data type.An object is said to
               be an instance of a class, in the same way  my 1954  Chevrolet is an instance of a vehicle. A class is
               a way to  bind the  data  and its  associated functions together.It  allows the data (and functions)to
               be hidden,if necessary,from external use.When defining a class we are creating a new abstract data type 
               that can be treated like any other built-in data type. 
               Generally, a class specification has two parts: 
 
               1. Class declaration 
               2. Class function definitions 
               The class declaration describes the type and scope of its members.The class function definitions
               describe how the class functions are implemented. 
               The general form of a class declaration is:
 
               class  class_name
               {
                               private: 
                               variable declarations; 
                               function declarations; 
                               public: 
                               variable declarations;
                               function declarations; 
               };
 
               The class declaration similar to struct declaration.The keyword class specifies that what follows
               is an  abstract data  of type  class_name.  The body of a class is  enclosed within  braces and
               terminated  by a  semicolon. The class body  contains the declaration of variables and functions. 
               These functions and variables are collectively called members.They are usually grouped under two 
               sections; namely,  private and  public to denote which members are private and which are public.  
               These keywords are known as visibility labels. 
 
               The members that have been declared as private can be accessed only from within the class.On the
               other hand, public members can be accessed from  outside the class  also. The data hiding is the 
               key feature of OOP.The use of the keyword private is optional.By default,the members are private. 
               Such a class is completely hidden from the outside world and does not serve any purpose.
 
               The variables declared inside the class are known as data members and the functions are known as
               member functions.Only the member functions can have access to the private members and functions. 
               However, the public members  (both  functions and data) can  be accessed from outside the class.  
               The binding of data and functions together into a single class-type  variable is  referred to as 
               encapsulation.
 
               A Simple Class Example: A typical class declaration would look like: 
 
               class item 
               { 
                               int number;              // variables declaration
                               float cost;                // private by default
                               public: 
                               void getdata(int a, float b);      // functions declaration 
                               void putdata(void);                 // using prototype 
               }
 
               We usually give a class some meaningful name, such as item. This name  now   becomes a  new type 
               identifier that can be used to declare instances of that class type. The class item contains two
               data members and two function members. The data members are  private by default while  both the 
               functions are public by declaration. The function getdata( ) can be used to assign values to the
               member variables number and cost, and putdata( ) for  displaying their values. These  functions 
               provide the only access to the data members from outside the class. This means  that  the data
               cannot  be  accessed by  any function  that is not a member of the class item. Note that the
               functions are declared,not defined.Actual function definitions will appear later in the program. 
               The data members are usual private and the member function