Page 112 - C++
P. 112

MODEL TEST PAPER –III (Solved)

        Time: 3 hrs.                                                                           Max. Marks: 70

        1.(a) Write the prototype of a function named Percent, which takes an integer as value parameter and return
        a float type value. The parameter should have a default value 10.

        Ans:   float Percent(int a=10);

        (b) Write the names of header files, which are NOT necessary to run the following
        program:
               #include <iostream.h>
               #include <stdio.h>
               #include <string.h>
               #include <math.h>
               void main()
               {
               char STR[80];
               gets(STR);
               puts(strrev(STR));
               }
        Ans:  NOT required math.h and iostream.h

        (c) Tarunaj has just started working as programmer in the JAGAT WORLD SOFTWARE company. In the
        company, he has got his first assignment to develop a small C++ module to find the biggest number out of a
        given set of numbers stored in a one dimensional array. Somehow he has committed a few logical mistakes
        while writing this code and so he is not getting the desired result from the code. Find out the
        mistakes and correct this C++ code so that it provides the desired result (do not add any new statement in the
        code). Underline each correction made:
               int BIGFIND(int ARR[],int Size)
               {
               int BIG=ARR[1]; //Statement 1
               for (int C=2;C<Size;C++) //Statement 2
               if (ARR[C]<BIG) //Statement 3
               ARR[C]=BIG; //Statement 4
               return BIG; //Statement 5
               }
        Ans:
               for (int C=0;C<Size;C++) //Statement 2
               if (ARR[C]     >      BIG) //Statement 3
               BIG= ARR[C]; //Statement 4

        (d) Find output of the following program segment:
               int A[][3] = {{1,2,3}, {5,6,7}};
               for (int i = 1; i<2; i++)
               for (int j = 0; j<3; j++)
               cout<<A[i][j]<<"*\n";
        Ans:                  5*
                              6*
                              7*
        e)Find output of the following program segment:
        int a = 3;
        void demo(int x, int y, int &z)
        { a += x+y;
        z = a+y;
        y += x;
   107   108   109   110   111   112   113   114   115   116   117