Unit 3: Data Files, Constructors and Destructors - Subjective Questions

CSE202 — Object Oriented Programming • Practice Questions with Detailed Answers

20 questions

1

Define a file and explain how files are opened and closed in C++ using file streams.

2

Explain the different file opening modes available in C++. How can multiple modes be combined?

3

Describe the important file stream functions used to control file processing and detect errors in C++.

4

Explain how formatted and unformatted data are written to and read from text files in C++. Give suitable examples.

5

Distinguish between sequential-access and random-access file processing.

6

Describe the functions used to manipulate the get pointer and put pointer during random-access file processing.

7

Explain binary file operations in C++. Develop a short example that writes and reads a fixed-size record.

8

Compare text files and binary files with respect to representation, size, speed, portability, and usability.

9

Explain how a class can perform file operations. Illustrate a suitable design for storing and retrieving class data.

10

Describe how structures are used with files. Explain both text-based and binary storage of structure records.

11

What are constructors and destructors? Why are they called manager functions of a class?

12

Define a default constructor. Under what conditions does the compiler generate one automatically?

13

Explain a constructor with default arguments. How does it differ from an ordinary default constructor, and what ambiguity can arise?

14

Describe a parameterized constructor and explain constructor overloading with an example.

15

Explain the role and behavior of a destructor. In what order are destructors invoked for local objects, members, and derived objects?

16

Define a copy constructor. State when it is invoked and demonstrate its general syntax.

17

Distinguish between a shallow copy and a deep copy. Explain why a user-defined copy constructor may be necessary.

18

What is a constructor initializer list? Explain why it is preferred over assignment inside the constructor body.

19

Develop a C++ approach for randomly accessing and updating a structure record in a binary file. Explain the position calculation and major error checks.

20

Design and explain a class that combines constructors, a copy constructor, a destructor, initializer lists, and file operations to manage a file resource.