aboutsummaryrefslogtreecommitdiff
path: root/week03/Exercise4.cpp
blob: 006b19675863d3b1a426adec28d5b90dcb47dd43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}