0% found this document useful (0 votes)
3 views

C++

The document outlines a plan for creating scenario-based questions related to C++ Standard Template Library (STL) concepts, including containers, iterators, algorithms, and function objects. It provides a structure for each question, including a scenario, question, STL concept used, syntax, explanation, and expected output. Additionally, it presents three sample questions demonstrating the use of STL components in practical scenarios and proposes next steps for generating more questions.

Uploaded by

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

C++

The document outlines a plan for creating scenario-based questions related to C++ Standard Template Library (STL) concepts, including containers, iterators, algorithms, and function objects. It provides a structure for each question, including a scenario, question, STL concept used, syntax, explanation, and expected output. Additionally, it presents three sample questions demonstrating the use of STL components in practical scenarios and proposes next steps for generating more questions.

Uploaded by

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

Great!

Here’s a plan tailored to your request:

✅ Brief of C++ STL Concepts


The C++ Standard Template Library (STL) is composed of four main components:
1. Containers
 Store collections of objects/data.
 Types:
o Sequence Containers: vector, list, deque, array

o Associative Containers: set, multiset, map, multimap

o Unordered Containers: unordered_set, unordered_map,


unordered_multiset, unordered_multimap
o Container Adaptors: stack, queue, priority_queue

2. Iterators
 Used to point to container elements. Types:
o input_iterator, output_iterator, forward_iterator,
bidirectional_iterator, random_access_iterator
3. Algorithms
 Operate on containers using iterators.
 Examples: sort(), find(), count(), reverse(), accumulate(), binary_search()
4. Function Objects & Utilities
 pair, tuple, bind, function, lambda, etc.

📘 Structure of Each Question


Each scenario-based question will include:
1. Scenario
2. Question
3. STL Concept Used
4. Syntax & Explanation
5. Expected Output

🧩 Sample (Preview) — 3 Questions

🐶 Q1. Scenario: Ravi and His Dogs (Vector + Sort)


Scenario: Ravi owns 5 dogs. Their ages are {3, 1, 5, 2, 4}. He wants to sort
them from youngest to oldest before a vet visit.
Question: Write a C++ program using STL to sort and display the ages.
STL Concept: vector, sort()
Syntax & Explanation:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
vector<int> dogAges = {3, 1, 5, 2, 4};
sort(dogAges.begin(), dogAges.end());
for (int age : dogAges) cout << age << " ";
return 0;
}
Expected Output:
12345

🍎 Q2. Scenario: Grocery Store (Map)


Scenario: Priya runs a grocery store. She wants to store item names and their
prices: {"apple": 50, "banana": 30, "milk": 70}.
Question: Use a map to store items and print each item with its price.
STL Concept: map
Syntax & Explanation:
#include <iostream>
#include <map>
using namespace std;

int main() {
map<string, int> items = {{"apple", 50}, {"banana", 30}, {"milk", 70}};
for (auto it : items)
cout << it.first << ": " << it.second << endl;
return 0;
}
Expected Output:
apple: 50
banana: 30
milk: 70

✈️Q3. Scenario: Flight Bookings (Set)


Scenario: A travel company wants to record unique destinations booked today:
{"Paris", "London", "New York", "Paris"}.
Question: Use a set to remove duplicates and display destinations.
STL Concept: set
Syntax & Explanation:
#include <iostream>
#include <set>
using namespace std;

int main() {
set<string> destinations = {"Paris", "London", "New York", "Paris"};
for (const auto& city : destinations)
cout << city << endl;
return 0;
}
Expected Output:
London
New York
Paris

🔜 Next Steps
I’ll now create:
 50 scenario-based questions like the above
 For each: STL used, syntax/methods, expected results
Would you like me to prepare:
 A downloadable Word/PDF file with all 50?
 Or should I start listing the next 10 here for review before continuing with
the rest?
Let me know how you'd like to proceed.

You might also like