Page 124 - C++
P. 124

type=( type==’P’) ? ’G’: ’P’;
                              }
                              void game::play(int gs)
                              {
                                     point +=gs;
                                     if(point>=30)
                                            phase=3;
                                     else if( point>=20)
                                            phase=2;
                                            else
                                            phase=1;
                              }
               Ans:           P@1
                              0
                              P@1
                              11
                              P@2
                              25

                       f) Read the following C++ code carefully and find out, which out of the given
                       options  (i)  to  (iv)  are  the  expected  correct  outputs  of  it.  Also,  write  the

                       maximum  and  minimum  value  that  can  be  assigned  to  the  variable  score
                       used in the code.                                                                 2

                              #include<iostream.h>
                              #include<stdlib.h>
                              void main()
                              {      randomize();
                                     int guess[4]={ 100, 50, 200, 20 };
                                     int score=random(2) +2;
                                     for( int c=0; c<score; c++)
                                            cout<<guess[c]<<”#”;
                              }

                                  Outputs:
                              (i)    100#
                              (ii)   50# 200#
                              (iii)   100#50#200#
                              (iv)   100#50
               Ans:    Minimum value =2            maximum=3
               Correct output is (iii)
                 2.    a) What is the difference between the members in private visibility mode and

                       the members in protected visibility mode inside a class? Also give a suitable
                       C++ code to illustrate the same.                                                     2

               Ans:

                        Private visibility mode                    Protected visibility mode



               XII / Comp. Sc.                                                             Page 3 of 17
   119   120   121   122   123   124   125   126   127   128   129