Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 09-Practice-19.04.2022 / HranaLemur.cpp
diff options
context:
space:
mode:
1 files changed, 30 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/09-Practice-19.04.2022/HranaLemur.cpp30
diff --git a/Year 1/Object-oriented Programming/09-Practice-19.04.2022/HranaLemur.cpp b/Year 1/Object-oriented Programming/09-Practice-19.04.2022/HranaLemur.cpp
new file mode 100644
index 0000000..4dc9c22
--- /dev/null
+++ b/Year 1/Object-oriented Programming/09-Practice-19.04.2022/HranaLemur.cpp
@@ -0,0 +1,30 @@
+#include "HranaLemur.h"
+#include <cstring>
+#include <iostream>
+
+int HranaLemur::indexOfRestaurant(const char* name) {
+ for (int i = 0; i < restaurantsCount; i++) {
+ if (strcmp(restaurants[i].get_name(), name) == 0)
+ return i;
+ }
+ return -1;
+}
+
+void HranaLemur::handleOrder(Order order) {
+ int rest = indexOfRestaurant(order.get_restaurantName());
+ if (rest < 0) {
+ std::cout << "Restaurant " << order.get_restaurantName() << " doesn't exist!" << std::endl;
+ return;
+ }
+
+ try {
+ int time = restaurants[rest].giveOrder(order);
+ std::cout << "Order will take: " << time << std::endl;
+ }
+ catch (int errorCode) {
+ if (errorCode == 1)
+ std::cout << "The restaurant doesn't offer some product!" << std::endl;
+ else
+ throw errorCode;
+ }
+}