diff options
| author | Syndamia <kamen@syndamia.com> | 2024-03-28 09:43:24 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-03-28 09:43:24 +0200 |
| commit | 70c2c3eab85bee3100ce1c749af03937a6e11e17 (patch) | |
| tree | de11302f6187f2234485381af99cf131aa9e210b /week05/Exercise1.cpp | |
| parent | 96fc3d9205fb4fd8ecff960f44ae2e3def929882 (diff) | |
| download | oop-2023-solutions-70c2c3eab85bee3100ce1c749af03937a6e11e17.tar oop-2023-solutions-70c2c3eab85bee3100ce1c749af03937a6e11e17.tar.gz oop-2023-solutions-70c2c3eab85bee3100ce1c749af03937a6e11e17.zip | |
[w5] Added solutions to exercises 1-7
Diffstat (limited to 'week05/Exercise1.cpp')
| -rw-r--r-- | week05/Exercise1.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/week05/Exercise1.cpp b/week05/Exercise1.cpp new file mode 100644 index 0000000..28fc290 --- /dev/null +++ b/week05/Exercise1.cpp @@ -0,0 +1,32 @@ +struct Patient { + unsigned id; + char name[1024]; +}; + +struct Hospital { +private: + Patient* patients; + unsigned maxPatients; + unsigned lastIndex; + +public: + Hospital(unsigned maxPatients) { + this->maxPatients = maxPatients; + patients = new Patient[maxPatients]; + lastIndex = 0; + } + ~Hospital() { + delete[] patients; + } + + void AddPatient(const Patient& newPatient) { + if (lastIndex == maxPatients) return; + patients[lastIndex++] = newPatient; + } + + // По принцип логиката трябва да е по-сложна, да се маха пациент по индекс и + // след това да се изместват останалите, но за целите на задачата това не е нужно + void RemovePatient() { + lastIndex--; + } +}; |
