CBSE Computer Science - Revision Tour(Solved)

CBSE Guess > eBooks > Class XII > CBSE Computer Science C++ Solved Revision Tour By Mr. Ravi Kiran

COMPUTER SCIENCE C++

Previous Index Next

e) Find the output of the following program:

#include<iostream.h>
void main( )
{ int U=10,V=20;
for(int I=1;I<=2;I++)
{ cout<<”[1]”<<U++<<”&”<<V – 5 <<endl;
cout<<”[2]”<<++V<<”&”<<U + 2 <<endl;
}
}

2

Ans:

Output:

[1]10&15
[2]21&13
[1]11&16
[2]22&14

f) In the following program, find the correct possible output(s) from the options:

#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char City[][10]= {“DEL”,”CHN”,”KOL”,”BOM”,”BNG”};
int Fly;
for(int I=0; I<3;I++)
{ Fly=random(2) + 1;
cout<<City[Fly]<<”:”;}
}

2

Outputs:

(i) DEL : CHN : KOL:
(ii) CHN: KOL : CHN:
(iii) KOL : BOM : BNG:
(iv) KOL : CHN : KOL:

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

So the possible output will be

(ii) CHN : KOL : CHN:
(iv) KOL :CHN : KOL:

2008 Outside Delhi:

1.b) Name the header files that shall be needed for the following code:

void main( )
{ char word[]=”Exam”;
cout<<setw(20)<<word;
}

1

Ans: iostream.h, iomanip.h

1.c) Rewrite the following program after removing the syntax error(s) if any. Underline each correction.

#include<iostream.h>
void main( )
{ One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2)
{ Arg1=Arg1+Arg2;
Count<<Arg1>>Arg2; }

2

Ans:

void Callme(int Arg1,int Arg2=20);
#include<iostream.h>
void main( )
{ int One=10,Two=20;
Callme(One,Two); //Given ; instead of , Callme(Two);
}
void Callme(int Arg1,int Arg2)
{ Arg1=Arg1+Arg2;cout<<Arg1<<Arg2;
}

 

Previous Index Next

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )