0% found this document useful (0 votes)
165 views3 pages

Random Program

The document contains 9 multiple choice questions about the output of various C++ programs that utilize random number generation. For each question, 4 possible output options are provided, and the correct one(s) must be identified and justified based on analyzing the code. Minimum and maximum possible values for randomly generated variables are also sometimes requested.

Uploaded by

Rishi Sakthivelu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views3 pages

Random Program

The document contains 9 multiple choice questions about the output of various C++ programs that utilize random number generation. For each question, 4 possible output options are provided, and the correct one(s) must be identified and justified based on analyzing the code. Minimum and maximum possible values for randomly generated variables are also sometimes requested.

Uploaded by

Rishi Sakthivelu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Observe the following program GAME.

CPP carefully, if the value of Num entered by the


user is 14, choose the correct possible output(s) from the options from (i)to (iv), and justify
your option.
//Program : GAME.CPP
#include<stdlib.h>
#include<iostream.h>
void main ()
{
randomize();
int Num, Rndnum;
cinNum;
Rndnum = random (Num) + 7;
for (int N = 1; N<=Rndnum;N++)
cout<<N<< ;
}
Output Options:
(i) 1 2 3
(ii) 1 2 3 4 5 6 7 8 9 10 11
(iii) 1 2 3 4 5
(iv) 1 2 3 4
2. In the following C++ program what is the expected value of Myscore from Options (i) to
(iv) given below. Justify
your answer.
#include<stdlib.h>
#include<iostream.h>
void main ()
{
randomize() ;
int Score[]={25,20,34,56,72,63), Myscore;
Myscore = Score [2 + random (2)] ;
coutMyscoreendl;
}
Output Options:
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
3. In the following progrom, find the correct possible output(s) from the options:
#include<stdlib.h>
#include<!ostream.h>
void main ()
{
randomize();
char Area [] [10]= {"NORTH",SOUTH", "EAST", "WEST"} ;
int ToGo;
for (int i=0;i<3;i++)
{
ToGo=random(2) +1;
coutArea [ToGo]<<:;
}
}
Output Options:
(i) SOUTH:EAST:SOUTH:
(ii) NORTH:SOUTH:EAST:
(iii) SOUTH:EAST:WEST:
(iv) SOUTH:EAST:EAST:
4. 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--)
coutP#;
cout<<endl;

}
Output Options:
(i)53#52#51#50#
(ii)50#51#52#
(iii)50#51#
(iv)51#50#
5. The following code is from a game, which generates a set of 4 random numbers. Praful
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>
const int LOW=25;
void main()
{
randomize();
int POINT=5,Number;
for(int I=1;I<=4;I++)
{
Number=LOW+random(POINT);
cout<<Number<<:;
POINT--;
}
}
Output Options:
(i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29:26:25:26:
6. 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 minimum and maximum values,
which can be assigned to the variable MyNum.
#include <iostream.h>
#include <stdlib.h>
void main ()
{
randomize();
int MyNum, Max=5;
MyNum=20+random(Max);
for (int N=MyNum;N<=25;N++)
cout<<N<<*;
}
Output Options:
(i) 20*21*22*23*24*25
(ii) 22*23*24*25*
(iii) 23*24*
(iv) 21*22*23*24*25
7. Observe the following program and find out, which output(s) out of (i) to (iv) will not be
expected from the program? What will be the minimum and the maximum value assigned to
the variable. Chance?
#include<iostream.h>
#include<stdlib.h>
void main()
{
randomize();
int Arr[]={19,26},N;
int Change=random(3)+10;
for(int C=0;C<2;C++)
{
N=random(2);
cout<<Arr[N]+Chance<<#;
}
}
Output Options:
(i) 29#36#
(ii)30#37
(iii)29#38#
(iv)31#38#

8. Based on the following C++ code, find out the expcted correct output(s) from the options
(i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the
variable Guess used in the code at the time when value of Turn is 3.
void main ( )
{
char Result [] [10] ={ "GOLD","SILVER",BRONZE"};
int Getit=9,Guess;
for (int Turn=1;Turn<4;Turn++)
{
Guess=random(Turn) ;
coutGetit-GuessResult[Guess]"*";
}
}
Output Options:
(i) 9GOLD*9GOLD*8SILVER*
(ii) 9GOLD*7BRONZE*8GOLD*
(iii) 9GOLD*8SILVER*9GOLD*
(iv) 9GOLD*8SILVER*8GOLD*
9. Read the following C++ code carefully and find out, which out of the given options (i) to
(iv) are the expected correct output(s) of it. Also, write the maximum and minimum value
that can be assigned to the variable Taker used in the code:
void main ()
{
int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
coutGuessMe[Chance]#;
}
Output Options:
(i) 100#
(ii) 50#200#
(iii) 100 #50#200 #
(iv) 100#50

You might also like