C++ · Intermediate level

Intermediate level · Module 6: Intermediate C++ Project · Lesson 1 of 3

Designing the Stock Manager

Plan classes, files and rules for the pharmacy application before writing code.

In this lesson you will

  • Identify classes and responsibilities for the application
  • Specify rules and how each will be checked

Key concepts

class responsibilitiesheader layoutrule specificationdate handling

The lesson

Identify the main types: Medicine (name, reorder level), Batch (quantity, expiry date) and an Inventory that holds them and enforces the rules. File loading and saving belong in a separate component.

Write each rule in one sentence and decide how it will be checked: 'An expired batch is never dispensed', 'Dispensing takes from the batch that expires first', 'Stock never goes below zero'. Each rule becomes code and at least one check.

Dates can be represented with std::chrono::year_month_day (C++20) or as ISO text such as 2026-05-04 that compares correctly as a string. Choose one approach and use it everywhere.

Step by step

  1. List the classes and their responsibilities.
  2. Write the rules and their checks.
  3. Create the CMake skeleton with empty classes.
  4. Review the design with a partner.

Practice activity

Submit the design and a skeleton project that builds with CMake.

Expected result: An approved design and a skeleton that builds without warnings.

Check your understanding

  1. Why keep file loading separate from Inventory?

    Show answer

    So the stock rules can be checked without files and storage can change independently.

  2. Why does ISO date text such as 2026-05-04 compare correctly as a string?

    Show answer

    The most significant parts come first and have fixed widths.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.