Modifying and adding elements
📖 Scenario: You are managing a list of fruits in a basket. Sometimes you need to change a fruit or add a new one to keep the basket fresh and interesting.
🎯 Goal: You will create a vector of fruits, then modify one fruit's name, add a new fruit, and finally display the updated basket.
📋 What You'll Learn
Create a vector called
basket with the fruits: "apple", "banana", "cherry"Create a variable called
replace_index and set it to 2Replace the fruit at position
replace_index in basket with "blueberry"Add the fruit
"date" to the end of basketPrint the updated
basket vector💡 Why This Matters
🌍 Real World
Managing lists of items like groceries, tasks, or favorites often requires changing or adding elements to keep the list current.
💼 Career
Knowing how to modify and add elements in data structures is essential for data cleaning, updating records, and managing collections in many programming jobs.
Progress0 / 4 steps