Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04
diff options
context:
space:
mode:
Commitb3c27f3d075489d7299eb90f121c8f4878b88dbe (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-03-15 19:44:55 +0200
Committer
 GitHub <noreply@github.com>
2022-03-15 19:44:55 +0200
Filesc03c47963d669734c8496bac0f059b9be58497ce /Sem. 04
Object-oriented_programming_FMI-b3c27f3d075489d7299eb90f121c8f4878b88dbe.tar
Object-oriented_programming_FMI-b3c27f3d075489d7299eb90f121c8f4878b88dbe.tar.gz
Object-oriented_programming_FMI-b3c27f3d075489d7299eb90f121c8f4878b88dbe.zip
Parent8436169710fca49323771f429abe9822416acb5d (diff)
Create Student_example.cpp
1 files changed, 37 insertions, 0 deletions
-rw-r--r--Sem. 04/Student_example.cpp37
diff --git a/Sem. 04/Student_example.cpp b/Sem. 04/Student_example.cpp
new file mode 100644
index 0000000..954b3bf
--- /dev/null
+++ b/Sem. 04/Student_example.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <fstream>
+#include <cstring>
+using namespace std;
+
+struct Student
+{
+ char* name;
+ int age;
+
+ Student(const char* name, int age)
+ {
+ this->name = new char[strlen(name) + 1];
+ strcpy(this->name, name);
+ this->age = age;
+ }
+
+ void print() const
+ {
+ std::cout << "Name: " << name << ", age: " << age << std::endl;
+ }
+ ~Student()
+ {
+ delete[] name;
+ }
+};
+int main()
+{
+ Student s("Ivan", 33);
+
+ Student* ptr = new Student("Petur", 17);
+
+ s.print();
+ ptr->print();
+
+ delete ptr; //calls destructor of ptr
+}//calls destructor of s