Menu
Coddy logo textTech

Project Setup

Part of the Logic & Flow section of Coddy's C++ journey — lesson 30 of 56.

challenge icon

Challenge

Easy

We 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:

  1. Create a std::map<std::string, int> named inventory
  2. Add the following items to the inventory using the square bracket notation:
    • "Laptops" with quantity 15
    • "Mice" with quantity 42
    • "Keyboards" with quantity 28
    • "Monitors" with quantity 12
  3. Print the initial inventory showing all items and their quantities
  4. 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