Page 122 - C++
P. 122

MODEL TEST PAPER – IV (Solved)

               Time: 3 Hrs.                                                                    M.M.: 70



               1.      a) What is the difference between type casting and automatic type conversion
               in an expression?  Give example of each.                                                      2

               Ans: Type Promotion: It is an implicit process of conversion of a data from one type to another. For
                       example
                       int n=65;

                       char ch=n;    // automatic type conversion
                       cout<<ch;
                       Output will be A
                       Type Casting: It is an explicit process of conversion of a data from one type to another. For
                       example
                       int a=1, b=2;
                       float c=(float)a/b;     // type casting

                       cout<<c;
                       Output will be 0.5
               b) Observe the following C++ code and Write the names of the header files  which
               will be essentially required  to run it :                                                  1

                              void main()
                              {      int a, b;
                                     randomize();
                                     cin>>a;
                                     b=random(a);
                                     cout<<b;
                              }
               Ans. iostream.h/iomanip.h  and  stdlib.h
               c)  Rewrite  the  following  program  after  removing  the  syntactical  errors  (if  any).

               Underline each correction.( assuming all header files included)                    2

                                     #define area( a,b)  a * b;
                                     void main()
                                     {      float x,y,z;
                                            cin<<x<<y;
                                            z=area[a,b];
                                            cout<<” Area is :”<<z<<endline;
                                     }
               Ans:                  #define area( a,b)  a * b
                                     void main()
                                     {      float x,y,z;
                                            cin>>x>>y;
                                            z=area(a,b);



               XII / Comp. Sc.                                                             Page 1 of 17
   117   118   119   120   121   122   123   124   125   126   127