Class 11 Comp QB
Class 11 Comp QB
COMPUTER SCIENCE
1. 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:
- 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 () {
int num,i;
randomize();
for(i=0;<5;++i) {
num=random(14-5+1)+5;
cout<<num<<" ";
}
}
(i) 7 8 8 14 5 (iii) 8 8 9 12 17
(ii) 7 8 8 16 5 (iv) 5 13 11 12 5
2. Observe the following program 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).
#include<stdlib.h>
#include<iostream.h>
void main()
{ randomize();
int Num, Rndnum;
cin>>Num;
Rndnum = random(Num) + 14;
for (int N; N<=Rndnum; N++)
cout <<N<<" ";
}
(i) 1 2 3 4 (iii) 1 2 3 4 5 9
(ii) 1 2 3 4 5 6 7 8 9 10 11 12 13 (iv) 1 2 3 4
3. In the following program, if the value of N given by the user is 10, what maximum
and minimum values the program could possibly display?
#include <iostream.h>
#include <stdlib.h>
void main(){
int N, Guessnum;
randomize();
cin >> n;
Guessnum = random(N-5) + 5;
cout << Guessnum << endl;
}
4. Read the following C++ code carefully and find out, which out of the given options
(i) to (iv) are expected correct output(s) of it. Also, write the maximum and minimum
value that can be assigned to the variable Start used in the code:
void main()
{
int Guess[4]={200,150,20,250};
int start=random(2)+2;
for (int C=Start; C<4; C++)
cout <<Guess[C]<<”#”;
}
(i) 200#150# (iii) 150#20#250#
(ii) 150#20# (iv) 20#2503
5. Study the following program and select the possible output(s) from the options (i) to
(iv) following it. Also, write the maximum and minimum values that can be assigned
to the variable NUM.
Note:
- Assume all required header files are already being included in the program.
- random(n) functions generates an integer 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;
}
}