COMPUTER SCIENCE C++

1.d) Find the output of the following program:

#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;}

3

Ans: Output:

hat@*PVUQVU*

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;
}}

2

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]<<”:”;
}}

2

Ans: Outputs:

(i) SOUTH : EAST : SOUTH :
(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) 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 :

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp5.php on line 135

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp5.php on line 135

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp5.php on line 137

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp5.php on line 137