aboutsummaryrefslogtreecommitdiff
path: root/week05/Exercise1.cpp
blob: 7fdaa7da7741b126d5b92e1c88a37622c213cbad (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
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(int index) {
		for (int i = index; i < lastIndex - 1; i++) {
			patients[i] = patients[i+1];
		}
		lastIndex--;
	}
};