0% found this document useful (0 votes)
5 views5 pages

Unit 4 Oop

Uploaded by

mayuraniljamdade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Unit 4 Oop

Uploaded by

mayuraniljamdade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT 4 OOP

### **List of Repeated and Important Questions from the Given Topics**

The following list compiles the most repeated and important questions from the provided
topics related to **file handling**, **command line arguments**, **stream classes**,
**inheritance**, and **other file input/output (I/O) concepts** in C++. This breakdown will
help identify which questions are frequently asked in exams and provide guidance on the
areas to focus on.
### **List of Repeated Questions (Topic-Wise)**:

#### **1. Command Line Arguments in C++**


- **Common Question 1:** Explain the use of **command line arguments**. What will be
the prototype of the `main()` function if we want to pass command line arguments? Explain
its arguments with an example.
- **Appeared 4-5 times**.
- **Key Points**: Syntax of `main(int argc, char *argv[])`, explanation of `argc` (argument
count) and `argv` (argument vector), and practical example showing how to pass and use
command line arguments.
**Common Question 2:** Write a C++ program to explain **command line arguments**.
- **Appeared 2-3 times**.
- **Key Points**: Program demonstrating the passing of arguments from the command
line, accessing and displaying them inside the program.

#### **2. File Handling in C++**


- **Common Question 3:** Explain **file handling functions** in C++ (focus on `seekg()`,
`tellg()`, `seekp()`, `tellp()`).
- **Appeared 4-5 times**.
- **Key Points**: Detailed explanation of file pointer manipulation functions:
- `seekg()`: Move the file read pointer.
- `tellg()`: Return the current position of the read pointer.
- `seekp()`: Move the file write pointer.
- `tellp()`: Return the current position of the write pointer.
- **Common Question 4:** Explain different **file opening modes** in C++.
- **Appeared 3-4 times**.
- **Key Points**: Various mode flags used in `open()` function like:
- `ios::in` (read mode),
- `ios::out` (write mode),
- `ios::app` (append mode),
- `ios::binary` (binary mode),
- `ios::ate` (open and move the file pointer to the end).
- **Common Question 5:** Write a C++ program using file handling to **open, read, and
write** to a file using `open()`, `get()`, `put()`, `close()` functions.
- **Appeared 3-4 times**.
- **Key Points**: File handling program where a file is opened, data is read using `get()`,
written using `put()`, and the file is closed using `close()`. Implement in append mode.
- **Common Question 6:** Explain **error handling in file I/O**.
- **Appeared 2-3 times**.
- **Key Points**: Checking file operation errors using functions like `fail()`, `eof()`, `bad()`,
and handling errors while opening or reading files.

#### **3. Stream Classes in C++**


- **Common Question 7:** What are **fstream**, **ifstream**, and **ofstream**?
Explain with an example and provide the hierarchy of stream classes in C++.
- **Appeared 3-4 times**.
- **Key Points**: Explanation of:
- `ifstream`: Input file stream for reading.
- `ofstream`: Output file stream for writing.
- `fstream`: General file stream for both input and output.
- Hierarchy: `ios_base` -> `istream`/`ostream` -> `ifstream`/`ofstream`/`fstream`.
- **Common Question 8:** Explain the **types of streams** available in C++: `istream`,
`ostream`, `ifstream`, and `ofstream`.
- **Appeared 2-3 times**.
- **Key Points**: Stream classes for handling input (`istream`), output (`ostream`), and file
streams (`ifstream`, `ofstream`).
#### **4. File Pointers and Manipulation**
- **Common Question 9:** Explain the various functions used to **manipulate file
pointers** (`seekg()`, `tellg()`, `seekp()`, `tellp()`). Provide an example.
- **Appeared 3-4 times**.
- **Key Points**: File pointer manipulation for reading/writing in random positions within
a file, using functions `seekg()`, `tellg()`, `seekp()`, `tellp()`.
- **Common Question 10:** Write a program to **create a file, read and write records**
into it (e.g., employee records). Store and retrieve at least three records.
- **Appeared 2-3 times**.
- **Key Points**: Creating a file, storing multiple records, reading records back from the
file.

#### **5. Inheritance in C++**


- **Common Question 11:** Explain **virtual base class** and **virtual functions** in C++
with an example.
- **Appeared 2-3 times**.
- **Key Points**: Virtual base classes to avoid ambiguity in multiple inheritance, and
virtual functions for runtime polymorphism.
- **Common Question 12:** Explain **different forms of inheritance** in C++ with
examples (single, multiple, multilevel, hierarchical, hybrid).
- **Appeared 2-3 times**.
- **Key Points**: Types of inheritance and practical examples demonstrating each type.
- **Common Question 13:** What ambiguity arises in **multiple inheritance**? How can it
be overcome? Provide an example.
- **Appeared 2-3 times**.
- **Key Points**: The diamond problem in multiple inheritance, and the use of virtual base
classes to resolve it.

#### **6. Other File I/O and Stream Concepts**


- **Common Question 14:** What are the **mode bits** used in the `open()` function?
Explain any five.
- **Appeared 2-3 times**.
- **Key Points**: Explanation of mode bits like `ios::in`, `ios::out`, `ios::app`, `ios::trunc`,
`ios::binary`, etc.
- **Common Question 15:** Explain **formatted and unformatted input/output**
functions in C++ with an example.
- **Appeared 1-2 times**.
- **Key Points**: Differences between formatted (`cin`, `cout`, `getline()`, etc.) and
unformatted (`get()`, `put()`) I/O functions, with examples.
### **Non-Repeated Questions**:
1. **Program to Create Files Using Constructor**:
- Write a program to create files using a constructor function.
- **Appeared 1 time**.

2. **Class Program with File Handling**:


- Define a class `Person` with attributes (`name`, `gender`, `age`). Write a program to
write/read objects to/from a file.
- **Appeared 1 time**.

3. **Program to Handle Employee Records in File**:


- Write a program to create a file, read and write employee records (name, id, salary), and
store/retrieve at least 3 records.
- **Appeared 1 time**.
### **Most Important Topics Based on Repetitions**:
1. **Command Line Arguments**:
- Questions related to the use, prototype, and implementation of command line arguments
frequently appear.
- **Appeared 4-5 times**.
2. **File Handling Functions**:
- File pointer manipulation (`seekg()`, `tellg()`, `seekp()`, `tellp()`), and file opening modes
are repeatedly asked.
- **Appeared 4-5 times**.

3. **Stream Classes (fstream, ifstream, ofstream)**:


- Detailed explanations and examples of these classes along with the stream hierarchy are
frequently asked.
- **Appeared 3-4 times**.

4. **Inheritance (Multiple and Virtual Base Classes)**:


- The concept of virtual base classes and ambiguity in multiple inheritance appears
regularly.
- **Appeared 2-3 times**.

5. **File I/O Error Handling**:


- Error handling during file operations appears 2-3 times, especially focusing on the use of
`fail()`, `eof()`, `bad()`, etc.

### **Summary of Repeated Questions**:


- **Command line arguments** are one of the most frequently asked questions, with both
theoretical explanations and practical coding required.
- **File handling functions** (`seekg()`, `tellg()`, `seekp()`, `tellp()`) and **file opening
modes** are commonly examined. Make sure to practice the key functions and understand
their usage thoroughly.
- **Stream classes** like `fstream`, `ifstream`, and `ofstream` are important for file I/O, and
their hierarchy is frequently tested.
- **Inheritance**, especially multiple inheritance and virtual base classes, often comes up in
questions focusing on resolving ambiguities.
### **Conclusion**:
- Prioritize understanding **file handling** (functions, modes, and stream classes) and
**command line arguments** as they are the most commonly repeated topics.
- Practice coding for both file handling and command line arguments.
- Review **inheritance** concepts and be ready to explain and provide examples of
multiple inheritance, virtual base classes, and the role of access specifiers.

You might also like