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/ 3
Exercises with set
1. Check if a Value Exists in a Set
Write a C++ program that checks if a given value exists in a set. Example Input: Set {1, 2, 3, 4, 5}, Check for 3 Output: 3 exists in the set 2. Remove a Value from a Set Write a C++ program that removes a specified value from a set and prints the updated set. Example Input: Set {10, 20, 30, 40}, Remove 30 Output: 10 20 40 3. Find the Size of a Set Write a C++ program that finds and prints the size of a set after inserting elements. Example Input: {2, 4, 6, 8, 10} Output: Size of the set: 5
Exercises with map
1. Create and Print a Map Write a C++ program that creates a map (key-value pairs), inserts values, and prints the map. Example Input: Map {1: "apple", 2: "banana"} Output: 1 -> apple, 2 -> banana 2. Find a Value Using a Key in a Map Write a C++ program that takes a key and finds the corresponding value in a map. Example Input: Map {1: "apple", 2: "banana"}, Search key 1 Output: apple 3. Update the Value of an Existing Key in a Map Write a C++ program that updates the value of an existing key in a map. Example Input: Map {1: "apple", 2: "banana"}, Update key 1 to orange Output: 1 -> orange, 2 -> banana 4. Remove a Key-Value Pair from a Map Write a C++ program that removes a key-value pair from the map and prints the updated map. Example Input: Map {1: "apple", 2: "banana"}, Remove key 1 Output: 2 -> banana 5. Find the Size of a Map Write a C++ program that finds and prints the size of a map after adding some key-value pairs. Example Input: {1: "apple", 2: "banana", 3: "cherry"} Output: Size of the map: 3
Exercises with stack
1. Create and Print a Stack Write a C++ program that creates a stack, pushes some values onto it, and prints the stack. Example Input: Stack {10, 20, 30} Output: Top of stack: 30 2. Pop an Element from a Stack Write a C++ program that pops the top element from the stack and prints the updated stack. Example Input: Stack {10, 20, 30}, Pop once Output: Top of stack after pop: 20 3. Check if a Stack is Empty Write a C++ program that checks whether a stack is empty and prints the result. Example Input: Stack {5, 10, 15} Output: Stack is not empty 4. Reverse a Sequence Using Stack Write a C++ program that reverses a sequence of integers using a stack. Example Input: Sequence {1, 2, 3, 4, 5} Output: Reversed Sequence: 5 4 3 2 1 5. Count the Number of Elements in a Stack Write a C++ program that counts and prints the number of elements in a stack. Example Input: Stack {1, 2, 3, 4, 5} Output: Number of elements in stack: 5