Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise04
diff options
context:
space:
mode:
Commitf18c44909c604a01bb0265d006a84223ee88d603 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-03-01 18:33:54 +0200
Committer
 Syndamia <kamen@syndamia.com>
2026-03-01 18:33:54 +0200
Files513a5b000add253f698901c7d636ed921f6913f2 /Week02/Exercise04
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar.gz
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.zip
Parentfcf38e62e8160f2c9901bdfd33760afed28beb8d (diff)
feat(Week02): Add solutions
2 files changed, 47 insertions, 0 deletions
-rw-r--r--Week02/Exercise04/main.cpp35
-rw-r--r--Week02/Exercise04/product.h12
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 <iostream>
+#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;
+}
diff --git a/Week02/Exercise04/product.h b/Week02/Exercise04/product.h
new file mode 100644
index 0000000..e83e5ee
--- /dev/null
+++ b/Week02/Exercise04/product.h
@@ -0,0 +1,12 @@
+#ifndef _PRODUCT
+#define _PRODUCT
+
+static const unsigned MAX_NAME_LENGTH = 256;
+
+struct Product {
+ unsigned ID;
+ char name[MAX_NAME_LENGTH];
+ unsigned stockSize;
+};
+
+#endif