Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit708d47275d92e41bf5dbdb25c1a510a9710c04b6 (patch)
Author
 Angeld55 <achi_d@abv.bg>
2019-09-18 20:54:00 +0300
Committer
 GitHub <noreply@github.com>
2019-09-18 20:54:00 +0300
Files3834a3de958eb94bceaad25484a702386c5c333a
Object-oriented_programming_FMI-708d47275d92e41bf5dbdb25c1a510a9710c04b6.tar
Object-oriented_programming_FMI-708d47275d92e41bf5dbdb25c1a510a9710c04b6.tar.gz
Object-oriented_programming_FMI-708d47275d92e41bf5dbdb25c1a510a9710c04b6.zip
Parentcebf72b098023f1e954986cf315eac584f56eb63 (diff)
Create InformaticsStudent.cpp
1 files changed, 84 insertions, 0 deletions
-rw-r--r--Big4/InformaticsStudent.cpp84
diff --git a/Big4/InformaticsStudent.cpp b/Big4/InformaticsStudent.cpp
new file mode 100644
index 0000000..3ab4ab4
--- /dev/null
+++ b/Big4/InformaticsStudent.cpp
@@ -0,0 +1,84 @@
+#include "InformaticsStudent.h"
+
+
+void InformaticsStudent::CopyFrom(const InformaticsStudent& other)
+{
+ int len = strlen(other.name);
+ name = new char[len + 1];
+ strcpy(name, other.name); //copy name
+ fn = other.fn; //copy fn
+}
+void InformaticsStudent::Free()
+{
+ delete[] name;
+ fn = 0;
+}
+
+InformaticsStudent::InformaticsStudent()
+{
+ name = nullptr;
+ fn = 0;
+}
+
+InformaticsStudent::InformaticsStudent(const char* name, int fn)
+{
+ setName(name);
+ setFn(fn);
+}
+
+
+InformaticsStudent::InformaticsStudent(const InformaticsStudent& other)
+{
+ CopyFrom(other); //копирам от другия обект(няма нужда да трия памет от себе си, понже това е конструктор и обекта сега се създава)
+}
+
+InformaticsStudent& InformaticsStudent::operator=(const InformaticsStudent& other)
+{
+ if (this != &other)
+ {
+ Free(); //трия своята памет
+
+ CopyFrom(other); // копирам от другия обект
+ }
+ return *this;
+}
+
+InformaticsStudent::~InformaticsStudent()
+{
+ Free();
+}
+// BIG 4 ends here
+
+void InformaticsStudent::setName(const char* name)
+{
+ delete[] name; //трием данните, които са били тук.
+ int len = strlen(name);
+ if (hasDigits(name, len))
+ {
+ this->name[0] = '\0';
+ return;
+ }
+ this->name = new char[len + 1];
+ strcpy(this->name, name);
+
+
+}
+void InformaticsStudent::setFn(int fn)
+{
+ if (fn < 45000 || fn >45999)
+ fn = 45000;
+ this->fn = fn;
+}
+const InformaticsStudent::char* getName() const
+{
+ return name;
+}
+int InformaticsStudent::getFn() const
+{
+ return fn;
+}
+
+void printStudent()
+{
+ cout << name << " fn: " << fn << endl;
+}