From 5624cd9b63bec13fc464a3d7820d703abd8de113 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 8 Mar 2026 19:54:32 +0200 Subject: feat(Week03): Add solution to first exercise --- Week03/Exercise01/Product.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Week03/Exercise01/Product.cpp (limited to 'Week03/Exercise01/Product.cpp') diff --git a/Week03/Exercise01/Product.cpp b/Week03/Exercise01/Product.cpp new file mode 100644 index 0000000..1bfa66e --- /dev/null +++ b/Week03/Exercise01/Product.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "Product.h" + +void ProductArray::add(const Product& product) { + if (count >= allocated) { + std::cout << "No more products are allowed!" << std::endl; + return; + } + + products[count++] = product; +} + +Product* ProductArray::find(char* username) { + for (unsigned i = 0; i < count; ++i) + if (strcmp(username, products[i].name) == 0) + return &products[i]; + return nullptr; +} + +ProductArray newProductArray(unsigned allocatedSize) { + ProductArray pa; + pa.products = new Product[allocatedSize]; + pa.count = 0; + pa.allocated = allocatedSize; + return pa; +} + +void deleteProductArray(ProductArray& pa) { + delete[] pa.products; + pa.products = nullptr; + pa.count = pa.allocated = 0; +} -- cgit v1.3.1-23-gd82d