0

File Handling (NCO)

Description: datafile handling
Number of Questions: 15
Created by:
Tags: Data File Handling File Handling
Attempted 0/15 Correct 0 Score 0

Which of the following files in C++ is a file that contains information in the same format in which the information is held in the memory?

  1. Binary file

  2. Text file

  3. ASCII file

  4. Data file

  5. filebuf


Correct Option: A
Explanation:

This file in C++ is a file that contains information in the same format in which the information is held in the memory.

Which of the following classes in C++ supports output operations and contains open() function with default output mode?

  1. fstreambase

  2. ifstream

  3. ofstream

  4. fstream

  5. filebuf


Correct Option: C
Explanation:

This class in C++ supports output operations and contains open() function with default output mode.

Which of the following streams in C++ receives data from a program and writes the data to a monitor that it receives from the program?

  1. Input stream

  2. Output stream

  3. Error stream

  4. File

  5. Data stream


Correct Option: B
Explanation:

This stream in C++ receives data from the program and writes the data to the monitor that it receives from the program.

Which of the following codes is used for relative position in get pointer and is used to place the file pointer, and read the contents from the beginning of a file?

  1. ios::cur

  2. ios::beg

  3. ios::end

  4. ios::out

  5. ios::in


Correct Option: B
Explanation:

This code is used for relative position in get pointer and is used to place the file pointer, and read the contents from the beginning of a file.

Which of the following file modes is used in file handling, if an already existing file is to be opened for output operations and its previous contents are to be deleted by a new one?

  1. ios::app

  2. ios::ate

  3. ios::binary

  4. ios::trunc

  5. ios::out


Correct Option: D
Explanation:

This file mode is used in file handling if an already existing file is to be opened for output operations and its previous contents are to be deleted by a new one.

Which of the following operators in C++ is called as an insertion operator that inserts data into an appropriate stream?

  1. >>

  2. <<

  3. :?

  4. &

  5. *


Correct Option: B
Explanation:

This operator in C++ is known as an insertion operator. It is used to insert data into an appropriate stream.

Which of the following program codes is correct for opening a file in append mode that sets the write pointer to end of a file?

  1. fstream f1; f1.open(TEXT.DAT, ios::app);

  2. ifstream f1; f1.open(TEXT.DAT, ios::app);

  3. ofstream f1; f1.open(TEXT.DAT, ios::trunc);

  4. fstream f1; f1.open(TEXT.DAT, ios::out);

  5. fstream f1; f1.open(TEXT.DAT, ios::in);


Correct Option: A
Explanation:

This code is correct for opening a file in append mode that sets the write pointer to the end of a file.

Which of the following steps is the first step to use files in C++?

  1. Declaring file streams

  2. Including the header files

  3. Opening a file

  4. Process the file

  5. Closing a file


Correct Option: B
Explanation:

This is the first step to use files in C++. To handle external files, header file like fstream.h has to be included in the beginning to perform input and output operations on files.

Which of the following stream classes is used in C++ to perform input and output operations on to a data file?

  1. istream

  2. ostream

  3. ifstream

  4. ofstream

  5. fstream


Correct Option: E
Explanation:

This stream class is used in C++ to perform input and output operations on to a data file.

Which of the following functions in data file handling moves the file put pointer to a location specified by its arguments?

  1. seekg()

  2. tellg()

  3. tellp()

  4. seekp()

  5. return()


Correct Option: D
Explanation:

This function in data file handling moves the file put pointer to a location specified by its arguments.

Which of the following stream classes acts as base class in the hierarchy of file stream classes?

  1. istream

  2. ostream

  3. iostream

  4. ios

  5. fstream


Correct Option: D
Explanation:

This stream class acts as base class in the hierarchy of file stream classes.

What would be the output of the following C++ code?

textfile.seekp(5, ios::beg);

  1. Moves the put pointer by 5 bytes from the beginning of a data file

  2. Moves the get pointer by 5 bytes from the beginning of a data file

  3. Displays the contents of a data file

  4. Modifies data of a data file

  5. Deletes the contents of a data file


Correct Option: B
Explanation:

This is the correct option as seekg() function is used to move the get pointer from the beginning of a data file.

Which of the following functions is used to write the contents of the binary file associated with ofstream object?

  1. read()

  2. write()

  3. tellg()

  4. tellp()

  5. seekg()


Correct Option: B
Explanation:

This function is used to write the contents of the binary file associated with ofstream object.

Which of the following devices is connected to the input stream in C++ from which data is extracted and provided to the program for manipulation?

  1. Monitor

  2. Printer

  3. Keyboard

  4. Plotter

  5. Joystick


Correct Option: C
Explanation:

This device is connected to the input stream from which data is extracted and provided to the program for manipulation.

Consider the following C++ code:

textfile.open(sample.dat, ios::in);

Where is the get pointer placed after the execution of the above code?

  1. At the beginning of the file

  2. At the end of the file

  3. In the middle of data file

  4. At the current position of data file

  5. Automatically positioned


Correct Option: A
Explanation:

This is the correct option as whenever a user sends read request to a data file, the get pointer is always positioned at the beginning of the data file sample.dat.

- Hide questions