diff options
Added work from todays practice
1 files changed, 34 insertions, 0 deletions
| -rw-r--r-- | Year 1/Object-oriented Programming/09-Practice-19.04.2022/Order.cpp | 34 |
diff --git a/Year 1/Object-oriented Programming/09-Practice-19.04.2022/Order.cpp b/Year 1/Object-oriented Programming/09-Practice-19.04.2022/Order.cpp new file mode 100644 index 0000000..530769e --- /dev/null +++ b/Year 1/Object-oriented Programming/09-Practice-19.04.2022/Order.cpp @@ -0,0 +1,34 @@ +#include "Order.h" +#include <cstring> + +void Order::free() { + delete[] products; +} + +void Order::copyFrom(const Order& other) { + strcpy(restaurantName, other.restaurantName); + productCount = other.productCount; + products = new Product[productCount]; + for (int i = 0; i < productCount; i++) + products[i] = other.products[i]; +} + +void Order::move(Order&& other) { + strcpy(restaurantName, other.restaurantName); + other.restaurantName = nullptr; + s +} + +Order::Order(const char* restaurant) { + strcpy(this->restaurantName, restaurant); + products = new Product[8]; + this->productCount = 0; +} + +Order::~Order() { + free(); +} + +void Order::addProduct(const Product& product) { + this->products[productCount++] = product; +} |
