Friday 03rd May 2024
REGISTRATION
Online Fashion Store

CBSE eBooks

CBSE Guess > eBooks > Class XII > Computer Science By . Mr. MRK

Chapter – 1 C++ Revision Tour

Previous Index Next

1. e. Find the output of the following program: 2

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

Ans: Output:

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

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[ ] =

When I=4
Since Text[4] is ‘@’, Since which is not an alphabet,
(!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;
Ie Text[4]=’*’ Ie ‘*’
will be stored in place of ‘@’
Now the String Text[ ] =

When I=5
Since Text[5] is ‘W’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[5]=Text[5]+1
Text[5] =87(ASCII Value of W) + 1 = 88 = X (88 is ASCII Value of X)
Now the String Text[ ] =

When I=6
Since Text[6] is ‘o’, Which is a character, but which is not Upper case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[6]=Text[6+1]
=Text[7]
Ie ‘r’ will be stored in place of ‘o’
Now the String Text[ ] =

When I=7
Since Text[7] is ‘r’, Which is a character, but which is not Upper case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[7]=Text[7+1]
=Text[8] Ie ‘k’ will be stored in place of ‘r’
Now the String Text[ ] =

When I=8
Since Text[8] is ‘k’, Which is a character, but which is not Upper case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[8]=Text[8+1]
=Text[9] Ie ‘!’ will be stored in place of ‘k’
Now the String Text[ ] =

When I=9
Since Text[9] is ‘!’, Since which is not an alphabet,
(!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;
Ie Text[9]=’*’ Ie ‘*’
will be stored in place of ‘!’
Now the String Text[ ] =

Output: Nnd@*Xrk!*

Previous Index Next