Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 11 / Examples / Student
diff options
context:
space:
mode:
Commit5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-05-10 20:06:53 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-05-10 20:06:53 +0300
Files52f913ec9532fd07c8f679ccf1e68876d1fc9ff2 /Sem. 11/Examples/Student
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.tar
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.tar.gz
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.zip
Parent459d3ac280aafdba703930455f3200b6e7b0f31b (diff)
sem 11
2 files changed, 59 insertions, 0 deletions
-rw-r--r--Sem. 11/Examples/Student/Student.cpp34
-rw-r--r--Sem. 11/Examples/Student/Student.h25
diff --git a/Sem. 11/Examples/Student/Student.cpp b/Sem. 11/Examples/Student/Student.cpp
new file mode 100644
index 0000000..8b5b04c
--- /dev/null
+++ b/Sem. 11/Examples/Student/Student.cpp
@@ -0,0 +1,34 @@
+#include "Student.h"
+
+Student::Student(const char* name, int age, size_t fn) : Person(name, age)
+{
+ setFn(fn);
+}
+
+size_t Student::getFn() const
+{
+ return fn;
+}
+
+void Student::setFn(size_t fn)
+{
+
+ if (fn < 100)
+ fn = 100;
+ this->fn = fn;
+}
+
+// The compiler will make:
+
+//Student(const Student& other) : Person(other), fn(other.fn), grade(other.grade) OK!!!
+//{}
+
+//Student& operator=(const Student& other) OK!!!!
+//{
+// if (this != &other)
+// {
+// Person::operator=(other); //handles the deletion and copying of the base class
+// fn = other.fn;
+// }
+// return *this;
+//} \ No newline at end of file
diff --git a/Sem. 11/Examples/Student/Student.h b/Sem. 11/Examples/Student/Student.h
new file mode 100644
index 0000000..af99e30
--- /dev/null
+++ b/Sem. 11/Examples/Student/Student.h
@@ -0,0 +1,25 @@
+#include <iostream>
+#include "../Person/Person.h"
+
+class Student : public Person
+{
+ size_t fn = 0;
+ size_t grade = 2;
+public:
+ Student() = default;
+ Student(const char* name, int age, size_t fn);
+
+ size_t getFn() const;
+ void setFn(size_t fn);
+
+
+ // No need for big 4, since there is NO dyn. memory in Student
+ // The compiler will generate valid:
+
+ //Student(const Student& other);
+ //Student& operator=(const Student& other); //no need
+ // ~Student()
+
+ //See on the .cpp file how the compiler creates them
+
+};