From f18c44909c604a01bb0265d006a84223ee88d603 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 1 Mar 2026 18:33:54 +0200 Subject: feat(Week02): Add solutions --- Week02/Exercise04/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Week02/Exercise04/main.cpp (limited to 'Week02/Exercise04/main.cpp') diff --git a/Week02/Exercise04/main.cpp b/Week02/Exercise04/main.cpp new file mode 100644 index 0000000..c02fd21 --- /dev/null +++ b/Week02/Exercise04/main.cpp @@ -0,0 +1,35 @@ +#include +#include "product.h" + +int main() { + unsigned productsCount; + std::cin >> productsCount; + + Product* products = new Product[productsCount]; + + for (unsigned i = 0; i < productsCount; ++i) { + std::cin >> products[i].ID; + std::cin.ignore(); + std::cin.getline(products[i].name, MAX_NAME_LENGTH); + } + + for (unsigned i = 0; i < productsCount; ++i) { + unsigned ID, stockSize; + std::cin >> ID >> stockSize; + + for (unsigned i = 0; i < productsCount; ++i) { + if (products[i].ID == ID) { + products[i].stockSize = stockSize; + break; + } + } + } + + for (unsigned i = 0; i < productsCount; ++i) { + std::cout << products[i].name << ": " << products[i].stockSize << std::endl; + } + + delete[] products; + + return 0; +} -- cgit v1.3.1-23-gd82d