Unit 3: Constructors, Destructors and Managing File Operations - Subjective Questions

CAP455 — Object Oriented Programming Using C++ • Practice Questions with Detailed Answers

20 questions

1

Define a constructor in C++. Explain the important features of a constructor function.

2

What is a default constructor? Explain its operation with a suitable C++ program.

3

Distinguish between a constructor and a normal member function in C++.

4

Explain parameterized constructors and constructor overloading with an appropriate C++ example.

5

What is a copy constructor? Explain when it is invoked and illustrate deep copying with a C++ program.

6

Explain constructor initializer lists. Why are they preferred or required in certain situations?

7

Describe a constructor with default arguments. Discuss its benefits and the ambiguity that may occur when it is combined with a default constructor.

8

Define a destructor. Explain its characteristics, order of execution, and role in resource management.

9

Explain how files are opened and closed in C++ using constructors and the open() and close() functions.

10

Describe the different file opening modes available in C++. Explain how multiple modes can be combined.

11

Explain the important state-checking, positioning, and data-transfer functions provided by C++ file streams.

12

Explain formatted and unformatted reading and writing of text files with suitable examples.

13

What is sequential file access? Describe its working, advantages, limitations, and a typical processing algorithm.

14

Explain random access file processing using seekg(), seekp(), tellg(), and tellp(). Derive the position of the th fixed-size record.

15

Explain binary file operations in C++. Compare binary files with text files and demonstrate the use of read() and write().

16

Describe how objects of a class can be stored in and retrieved from a file. Explain why direct binary dumping is unsafe for some classes.

17

Explain file operations with structures. Write a C++ approach to append, display, and search fixed-size structure records in a binary file.

18

Compare sequential access and random access techniques for file processing.

19

Explain stream error states and proper error handling during file operations. Why is while (!file.eof()) considered incorrect?

20

Design and explain a C++ class-based file system that adds, displays, searches, and updates student records using random access.