diff options
| author | Syndamia <kamen@syndamia.com> | 2024-03-07 17:18:24 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-03-07 17:18:24 +0200 |
| commit | 449d0043523f13b4fd273e381b192b6fe10baefd (patch) | |
| tree | 81de2f9762aacc3331ccdf70956ebceb3b432da4 /week03/Exercise4.cpp | |
| parent | 83474fef7d7b495502db0c0a22665f43739dd8b9 (diff) | |
| download | oop-2023-solutions-449d0043523f13b4fd273e381b192b6fe10baefd.tar oop-2023-solutions-449d0043523f13b4fd273e381b192b6fe10baefd.tar.gz oop-2023-solutions-449d0043523f13b4fd273e381b192b6fe10baefd.zip | |
[w3] Added solutions for revision exercises
Diffstat (limited to 'week03/Exercise4.cpp')
| -rw-r--r-- | week03/Exercise4.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/week03/Exercise4.cpp b/week03/Exercise4.cpp new file mode 100644 index 0000000..006b196 --- /dev/null +++ b/week03/Exercise4.cpp @@ -0,0 +1,36 @@ +struct Bus { + unsigned int passengerCapacity; + unsigned int mileage; +}; + +struct BusWarehouse { +private: + Bus* buses; + int maxSize; + int lastIndex; + +public: + BusWarehouse(int maxSize) { + this->maxSize = maxSize; + buses = new Bus[maxSize]; + lastIndex = 0; + } + + ~BusWarehouse() { + delete[] buses; + } + + void AddBus(const Bus& bus) { + if (maxSize == lastIndex) return; + buses[lastIndex++] = bus; + } +}; + +int main() { + Bus b1 = { 20, 100000 }; + Bus b2 = { 50, 90812 }; + + BusWarehouse bw = BusWarehouse(2); + bw.AddBus(b1); + bw.AddBus(b2); +} |
