Project Setup
Part of the Logic & Flow section of Coddy's C++ journey — lesson 30 of 56.
Challenge
EasyWe will build an inventory tracking tool.
Create a program that sets up a basic inventory tracking system for a small store. Your program will initialize a std::map<std::string, int> to store item names and their quantities, add some initial inventory items, and display a confirmation message.
Your program should:
- Create a
std::map<std::string, int>namedinventory - Add the following items to the inventory using the square bracket notation:
"Laptops"with quantity15"Mice"with quantity42"Keyboards"with quantity28"Monitors"with quantity12
- Print the initial inventory showing all items and their quantities
- Print a confirmation message that the inventory system is ready
Use the following exact output format:
Initial Inventory Setup:
Keyboards: 28
Laptops: 15
Mice: 42
Monitors: 12
Inventory system is ready!The items should be printed in the order they appear when iterating through the map (alphabetical order by item name). Use a range-based for loop to iterate through the map, accessing each key-value pair with pair.first for the item name and pair.second for the quantity.
Try it yourself
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
// TODO: Write your code below
return 0;
}All lessons in Logic & Flow
1Pointers and Memory
What is a Pointer?Address-Of OperatorDereference OperatorNull PointersPointers and ArraysDynamic Memory with 'new'Freeing Memory with 'delete'Recap - Pointer Practice2Vectors (Dynamic Arrays)
Introducing std::vectorCreating a VectorAdding ElementsAccessing ElementsVector SizeIterating with a For LoopRange-Based For LoopRemoving ElementsRecap - Vector Operations5Project: Inventory Tool
Project SetupAdding and Updating Items