Thursday 28th May 2020
Online Fashion Store

CBSE Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2012 > Computer Science > Computer Science Mr. Pradumna Singh

Computer Science- CBSE CLASS XII

Index Next

Q1. What is the difference between call by reference & call by value method in a user defined function in C++? Explain it with suitable example. For - 2 Marks

Ans. Call by value : In this method, actual arguments of a calling function gets duplicated as formal arguments & are made available to the called function. As a result whatever change is made by called function in these arguments, are not reflected back in actual arguments.
Ex. void SWAP(float a, float b)
{ a=a+b;
cout<<"\na="<<a<<" and b="<<b;  }
Call by reference : In this function call, the reference of actual arguments are provided to the called function i.e. memory location of actual arguments. As a result, any change made in these arguments by called function is reflected back to the actual arguments.
Ex. void SWAP(float &a, float &b)
{ a=a+b;
a=a-b; }

In the function’s argument we simply specify ‘&’ operator along with the argument(s) which are being called by reference.

Q.2.Write the names of the header files, which is/are essentially required to execute the following functions:  For - 1 Marks       

   i) isdigit( )                ii) sin( )

Ans. i) ctype.h        ii) math.h

Q .3 . Rewrite the following program after removing all the syntactical errors (if any), underlining each correction. :                    For - 2 Marks

typedef char[40] string;
void main( )
{  string S=”Australia”;
cout<<”String “<<S<<’ has ’<<L<<”Characters”<<endl; }

Ans.      #include<iostream.h>
typedef char string[40];
void main( )
{  string S=”Australia”;
int/long L=strlen(S);
cout<<”String “<<S<<” has”<<L<<”Characters”<<endl; }

Q 4. Give the output of the following program ( Assuming that all required header files are  included in the program )     :               For - 2 Marks

#define i 5
class TEMP
{ static int a;
float b;
{ b=10; }
void INTEMP( )
{ a++;
b=a+10; }
void OUTTEMP( )
{ cout<<a*i<<"$"<<b-3<<endl; } };
int TEMP::a=2;
void main()
{ TEMP ob[5];
for(int x=1;x<5;x++)
ob[x].INTEMP( );
ob[x].OUTTEMP( );} 

Ans. 30$10

Q . 5. Give the output of the following program ( Assuming that all required header files are  included in the program )   :                             For - 2 Marks
void TRANSFER(char *s1,char *s2)
{ int n,j=0;
for(int i=0;*(s1+i)!='\0';i++)
} }
void main()
{ char *p="ChaRlesBabBaGe",q[80];

Ans. hRlBbB

Q. 6.Go through the following c++ code, find out the correct possible output(s) from the suggested output options i) to iv). Also write the highest value which can be assigned to variable G :                              For - 2 Marks
void main( )
randomize( );
int G,H=5;
for(int i=35;i>G;i--)

  1. 35$34$33$32$31$30$
  2. 35$34$33$32$31
  3. 30$31$32$33$34$35$36
  4. 35$34$33$32$31$30

Ans.  Options ii) & iv) will be the correct possible outputs. The highest value of variable G would be 34

Q. 7. What is constructor overloading? Support your answer with example.                             For - 2 Marks

Ans. CONSTRUCTOR OVERLOADING : When more than one constructor appears inside a single class, it is said to be constructor overloading i.e. if we have two or more constructors inside a class, it is said to be an overloaded constructor. For ex.
class ABC
{ private:
int x;
float y;
ABC( )                   //default constructor
{ x=5;
y=0.0; }
ABC(int p, float q) //parameterized constructor
{ x=p;
y=q; }
ABC(ABC &t)      //Copy constructor
{ x=t.p;
y=t.q; }
void INABC( );
void OUTABC( ); };

Here in the above written example, we see three constructors one after another. Since all of them share the same class name and are different in their type and number of arguments, therefore supports overloading mechanism of OOP.

Q. 8 . Answer the questions (i) and (ii) after going through the following class :                             For - 2 Marks
    class BUS
    { private:
     char Pname[30],TicktNo[20];
     float Fare;
      BUS( )                                                              //function 1
     { strcpy(Pname,”\0”);
        Fare=0; }
      void Details( )                                                   //function 2
      { cout<<Pname<<endl<<TicktNo<<endl<<Fare<<endl; }
       BUS(char * name, char *tno, float N);           //function 3
       BUS(BUS &F);                                              // function 4

  1. In OOP, what is function 3 referred to as? Also define this function.
  2. Define function 4 and write about its purpose?

Ans. i) Function 3  is referred to as parameterized constructor. Its definition is as follows:
                 BUS(char * name, char *tno, float N)
                  { strcpy(Pname,name);
                     Fare=N; }
  1. BUS(BUS &F)

                   { strcpy(Pname,F.Pname);
                     Fare=F.Fare; }

COPY CONSTRUCTOR : It is used to initialize an instance/object  using the values of another instance/object of same class type. It takes the reference to an object of the same class as an argument.

Index Next

Prepared By: Mr. Pradumna Singh
mail to: [email protected]