Page 128 - C++
P. 128

class marks: private personal
                          {
                              float m[5];
                          protected:
                              char grade[5];
                          public:
                              marks();
                              void mentry();
                              void mdisplay();
                          };
                          class result: public marks
                          {  float total, avg;
                          public:
                              result();
                               char finalgrade, comments[20];
                              void rcalculate();
                              void rdisplay();
                          };
                     i)   Which type of inheritance is shown in the above example?

                       Ans: Multilevel inheritance
                     ii)   Write the names of the data members which are directly accessible from

                          objects of class result.
                       Ans: finalgrade, comments
                    iii)   Write the names of those data members, which can be directly accessible

                          from the mentry() function of class marks.
                       Ans: grade, m, name

                    iv)   How many bytes will be required by an object belonging to class result?
                       Ans: 79


               3.      a)  Define  a  function  change(int  a[20],  int N)  to  repositions  all  elements  of
                       array  by  shifting  each  of  them  to  the  next  position  and  by  shifting  the  last

                       element to the first position.                                                    3

               Ans:    void change(int a[20], int n)
                       {
                              int t=a[n-1];
                              for( int i=0; i<n-1; i++)
                                     a[i+1]=a[i];
                              a[0]=t;

                       }








               XII / Comp. Sc.                                                             Page 7 of 17
   123   124   125   126   127   128   129   130   131   132   133