Professional Documents
Culture Documents
In The Following Program, If The Value of Guess Entered by The User Is 65, What Will Be The Expected Output(s)
In The Following Program, If The Value of Guess Entered by The User Is 65, What Will Be The Expected Output(s)
In The Following Program, If The Value of Guess Entered by The User Is 65, What Will Be The Expected Output(s)
1) In the following program, if the value of Guess entered by the user is 65, what will be the expected output(s)
from the following options (i), (ii), (iii) and (iv)?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int Guess;
randomize();
cin>>Guess;
for (int I=1;I<=4;I++)
{
New=Guess+random(I);
cout<<(char)New;
}
}
(i) ABBC
(ii) ACBA
(iii) BCDA
(iv) CABD
Ans:
From the above table, it is clear that option (ii) will not be expected output (since when I =2, then C cannot be there in
the output. Similarly, option (iii) will not be expected as when I =1, 2 and 3 then output cannot be B, C and D
respectively.
Option (iv) is also not possible, when I =1 then output cannot be C.
So, only possible output is (i) ABBC
2)
1
Ans:-
C Sequence Select[Sequence]
Minimum Maximum
0 0 3 25/90/30/45
1 0 2 25/90/30
2 0 1 25/90
3 0 0 25
3) In the following program, find the correct possible output(s) from the options. Justify your answer.
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int p=99,q=999;
int x=random(3)+4;
int y=random(2)+2;
for(int i=0;i<x;i++)
cout<<’#’;
cout<<p<<’-’;
for(i=0;i<y;i++)
cout<<’@’;
cout<<q<<endl;
}
i. ##99-@999
ii. ##99-@@999
iii. ######99-@@999
iv. ####99-@@@
random(3) x i #
Min Max
0 4 0 3 ####
1 5 0 4 #####
2 6 0 5 ######
random(2) y i @
Min Max
0 2 0 1 @@
1 3 0 2 @@@
p=99, q= 999
possible output option (iii)– because according to the above tables six “#” can be generated if value of x is 6 and two
“@” can be generated if value of y is 2.
Option (i) Not possible – because two “##” symbol and one “@” symbol cannot be generated according to the above
table.
Option (ii) Not possible – because two “##” symbol cannot be generated according to the above table.
Option (iv) Not possible – because the value of q (999) is not present in the output.
4) The following code is from a game, which generates a set of 4 random numbers.
Yallav is playing this game, help him to identify the correct option(s) out of the four choices given below as the possible
set of such numbers generated from the program code so that he wins the game. Justify your answer.
#include <iostream.h>
#include <stdlib.h>
2
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:
5) Go through the C++ code shown below, and find out the possible output or
outputs from the suggested Output Options (i) to (iv). Also, write the least
value and highest value, which can be assigned to the variable Guess. 2
#include <iostream.h>
#include <stdlib.h>
void main ( )
{
randomize ( ) ;
int Guess, High=4;
Guess=random(High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;
}
(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55
Guess C
Min Max
50 50 55
51 51 55
52 52 55
53 53 55
Possible output option (i)
3
6) Observe the following program & Find out the correct possible outputs from the options .
( Assuming that all required header files are included in the program)
void main()
{
char serial[ ] = {‘E’, ‘X’,’A’,’M’,’\0’};
int number [ ]= { 69,66,67,68};
randomize();
cout<<number[random(3)];
for( int i=0;i<4;i++)
cout<<serial[sizeof(int) + random(2)-1];
}
(i) 67XXAX
(ii) 69AXXA
(iii) 66AAXA
(iv) 67AAAM
Ans:
random(3) = minimum value 0 and maximum value 2
random(3) number[random(3)]
0 69
1 66
2 67
(i) 67XXAX
(ii) 69AXXA
(iii) 66AAXA
7) Based on the following C++ code, find out the expected correct output(s) from the options (i) to (iv). Also find out the
minimum and maximum value that can be assigned to the variable Trick used in the code at the time when value of
Count is 2:
#include<iostream.h>
#include<stdlib.h>
const int Max=3;
void main( )
{
randomize( );
char Status[] [20]= {"Jammu", "Jharkhand", "Maharashtra" };
int Turn=10, Trick;
for(int count=1;count<4;count++)
{
Trick=random(count);
cout<<Turn-Trick<<Status[Trick]<<"#";
}
}
i) 10Jammu#10Jammu#8Maharashtra#
ii) 10Jammu#8Maharashtra#9Jharkhand#
iii) 10Jammu#9Jharkhand#10Jammu#
iv) 10Jammu#10Jharkhand#8Maharashtra#
Answer:
Trick
count Turn-Trick Status
Min Max
1 0 0 10 Jammu
2 0 1 10 Or 9 Jammu Or Jharkhand
Jammu Or Jharkhand Or
3 0 2 10 or 9 Or 8
Maharashtra
So possible outputs:
i) 10Jammu#10Jammu#8Maharashtra#
iii) 10Jammu#9Jharkhand#10Jammu#
4
8) Study the following program and select the possible output from it
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
char city[ ][4]={“PKD”, “EKM”, ”TVM”, “KOL”, “CAL”};
int ZEN;
for(int i=0;i<3;i++);
{
ZEN=random(2)+1;
cout<<city[ZEN]<<”@”;
}
}
(i) PKD@ EKM @TVM@
(ii) EKM @TVM@ EKM @
(iii) TVM@KOL@CAL@
(iv) TVM@ EKM @TVM@
Answer:
i ZEN city[ZEN]
0 1 EKM
2 TVM
1 1 EKM
2 TVM
2 1 EKM
2 TVM
Possible outputs:
9) Study the following program and select the possible output(s) from the option (i) to (iv) following it.
Also write the maximum and the minimum values that can be assigned to the variable NUM.
Note: (2)
- Assume all required header files are already being included in the program.
- random(n) function generates an integer between 0 and n-1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]=”ABCDEFGHIJK”;
for (int I=1;I<=NUM; I++)
{
for (int J=NUM;J<=7;J++)
cout<<TEXT[J];
cout<<endl;
}
}
(i)FGHI (ii) BCDEFGH (iii) EFGH (iv) CDEFGH
FGHI BCDEFGH EFGH CDEFGH
FGHI EFGH
FGHI EFGH
5
Answer:
J TEXT[J]
J TEXT[J]
2 C J TEXT[J]
3 D
3 D 4 E
4 E
4 E 5 F
5 F
5 F 6 G
6 G
6 G 7 H
7 H
7 H
10) Observe the following C++ code and find out, which out of the given options i) to iv) are the expected correct output.
Also assign the maximum and minimum value that can be assigned to the variable ‘Go’.
void main()
{ int X [4] ={100,75,10,125};
int Go = random(2)+2;
for (int i = Go; i< 4; i++)
cout<<X[i]<<”$$”;
}
Minimum value of Go = 2
Maximum value of Go = 3
11) Observe the following C++ code and find out, which out of the given options i) to iv) are the expected correct output.
Find the maximum and minimum value of L.
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
void main()
{
randomize();
char P[ ] = “C++PROGRAM”;
long L;
for(int I =0; P[I]!=’R’;I++)
{
L=random(sizeof(L)) + 5;
cout<<P[ L ] <<”-“;
}
}
(i) R-P-O-R-
(ii) P-O-R-+-
(iii) O-R-A-G-
6
(iv) A-G-R-M-
Answer:
sizeof(L) = 4
If value of I =0, Or value of I =1, Or value of I = 2 Or value of I =3 then following values will be generated for L and P[L]
L P[L]
5 O
6 G
7 R
8 A
Minimum value of L = 5
Maximum value of L = 8
12) Consider the following C++ program code and choose the option(s) which are not possible as output. Also, print the
minimum & maximum value of variable Pick during complete execution of the program.(assume all necessary header
files are included in program):
(a) 5:6:6:6:
(b) 4:7:5:3:
(c) 8:6:1:2:
(d) 7:5:3:1
Ans:
Option (a) , (c) & (d)
Maximum value of Pick will be 8
Minimum value of Pick will be 1
(1/2 mark for each correct option)
(1 mark each giving correct values of both max & min)
7
13)
Ans:
Possible Outputs
(ii) and (iii)
Maximum value of R = 2
Maximum value of C = 3