From 8dd9b39fa54a91030cdd5fe71973f78f7e8089e0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 10 May 2024 11:33:50 +0300 Subject: [w12] Solved exercises 1 and 3 --- week12/Exercise3/TelecommunicationCompany.cpp | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 week12/Exercise3/TelecommunicationCompany.cpp (limited to 'week12/Exercise3/TelecommunicationCompany.cpp') diff --git a/week12/Exercise3/TelecommunicationCompany.cpp b/week12/Exercise3/TelecommunicationCompany.cpp new file mode 100644 index 0000000..b059edb --- /dev/null +++ b/week12/Exercise3/TelecommunicationCompany.cpp @@ -0,0 +1,47 @@ +#include "TelecommunicationCompany.h" +#include "MobileDevice.h" + +void TelecommunicationCompany::free() { + for (int i = 0; i < size; i++) { + delete devices[i]; + } + delete[] devices; +} + +void TelecommunicationCompany::resize() { + allocated *= 2; + MobileDevice** moreDevices = new MobileDevice*[allocated]; + for (int i = 0; i < size; i++) { + moreDevices[i] = devices[i]; + } + delete[] devices; + devices = moreDevices; +} + +TelecommunicationCompany::TelecommunicationCompany() { + devices = nullptr; + allocated = size = 0; +} + +TelecommunicationCompany::~TelecommunicationCompany() { + free(); +} + +TelecommunicationCompany::TelecommunicationCompany(TelecommunicationCompany&& other) { + this->size = other.size; + this->allocated = other.allocated; + this->devices = other.devices; + other.devices = nullptr; +} + +TelecommunicationCompany& TelecommunicationCompany::operator=(TelecommunicationCompany&& other) { + if (this != &other) { + free(); + + this->size = other.size; + this->allocated = other.allocated; + this->devices = other.devices; + other.devices = nullptr; + } + return *this; +} -- cgit v1.2.3