Page 213 - C++
P. 213

Member Functions
              •  A constructor function to initialize Type as ‘O’ and Fare(Freight) as 500
              •  A function to calculate Fare as per the following criteria:

              Type            Fare
              ‘O’             15 * Distance
              ‘E’             20 * Distance
              ‘L’             24 * Distance
              •  A function Allocate( ) to allow user to enter values for Busno, From, To, Type and Distance. Also this
                    function should call CalcFare( ) to calculate Fare.
              •  A function Show( ) to display the content of all the data members on screen.                [4]

      (d) Consider the following C++ code and answer the questions from (i) to (iv):                         [4]
               class Personal
               {
                       int    Class, Rno;
                       char *  Section;
                    protected :
                       char *  Name;
                    public :
                       personal( );
                       void pentry( );
                       void Pdisplay( );
               };
               class Marks : private Personal
               {
                       float   M[5];
                    protected :
                       char   Grade[5];
                    public :
                       Marks( );
                       void Mentry( );
                       void Mdisplay( );
               };
               class Result  : public Marks
               {
                       float   Total, Agg;
                    public :
                       char   FinalGrade, comments[20];
                       Result( );
                       void Rcalculate( );
                       void Rdisplay( );
               };
           (i)   Which type of inheritance is shown in the above example?
           (ii)   Write the names of those data members, which can be directly accessed from the objects of class Result.
           (iii)   Write the names of those member functions which can be directly accessed from the objects of class Result.
           (iv)   Write the names of those data members, which can be directly accessed from the Mentry( ) function of
                       class Marks.

   Q.3(a)Write a finction TRANSFER(int A[ ] , int B[ ] , int size) in C++  to copy the elements of array A into array B in such a
               way that all the negative elements of A appear in the beginning of B , followed by all the positive elements , followed by
               all the zeroes maintaining their respective orders in array A . For example :
          If the contents of array A are :-               7 , -23 , 3 , 0 , -8 , -3 , 4 , 0
               The contents of array B should be         -23 , -8 , -3 , 7 , 3 , 4 , 0 , 0                   [3]
         (b) Each element of the array A[8][6] is stored along the column using 4 bytes of memory . If the element A[2][4] is stored
               at location 936 , find the address of A[5][1] .                                               [3]

                                                                                                                   3
   208   209   210   211   212   213   214   215   216   217   218