aboutsummaryrefslogtreecommitdiff
path: root/week03
diff options
context:
space:
mode:
Diffstat (limited to 'week03')
-rw-r--r--week03/Exercise1.cpp12
-rw-r--r--week03/Exercise2.cpp45
-rw-r--r--week03/Exercise3.cpp34
-rw-r--r--week03/Exercise4.cpp36
4 files changed, 127 insertions, 0 deletions
diff --git a/week03/Exercise1.cpp b/week03/Exercise1.cpp
new file mode 100644
index 0000000..7490b4c
--- /dev/null
+++ b/week03/Exercise1.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+struct Lightbulb {
+ int diameter;
+ int length;
+ char type[100];
+ char series;
+};
+
+int main() {
+ Lightbulb lb = { 5, 10, "Fluorescent", 'A' };
+}
diff --git a/week03/Exercise2.cpp b/week03/Exercise2.cpp
new file mode 100644
index 0000000..2d7c748
--- /dev/null
+++ b/week03/Exercise2.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <cstring>
+
+struct Alarm {
+private:
+ char modelName[1024];
+ unsigned int pin;
+ float modelRevision;
+
+public:
+ const char* getModelName() {
+ return modelName;
+ }
+ void setModelName(const char* newModel) {
+ for (int i = 0; newModel[i] != '\0'; i++) {
+ if (newModel[i] < 'A' || newModel[i] > 'Z')
+ return;
+ }
+
+ strcpy(modelName, newModel);
+ }
+
+ unsigned int getPin() {
+ return pin;
+ }
+ void setPin(unsigned int newPin) {
+ if (newPin > 9999) return;
+
+ pin = newPin;
+ }
+
+ float getModelRevision() {
+ return modelRevision;
+ }
+ void setModelRevision(float newRevision) {
+ if (newRevision <= 0)
+ return;
+
+ modelRevision = newRevision;
+ }
+};
+
+int main() {
+ TODO
+}
diff --git a/week03/Exercise3.cpp b/week03/Exercise3.cpp
new file mode 100644
index 0000000..9d4a834
--- /dev/null
+++ b/week03/Exercise3.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <cstring>
+
+struct Person {
+private:
+ char* firstName;
+ char* lastName;
+ unsigned int age;
+ char* email;
+
+public:
+ Person(const char* firstName, const char* lastName, unsigned int age, const char* email) {
+ this->firstName = new char[strlen(firstName)];
+ strcpy(this->firstName, firstName);
+
+ this->lastName = new char[strlen(lastName)];
+ strcpy(this->lastName, lastName);
+
+ this->age = age;
+
+ this->email = new char[strlen(email)];
+ strcpy(this->email, email);
+ }
+
+ ~Person() {
+ delete[] firstName;
+ delete[] lastName;
+ delete[] email;
+ }
+};
+
+int main() {
+ Person p = Person("John", "Doe", 21, "john.doe@email.com");
+}
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);
+}