CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By MRK
CBSE CLASS XII
f. In the following program, find the correct possible output(s) from the options: 2
#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]<<”:”;
}
}
Outputs:
(i) DEL : CHN : KOL:
- CHN: KOL : CHN:
- KOL : BOM : BNG:
- 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 iterations will 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;
}
Ans. iostream.h, iomanip.h
1.c. Rewrite the following program after removing the syntax error(s) if any. Underline each correction. 2
#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; }
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;
}
1.d. Find the output of the following program:3 #include<iostream.h>
#include<ctype.h>
void main( )
{ char Mystring[ ] = "what@OUTPUT!";
for(int I=0; Mystring[I]!='\0';I++)
{ if(!isalpha(Mystring[I]))
Mystring[I]='*';
else if(isupper(Mystring[I]))
Mystring[I]=Mystring[I]+1;
else
Mystring[I] =Mystring[I+1];
}
cout<<Mystring;}
Ans. Output: hat@*PVUQVU*
Paper By Mr. MRK
Email Id : [email protected]@yahoo.com |