Sunday 28th April 2024
REGISTRATION
Online Fashion Store

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

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

#include<iostream.h>
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<<N1>>N2;
}

2

Ans):

#include<iostream.h>
void Jumpto(int N1,int N2=20);
//Prototype missing
void main( )
{ int First = 10, Second = 20;
//Data type missing
Jumpto(First,Second);
//Comma to come instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2)
{ N1=N1+N2;
cout<<N1<<N2;
//Output operator << required
}

d) Find the output of the following program;

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

3

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

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

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