From 6c1d22551025a4999948c640b134ee350e091292 Mon Sep 17 00:00:00 2001 From: barnestr Date: Wed, 16 Mar 2022 09:57:42 -0500 Subject: [PATCH] lab 2 start --- Lecture/Week2/dog.cpp | 27 +++++++++++++++++++++++++++ Lecture/Week2/dog.h | 10 ++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Lecture/Week2/dog.cpp create mode 100644 Lecture/Week2/dog.h diff --git a/Lecture/Week2/dog.cpp b/Lecture/Week2/dog.cpp new file mode 100644 index 0000000..107089c --- /dev/null +++ b/Lecture/Week2/dog.cpp @@ -0,0 +1,27 @@ +#include +#include "dog.h" +using namespace std; + +Dog::Dog(int age, int namelength, char * name) { + this->age = age; + this->namelength = namelength; + this->name = new char[namelength]; + for(int i = 0; i < namelength; i++){ + this->name[i] = name[i]; + } +} + +Dog::~Dog(){ + if(this->namelength > 0){ + delete[] this->name; + } +} + +Dog::Dog(const Dog& from){ + this->age = from.age; + this->namelength = from.namelength; + this->name = new char[this->namelength]; + for(int i = 0; i< this->namelength; i++){ + this->name[i] = from.name[i]; + } +} \ No newline at end of file diff --git a/Lecture/Week2/dog.h b/Lecture/Week2/dog.h new file mode 100644 index 0000000..ca150fe --- /dev/null +++ b/Lecture/Week2/dog.h @@ -0,0 +1,10 @@ +using namespace std; + +class Dog { + public: + Dog(int age, int namelength, char * name); + ~Dog(); + int age; + int namelength; + char * name; +}; \ No newline at end of file