Test Series - cpp

Test Number 99/102

Q: Which header file is used to create the pseudo random generator?
A. random
B. cstdlib
C. rand
D. both random and cstdlib
Solution: cstdlib header file is used to create pseudo random number. C++11 standard added random header file as well to generate random numbers.
Q: Which is a constant defined in  header file?
A. RAND_MAX
B. Rand
C. Srand
D. Blitz
Solution: RAND_MAX is a constant defined in  for deciding the maximum random number that can be produced.
Q: How many parameters are available in srand function?
A. 1
B. 2
C. 3
D. 4
Solution: There is one parameter available in srand function. That is an integer value to be used as seed by the pseudo-random number generator algorithm.
Q: Which operator is used to produce a certain number in a specific range?
A. $
B. %
C. modulo operator
D. both % and modulo operator
Solution: In C++, modulo operator is denoted by %.
Q: Which can be used to create a random number without duplication?
A. Character
B. Time
C. Both Character & Time
D. Date
Solution: Time can be used to create a random number without duplication.
Q: Which header file is required to use file I/O operations?
A. 
B. 
C. 
D. 
Solution:  header file is needed to use file I/O operations in C++. This header file contains all the file I/O operations definition.
Q: Which of the following is used to create an output stream?
A. ofstream
B. ifstream
C. iostream
D. fsstream
Solution: ofstream is used to create an output stream in C++ file handling operations. Ofstream objects are used to read files.
Q: Which of the following is used to create a stream that performs both input and output operations?
A. ofstream
B. ifstream
C. iostream
D. fstream
Solution: fstream is used to create a stream that performs both input and output operations in C++ file handling.
Q: Which of the following is not used as a file opening mode?
A. ios::trunc
B. ios::binary
C. ios::in
D. ios::ate
Solution: ios::trunc is used to truncate a file if it exists. It is not a file opening mode.
Q: Which of the following statements are correct?

1) It is not possible to combine two or more file opening mode in open() method.
2) It is possible to combine two or more file opening mode in open() method.
3) ios::in and ios::out are input and output file opening mode respectively.
A. 1, 3
B. 2, 3
C. 3 only
D. 1, 2
Solution: C++ allows to use one or more file opening mode in a single open() method. ios::in and ios::out are input and output file opening mode respectively.

You Have Score    /10