Important Questions

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

CBSE CLASS XII

Q.d. Find the output of the following program;3
#include<iostream.h>
#include<ctype.h>
void main( )
{ char Text[ ] = “Mind@work!”;
for(int I=0; Text[I]!=’\0’;I++)
{ if(!isalpha(Text[I]))
Text[I]=’*’;
else if(isupper(Text[I]))
Text[I]=Text[I]+1;
else
Text[I] = Text[I+1];
}
cout<<Text;
}

Ans:

Text[ ] =
When I=0
Since Text[0] is ‘M’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[0]=Text[0]+1
Text[0] =77(ASCII Value of M) + 1 = 78
=N(78 is ASCII Value of N)
Now the String Text[ ] =
When I=1
Since Text[1] is ‘i’, Which is a character, but
which is not Upper case,
else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[1]=Text[1+1]
=Text[2]
Ie ‘n’ will be stored in place of ‘i’
Now the String Text[ ] =
When I=2
Since Text[2] is ‘n’, Which is a character, but which is not Upper case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[2]=Text[2+1]
=Text[3]
Ie ‘d’ will be stored in place of ‘n’
Now the String Text[ ] =
When I=3
Since Text[3] is ‘d’, Which is a character, but which is not Upper case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[3]=Text[3+1]
=Text[4]
Ie ‘@’ will be stored in place of ‘d’
Now the String Text[ ] =

Paper By Mr. Ravi Kiran
Email Id : [email protected]