/  4
 
Computer SciencePractice Assignment: random( ) Function
Nita Arora,KHMS, Ashok ViharS.NO. SubPartMarksQ1. (a)
Study the following program and select the correct option(s) out of the four choices given below as the possible set of such numbers generated from the program code. Justify your answer. 2#include#includeconst int MIN = 25 ;void main( ){randomize ( );int SCORE = 10 , Num;for (int i = 1 ; i <= 4 ; i ++ ){ Num = MIN + random (SCORE );cout << Num << ":";}}(i) 34:31:30:33:(ii) 29:33:30:31:(iii) 34:31:30:31:(iv) 34:31:29:33:
(2)(b)
The following code is from a game which generates a set of 4 randomnumbers. 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 numbersgenerated from the program code so that he wins the game. Justify your answer. Note: Assume all the necessary header files are included.
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--;}}(i)
 
29:26:25:28:(ii)
 
24:28:25:26:(iii)
 
29:26:24:28:(iv)
 
29:26:25:26:
(2)
 
Computer SciencePractice Assignment: random( ) Function
Nita Arora,KHMS, Ashok Vihar(c)
Consider the following program code. Select the expected output(s) from theoptions(i) to (iv)
#
include<iostream.h>
#
include<stdlib.h>void main(){clrscr();int N=20,guess;randomize();for(int i=1;i<=3;i++){guess=random(N-10)+10;cout<<guess<<" ";}}
i)
 
9 12 14 ii) 14 12 17 iii) 12 14 11 15 iv) 11 14 22
3
 (d)
Mark the correct answer(s) with justification
#
include<iostream.h>
#
include<stdlib.h>
#
include<conio.h>void main(){randomize();int num,rndnum;num=7;rndnum=random(num)+7 ;for(int n=1;n<=rndnum;n++)cout<<n<<" ";getch();}
i) 1 2 3 4 5 6 7 8ii) 1 2 3 4 5 6 7 8 9 10 11 12 13iii) 0 1 2 3 4 5 6 7 8 9iv) 1 2 3 4 5 6 7 8 9 10 11 12 13 14
3
 (e)
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++)
(2)
 
Computer SciencePractice Assignment: random( ) Function
Nita Arora,KHMS, Ashok Vihar
{Fly=random(2)+I;cout<<City[Fly]<<´:´;}}Outputs:i)
 
DEL: CHN: KOL:ii)
 
CHN: KOL: CHN:iii)
 
KOL: BOM: BNG:iv)
 
KOL: CHN: KOL:
(f)
Consider the following program code. Select the expected output from theoptions(i) to (iv) Also justify your answer.
#
include <iostream.h>
#
include <stdlib.h>void main( ){ randomize();int dice = 6, res;res = random(dice) + 1;for (int i = 1 ; i<res ; ++i)cout << i << ´ ³;}
(i ) 0 1 2 3 4 ii) 1 2 3 4 5(iii) 2 3 4 iv) 0 1 2
(2)(g)
Read the following program and select the possible output and explain also.#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;}(a) 53#52#51#50# (b) 50#51#52#(c) 50#51# (d) 51#50#
(2)(h)
Observe the following program SCORE.CPP carefully, if the value of Num entered by the user is 8, choose the correct possible output(s)from the options from (i) to (iv) and justify your option .//program : SCORE.CPP#include<stdio.h>
(2)

Share & Embed

More from this user

Add a Comment

Characters: ...