C++ Zone Report Project
Aggregate valid owned records by zone and print a reproducible ordered report.
Your brief
Build a report from a fixed batch of zone names and counts. Reject invalid counts and empty zone names before updating the summary. The bounded fixture uses at most four records of at most one hundred parcels, so an int total is representable. A real unbounded ingestion service needs a checked accumulator and a record-size/count limit. Choose an ordered map because deterministic alphabetical report order is a requirement here, not because every keyed operation should use a tree.
Run it locally
Use a C++20 compiler and matching standard library in a separate lab folder. The command uses c++; substitute g++, clang++ or zig c++ for your toolchain. C++ does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed.
c++ -std=c++20 -Wall -Wextra -Wpedantic -Werror summary-project.cpp -o lessonOn Windows use -o lesson.exe and run .\lesson.exe in PowerShell. On Unix-like systems run ./lesson. Thread examples may need -pthread on your platform.
Download the complete C++ source. Run file labs in a private empty directory, away from existing reports.
Worked solution
Show the worked solution
#include <iostream>
#include <map>
#include <string>
#include <vector>
struct Entry { std::string zone; int parcels; };
int main() {
const std::vector<Entry> input{{"West", 4}, {"East", 2}, {"West", 3}, {"East", -1}};
std::map<std::string, int> totals;
for (const auto& entry : input) {
if (entry.zone.empty() || entry.parcels < 0 || entry.parcels > 100) { continue; }
totals[entry.zone] += entry.parcels;
}
for (const auto& [zone, parcels] : totals) { std::cout << zone << ": " << parcels << '\n'; }
}
Expected result
East: 2
West: 7
operator[] is intentional in this aggregation because a new valid zone should start with a zero mapped count. The negative record is skipped rather than accidentally subtracting parcels from the total. Separating validation from accumulation makes the rule clear. A production manifest should report rejected-record diagnostics instead of silently losing data when that would mislead its user.
Extend and test
Replace skipping with an explicit accepted/rejected report. Add checked accumulation for a stream of unknown length and test a repeated zone near the numeric limit.
Consult the WG21 C++ working group and the C++ Core Guidelines for language references and design guidance. Check the selected standard version and your implementation’s library support.