From 449d0043523f13b4fd273e381b192b6fe10baefd Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 7 Mar 2024 17:18:24 +0200 Subject: [w3] Added solutions for revision exercises --- week03/Exercise3.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 week03/Exercise3.cpp (limited to 'week03/Exercise3.cpp') 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 +#include + +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"); +} -- cgit v1.2.3