Page 229 - C++
P. 229

2.    (a)   Differentiate between private and public members of a class in context of Object
                         Oriented Programming. Also give a suitable example illustrating accessibility/non-
                         accessibility of each using a class and an object in C++.                        2


                   (b)  Observe the following C++ code and answer the questions (i) and (ii).

                         Note : Assume all necessary files are included.
                         class EXAM

                         {
                              long Code;

                              char EName[20];

                              float Marks;
                         public:

                              EXAM()                         //Member Function 1

                              {
                                    Code=100;strcpy(EName,"Noname");Marks=0;

                              }

                              EXAM(EXAM &E)                  //Member Function 2
                              {

                                    Code=E.Code+1;

                                    strcpy(EName,E.EName);
                                    Marks=E.Marks;

                              }

                         };
                         void main()

                         {

                              _____________                  //Statement 1
                              _____________                  //Statement 2

                         }

                         (i)   Which  Object  Oriented  Programming  feature  is  illustrated  by  the  Member
                              Function 1 and Member Function 2 together in the class EXAM ?               1

                         (ii)  Write  Statement  1  and  Statement  2  to  execute  Member  Function  1  and
                              Member Function 2 respectively.                                             1

             91/1                                          4
   224   225   226   227   228   229   230   231   232   233   234