Page 198 - C++
P. 198

PRACTICE PAPER -I
     Max Marks: 70                                                                                 Time: 3 Hrs

     1.    a.    i. What is typedef? Explain with suitable examples.                                         1
               ii. Define typecasting with the help of appropriate examples.                                 1

           b.  Which header files are required to run the following code:                                    1
                          void main()
                          {char str[20],str[20];
                           gets(str);
                           strcpy(str1,str);
                           strrev(str);
                           puts(str);
                           puts(str1);
                       }

           c.  The following C++ function is used to find the largest number out of a given set of           2
               numbers stored in a one-dimensional array. There are some logical mistakes the desired
               result is not obtained. Rewrite the correct code underlining the corrections done. Do not
               add any additional statements in the corrected code.
                           int find(int a[],int n)
                           { int s=a[0];
                             for(int x=1;x<=n;x++)
                                if(a[x]<s)
                                   a[x]=s;
                             return(s);
                           }

           d.  Predict the output of the following code (assume all header files included)                   2
                           void Convert(char Str[],int Len)
                           { for (int Count =0; Count<Len; Count++ )
                           { if (isupper (Str [Count] ) && Str[Count]<75 )
                               Str[Count]= tolower(Str[Count]);
                              else if (islower (Str [Count] ) && Str[Count]>75)
                                  Str[Count]= toupper(Str[Count]);
                              else if (isdigit (Str [Count]))
                                  Str[Count]= Str[Count] + 2;
                              else Str[Count] = '*'; }
                           }

                           void main ()
                           { char Text [] = "CBSE March 2016";
                              int Size=strlen(Text);
                              Convert(Text,Size);
                              cout<<Text<<endl;
                              for (int C = 0,R=Size-1;C<=Size/2; C++,R--)
                              { char Temp = Text[C];
                                Text [C] = Text [R] ;
                                Text [R] = Temp;
                              }
                              cout<<Text<<endl;
                            }

           e.  What is the expected output of the following code:                                            3
                              void in(int x,int y, int &z)
                              { x+=y;
                                y--;
                                                       Page 1 of 6
   193   194   195   196   197   198   199   200   201   202   203