Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By MRK

CBSE CLASS XII

e. Find the output of the following program:

#include<iostream.h>
void main( )
{ int A=5,B=10;
for(int I=1;I<=2;I++)
{ cout<<”Line1”<<A++<<”&”<<B-2 <<endl;
cout<<”Line2”<<++B<<”&”<<A +3 <<endl;
}
}

Ans: Output:
Line15&8
Line211&9
Line16&9
Line212&10

f. In the following program, find the correct possible output(s) from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char Area[ ][10]={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0; I<3;I++)
{ ToGo=random(2) + 1;
cout<<Area[ToGo]<<”:”;
}
}

Ans:
Outputs:

  1. SOUTH : EAST : SOUTH :
  2. NORTH : SOUTH : EAST :
  3. SOUTH : EAST : WEST :
  4. SOUTH : EAST : EAST :

Ans. Since random(2) gives either 0 or 1, ToGo value will be either 1 or 2.
(random(n) gives you any number between 0 to n-1)
Area[1] is “SOUTH”. Area[2] is “EAST”.
Since I value from 0 to 2 (ie<3), 3 iterations will takes place.
So the possible output consists 3 strings separated by :, each of them may be either “SOUTH” or “EAST”.
So the possible output will be
(i) SOUTH : EAST : SOUTH :
(iv) SOUTH : EAST : EAST :

2007 Delhi

1.a. Differenctiate between a Run Time Error and Syntax Error. Also give suitable examples of each in c++.

Ans. Run Time Errors: Errors that occur during the execution of a program are called as run time errors. It is caused of some illegal operation taking place or inavailability of desired or required conditions for the execution of the program. For instance, if a program is trying to open a file which does not exist or it could not be opened, it results into an execution error. Similarly, if enough memory is not available or an expression is trying to divide a number by zero are run-time errors.
Eg: Division by zero. c=a/b ;
User will give the values of a and b at the time of program execution.
If he give the value of b as ‘0’ , then division by zero, ie a run time error occurs.

Syntax Errors.
Syntax errors occur when rules of a programming languages (syntax) is misused. Ie when a grammatical rule of C++ is violated.
Eg (i) c=a+b
In this statement, since there is no semicolon at the end of the statement, there will occurs a syntax error.
(ii)cin<<a;
In this statement, since stream insertion operator (<<) has given instead of stream extraction operation(>>), there will occurs a syntax error.

Paper By Mr. MRK
Email Id : [email protected]@yahoo.com