Page 212 - C++
P. 212

M.CheckOut( );
                       N.Rain(10);
                       N.Sun(2);
                       N.CheckOut( );
                       M.Rain(15);
                       M.CheckOut( );
               }                                                                                             [3]
       (f) Based on the following C++ code find out the expected correct output(s) from option (i) to (iv). Also, find out the
           minimum and the maximum value that can be assigned to the variable ‘Guess’ used in the code at the time when
           value of ‘Turn’ is 3.
               void main( )
               {
                       char    Result [ ][10]={“GOLD”,”SILVER”,”BRONZE”};
                       int    Getit=9,  Guess;
                       for (int Turn=1; Turn<4; Turn ++)
                       {
                              Guess=random(Turn);
                              cout<<Getit – Guess<<Result[Guess]<<”*”;
                       }
               }
        (i)      9GOLD*9GOLD*8SILVER*
         (ii)     9GOLD*7BRONZE*8GOLD*
         (iii)   9GOLD*8SILVER*9GOLD*
         (iv)   9GOLD*8SILVER*8GOLD*                                                                         [2]

   Q.2(a) Write any two similarities between Constructor and Destructor. Write the function headers for constructor and
                destructor of a class Flight.                                                                [2]

      (b) Answer the question (i) and (ii) after going through the following class:                          [2]
               class Race
               {
                       int CarNo, Track;
               public:
                       Race( ) ;            // Function 1
                       Race(int CN);        // Function 2
                       Race(Race  &R);      // Function 3
                       void Register( );    // Function 4
                       void Drive( );       // Function 5
               };
               void main( )
               {
                       Race R;
                        :
               }
          (i)    Out of the following which of the option is correct for calling Function 2 ?
                       Option 1 – Race T(30);
                       Option 2 – Race U(R);
          (ii)  Name the features of Object Oriented Programming, which is illustrated by Function 1, Function 2 and
               Function 3 combined together.

      (c) Define a class Bus in C++ with the following specifications:
           Data Members
                   •  Busno  -       to store Bus No.
                   •  From  -        to store Place name of  origin
                   •  To      -      to store Place name of destination
                   •  Type  -        to store Bus Type such as ‘O’ for ordinary
                   •  Distance-      to store the distance in kilometers
                   •  Fare    -      to store the Bus Fare

                                                                                                                   2
   207   208   209   210   211   212   213   214   215   216   217