Page 140 - C++
P. 140

M.Score+=50;
                    cout<<M.Magic<<M.Score<<endl;
                    Game N=M;
                    N.Magic[0]=’A’;
                    N.Magic[3]=’J’;
                    N.Score-=120;
                    cout<<N.Magic<<N.Score<<endl;
                    }
                (e)  Write the output of the following program:                                         [2]
                    #include<iostream.h>
                    int a=3;
                    void demo(int x, int y, int &z)
                    {
                    a += x+y;
                    z = a+y;
                    y += x;
                    cout<<x<<y<<z<<endl;
                    }
                    void main()
                    {
                    int a=2, b=5;
                    demo(: :a, a, b);
                    cout<<: : a <<a<<b<<endl;
                    demo(: : a , a, b );
                 (f)  Observe the following C++ code and find out, which out of the given options (i) to (iv) are the
                   expected correct output. Also assign the maximum and minimum value that can be assigned to
                   the variable ‘Go’.                                                                   [2]
                    void main()
                    {
                    int X [4] ={100,75,10,125};
                    int Go = random(2)+2;
                    for (int i = Go; i< 4; i++)
                    cout<<X[i]<<”$$”;
                    }
                     (i)  100$$75
                    (ii)  75$$10$$125$$
                    (iii)  75$$10$$
                    (iv)  10$$125$
              2. (a)  How does a class implements Data Abstraction and Encapsulation?                   [2]
                (b)  Answer the questions (i) and (ii) after going through the following class:         [2]
                   class Race
                    {
                    int CarNo,Track;
                    public:

              MTP.2                                                          Computer Science with C++ —CBSE XII
   135   136   137   138   139   140   141   142   143   144   145