UNIT 6 OOP
### **List of Repeated and Important Questions from the Given Topics (STL, Iterators,
Containers, Algorithms, File Handling)**
This breakdown will help identify the most repeated questions across the topics, organize
them by their frequency of occurrence, and provide a list of non-repeated questions to help
you prepare effectively for exams.
### **List of Repeated Questions (Topic-Wise)**:
#### **1. Standard Template Library (STL)**
**Common Question 1:** What is **STL**? Enlist and explain its key components.
- **Appeared 4-5 times**.
- **Key Points**: Explanation of **components of STL**: Containers, Iterators, and
Algorithms.
- **Common Question 2:** Differentiate between **sequence containers** and
**associative containers** in STL. Provide examples.
- **Appeared 3-4 times**.
- **Key Points**: Examples of **sequence containers** (like vector, deque, list) and
**associative containers** (like map, set). Comparison based on element storage and
access.
- **Common Question 3:** What are **iterators** and **algorithms** in STL? Explain with
examples.
- **Appeared 4 times**.
- **Key Points**: Explanation of **iterators** (pointers-like objects) and **algorithms**
(predefined operations like sort, find, etc.). Include an example demonstrating their usage.
- **Common Question 4:** What is a **map** in STL? Write a program to implement a map
in C++.
- **Appeared 3-4 times**.
- **Key Points**: A map is an associative container with key-value pairs. Program
demonstrating how to insert, access, and iterate through a map.
- **Common Question 5:** What are **sequential containers** in STL? Compare **arrays
and vectors**.
- **Appeared 3-4 times**.
- **Key Points**: Definition of **sequential containers** (array, vector, deque, list).
Comparison based on dynamic memory allocation, size flexibility, and performance.
- **Common Question 6:** What are **container adapters** in STL? Explain with examples.
- **Appeared 2-3 times**.
- **Key Points**: Explanation of **container adapters** (like stack, queue, and priority
queue), which provide restricted interfaces to existing containers (like deque or vector).
- **Common Question 7:** Write a program to implement a **vector** and explain five
functions of vector with code.
- **Appeared 2-3 times**.
- **Key Points**: Functions such as `push_back()`, `size()`, `capacity()`, `resize()`, and `at()`
are frequently asked.
#### **2. Iterators in C++**
- **Common Question 8:** What is an **iterator**? Write a program in C++ to demonstrate
the use of an iterator.
- **Appeared 4-5 times**.
- **Key Points**: Explanation of **iterators** (objects that point to elements in
containers). Program showing iteration through a vector or map using an iterator.
- **Common Question 9:** Differentiate between **iterators and pointers**.
- **Appeared 2-3 times**.
- **Key Points**: Iterators are more abstract and can work with all containers in STL, while
pointers are limited to arrays or dynamic memory.
#### **3. Algorithms in STL**
- **Common Question 10:** What are **algorithms** in STL? List various algorithms and
explain one with a C++ program.
- **Appeared 3-4 times**.
- **Key Points**: Explanation of **algorithms** like `sort()`, `find()`, `reverse()`,
`accumulate()`, and `count()`. Program demonstrating the use of one algorithm like **sort**
or **find**.
- **Common Question 11:** Explain **sorting algorithms** in STL with an example.
- **Appeared 2-3 times**.
- **Key Points**: Explanation of **std::sort** and its usage with different iterators.
#### **4. Containers in STL**
- **Common Question 12:** What is a **container** in STL? List and explain different types
of containers.
- **Appeared 3-4 times**.
- **Key Points**: Explanation of **sequence containers**, **associative containers**, and
**container adapters** with examples.
- **Common Question 13:** Explain any two types of **containers** in STL in detail.
- **Appeared 2-3 times**.
- **Key Points**: Detailed explanation of containers like vector, list, map, or set with
examples.
#### **5. File Handling in C++**
- **Common Question 14:** What is **file mode**? Explain any four modes supported by
C++.
- **Appeared 2-3 times**.
- **Key Points**: Explanation of file modes like `ios::in`, `ios::out`, `ios::binary`, `ios::ate`,
`ios::app`, etc.
- **Common Question 15:** Explain **error handling** during file operations.
- **Appeared 2-3 times**.
- **Key Points**: Methods like `fail()`, `bad()`, `eof()`, and `good()` for error handling in file
I/O.
- **Common Question 16:** Write a program to use **open()**, **eof()**, and
**getline()** to read file content line by line.
- **Appeared 2-3 times**.
- **Key Points**: Program that reads file content using `open()`, checks for the end of the
file using `eof()`, and reads lines using `getline()`.
#### **6. Vectors in STL**
- **Common Question 17:** What is a **vector** in STL? Explain five functions of vector
with a C++ program.
- **Appeared 2-3 times**.
- **Key Points**: Functions like `push_back()`, `size()`, `capacity()`, `empty()`, `pop_back()`
and `clear()`.
### **Non-Repeated Questions**:
1. **Quick Sort Using STL Algorithms**:
- Describe the process of using STL algorithms for **Quick sort**.
- **Appeared 1 time**.
2. **Using List in STL**:
- How can **lists** be used as sequence containers in the STL? Provide an example.
- **Appeared 1 time**.
3. **Constructor vs. Open Function for Files**:
- Explain the difference between opening a file with a **constructor** and using the
**open()** function.
- **Appeared 1 time**.
4. **Map Container with Multiple Data Types**:
- Write a program to demonstrate the use of a **map** with different data types (e.g.,
string as key, int as value).
- **Appeared 1 time**.
5. **Comparing Pointers and Iterators**:
- Differentiate between **pointers** and **iterators** in detail with examples.
- **Appeared 1 time**.
### **Most Important Topics Based on Repetitions**:
1. **STL Basics**:
- Questions focusing on **what is STL**, its **components** (containers, iterators,
algorithms), and the **types of containers** are asked very frequently.
- **Appeared 4-5 times**.
2. **Containers**:
- Questions involving **sequence containers**, **associative containers**, and
**container adapters** (especially **vector**, **map**, and **list**) are essential.
- **Appeared 3-4 times**.
3. **Iterators and Algorithms**:
- **Iterators** (difference from pointers, their role in STL) and **algorithms** (sorting,
searching) are frequently tested concepts.
- **Appeared 4-5 times**.
4. **File Handling**:
- File modes and **error handling** during file operations come up repeatedly. Programs
demonstrating how to handle file reading/writing using functions like `open()`, `eof()`, and
`getline()` are also important.
- **Appeared 2-3 times**.
### **Summary of Repeated Questions**:
- **STL Concepts** and **components** such as containers, iterators, and algorithms are
highly prioritized.
- **File Handling** concepts like file modes, file reading/writing, and error handling during
file operations are regularly asked.
- **Iterators** are a recurring topic, often combined with containers or algorithms in
programming questions.
- Pay special attention to **vector** and **map** containers, as these are frequently asked,
especially their functions and how to implement them in C++.
### **Conclusion**:
- Focus on **STL**, **file handling**, and **iterators** as these topics are highly important
for exams.
- Practice writing C++ programs that demonstrate the usage of **maps**, **vectors**, and
**iterators**.
- Be well-prepared with examples and programs related to **file handling**, including
modes and error handling.