Order PDF of any content from our website with a little minor Fee to donate for hard work. Online MCQs are fully free but PDF books are paid. For details: contact whatsapp +923028700085 Important notes based PDF Books are available in very little price, starting from 500/-PKR; Order Now: contact whatsapp +923028700085

Past Papers CS201-Most Importants MCQs on File Handling in C++

Q#1: What is the initial step in developing a payroll system for a factory?
(A) Calculate the salary
(B) Gather employee attendance
(C) Enter employee names and salaries
(D) Print a salary report
Answer: (C) Enter employee names and salaries

Q#2: Why is it suggested to save employee information in a file for a payroll system?
(A) To make the program execution faster
(B) To avoid the need for calculating salaries
(C) To have a permanent record for future use
(D) To eliminate the need for entering data
Answer: (C) To have a permanent record for future use

Q#3: What is the purpose of using files in the context of data storage?
(A) To speed up program execution
(B) To save data temporarily
(C) To store data permanently on disk
(D) To reduce memory usage
Answer: (C) To store data permanently on disk

Q#4: Which header file is used for file handling in C++?
(A) <iostream.h>
(B) <fstream.h>
(C) <stdio.h>
(D) <stdlib.h>
Answer: (B) <fstream.h>

Q#5: What are the three basic steps in file handling?
(A) Input, Process, Output
(B) Open, Read and write, Close
(C) Save, Load, Print
(D) Declare, Initialize, Use
Answer: (B) Open, Read and write, Close

Q#6: What are ifstream and ofstream in C++ file handling?
(A) Input and output functions
(B) File stream variables
(C) File open and close operations
(D) Predefined streams
Answer: (B) File stream variables

Q#7: Which function is used to open a file in C++ file handling?
(A) read()
(B) openFile()
(C) open()
(D) startFile()
Answer: (C) open()

Q#8: What is the argument for the open function when associating a file with a file stream variable?
(A) File type
(B) File size
(C) File path
(D) Filename
Answer: (D) Filename

Q#9: How can multiple words be read from a file at once in C++ file handling?
(A) myFile >> c;
(B) myFile >> c1 >> c2 >> c3;
(C) read(myFile, c);
(D) readWords(myFile, c1, c2, c3);
Answer: (B) myFile >> c1 >> c2 >> c3;

Q#10: What is the purpose of the close() function in C++ file handling?
(A) To save changes made to the file
(B) To terminate the program
(C) To release memory
(D) To close the associated file
Answer: (D) To close the associated file

Q#11: Which stream is used to handle errors while opening a file?
(A) cerr
(B) clog
(C) cin
(D) cout
Answer: (A) cerr

Q#12: What happens if a file is not successfully opened in C++ file handling?
(A) Program continues without any issue
(B) Error message is displayed, and the program exits
(C) File is automatically created
(D) Program prompts user for another file
Answer: (B) Error message is displayed, and the program exits

Q#13: Which symbol is used to check if a file is successfully opened?
(A) ?
(B) &
(C) !
(D) #
Answer: (C) !

Q#14: What does the exit(1) statement do in C++ file handling error checking?
(A) Exits the program with an error code
(B) Closes the file
(C) Opens a new file
(D) Resumes program execution
Answer: (A) Exits the program with an error code

Q#15: What is the primary purpose of the ifstream and ofstream objects in C++ file handling?
(A) Display data on the screen
(B) Handle file stream operations
(C) Calculate salaries
(D) Execute input and output functions
Answer: (B) Handle file stream operations

Q#16: How can you read a word from a file in C++ file handling?
(A) read(myFile, word);
(B) myFile.readWord(word);
(C) myFile >> word;
(D) getWord(myFile, word);
Answer: (C) myFile >> word;

Q#17: Why is knowing the file structure important before reading it in C++ file handling?
(A) To speed up the reading process
(B) To avoid reading errors
(C) To reduce the size of the file
(D) To simplify file closing
Answer: (B) To avoid reading errors

Q#18: What is the purpose of the fstream.h header file in C++ file handling?
(A) It defines input and output functions
(B) It handles file operations
(C) It contains mathematical functions
(D) It manages memory allocation
Answer: (B) It handles file operations

Q#19: What does the dot (.) operator represent in the context of file stream objects in C++?
(A) File size
(B) Function call
(C) File path
(D) Member access
Answer: (D) Member access

Q#20: In C++ file handling, what does ifstream myFile; represent?
(A) Input file stream object
(B) Output file stream object
(C) Both input and output file stream objects
(D) Predefined file stream object
Answer: (A) Input file stream object

Contents Copyrights Reserved By T4Tutorials