Important Output Finding Questions Based On Randomize And
Pointer Concept
Class-12
1. Find the output of the following program :
#include<iostream.h>
#include<ctype.h>
void Secret(char Msg[ ], int N);
void main( )
{ char SMS[ ]=”rEPorTmE”;
Secret(SMS,2);
cout<<SMS<<endl;
}
void Secret(char Msg[ ], int N)
{ for(int C=0;Msg[C]!=’\0’;C++)
if(C%2= =0)
Msg[C]=Msg[C]+N;
else if(isupper(Msg[C]))
Msg[C]=tolower(Msg[C]);
else
Msg[C]=Msg[C]-N;
}
#include<ctype.h>
void Secret(char Msg[ ], int N);
void main( )
{ char SMS[ ]=”rEPorTmE”;
Secret(SMS,2);
cout<<SMS<<endl;
}
void Secret(char Msg[ ], int N)
{ for(int C=0;Msg[C]!=’\0’;C++)
if(C%2= =0)
Msg[C]=Msg[C]+N;
else if(isupper(Msg[C]))
Msg[C]=tolower(Msg[C]);
else
Msg[C]=Msg[C]-N;
}
Ans: teRmttoe
2. Study the following program and select the possible
output from it:
#include<iostream.h>
#include<stdlib.h>
const int MAX=3;
void main( )
{ randomize( );
int Number;
Number=50+random(MAX);
for(int P=Number;P>=50;P--)
cout<<P<<”#”;
cout<<endl;
}
#include<stdlib.h>
const int MAX=3;
void main( )
{ randomize( );
int Number;
Number=50+random(MAX);
for(int P=Number;P>=50;P--)
cout<<P<<”#”;
cout<<endl;
}
(i) 53#52#51#50# (ii) 50#51#52#
(iii) 50#51# (iv) 51#50#
(iii) 50#51# (iv) 51#50#
Ans: (iv) 51#50#
Solution: MAX value is 3 That’s why random(MAX) can produce 0
or 1 or 2. (random(N) will produce no. between 1 to n-1) The Number value may
be 50 or 51 or 52. The P value starts from Number, upto 50, each time decreases
by 1. So Possible outputs are as follows:
52#51#50#
51#50#
50#
51#50#
50#
As the output 51#50# is available in given
answers, so 51#50# is the answer.)
3. 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;
}
#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): Output: Nnd@*Xrk!*
4. In the following
program, find the correct possible output(s) from the options:
#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]<<”:”;}
}
#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:
(ii) CHN: KOL : CHN:
(iii) KOL : BOM : BNG:
(iv) KOL : CHN : KOL:
(ii) CHN: KOL : CHN:
(iii) KOL : BOM : BNG:
(iv) 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 iterationswill
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:
(iv) KOL :CHN : KOL:
5. 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;}
#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*
6. 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]<<”:”;
}}
#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 :
(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 :
(iv) SOUTH : EAST : EAST :
7. Find the output of the following program.
#include<iostream.h>
#include<string.h>
#include<ctype.h>
void Convert(char Str[ ],int Len)
{ for(int Count=0;Count<Len;Count++)
{ if(isupper(Str[Count]))
Str[Count]=tolower(Str[Count]);
else if (islower(Str[Count]))
Str[Count]=toupper(Str[Count]);
else if(isdigit(Str[Count]))
Str[Count]=Str[Count]+1;
else Str[Count]=’*’;
}
}
void main( )
{ char Text[ ]=”CBSE Exam 2005”;
int Size = strlen(Text);
Convert(Text,Size);
cout<<Text<<endl;
for(int C=0,R=Size – 1;C<=Size/2;C++,R--)
{ char Temp=Text[C];
Text[C]=Text[R];
Text[R]=Temp;
}
cout<<Text<<endl;
}
#include<string.h>
#include<ctype.h>
void Convert(char Str[ ],int Len)
{ for(int Count=0;Count<Len;Count++)
{ if(isupper(Str[Count]))
Str[Count]=tolower(Str[Count]);
else if (islower(Str[Count]))
Str[Count]=toupper(Str[Count]);
else if(isdigit(Str[Count]))
Str[Count]=Str[Count]+1;
else Str[Count]=’*’;
}
}
void main( )
{ char Text[ ]=”CBSE Exam 2005”;
int Size = strlen(Text);
Convert(Text,Size);
cout<<Text<<endl;
for(int C=0,R=Size – 1;C<=Size/2;C++,R--)
{ char Temp=Text[C];
Text[C]=Text[R];
Text[R]=Temp;
}
cout<<Text<<endl;
}
Ans:Output: cbse*eXAM*3116
8. Find and write the output of the following C++ program
code:
Note:
Assume all required header files are already being included in
the
program.
void main(
)
{
int Ar[ ]
= { 6 , 3 , 8 , 10 , 4 , 6 , 7} ;
int *Ptr =
Ar , I ;
cout<<++*Ptr++
<< '@' ;
I = Ar[3]
- Ar[2] ;
cout<<++*(Ptr+I)<<'@'<<"\n"
;
cout<<++I
+ *Ptr++ << '@' ;
cout<<*Ptr++
<<'@'<< '\n' ;
for( ; I
>=0 ; I -=2)
cout<<Ar[I]
<< '@' ;
}
Ans 7@11@
6@8@
11@3@
9. Find and write the output of the following C++ program
code:
typedef
char STRING[80];
void
MIXNOW(STRING S)
{
int Size=strlen(S);
for(int I=0;I<Size;I+=2)
{
char WS=S[I];
S[I]=S[I+1];
S[I+1]=WS;
}
for
(I=1;I<Size;I+=2)
if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void
main()
{
STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl;
}
Ans.
BCE@XEMA0291
No comments:
Post a Comment