summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-19 21:50:27 +0200
committerOskar <[email protected]>2024-09-19 21:50:27 +0200
commitc6d7e8e9a6cd4e31b259f9671510f7bee4d47b65 (patch)
treef31623c23e66a840ee08297c43b0bf9ad88a227f
parenta10a6e35975660b89b465faf5baacd6df9c43a34 (diff)
more
-rw-r--r--7p15.cpp8
-rw-r--r--7p16.cpp13
-rw-r--r--7p17.cpp14
-rw-r--r--7p18.cpp15
-rw-r--r--7p19.cpp14
-rw-r--r--person.hpp3
6 files changed, 66 insertions, 1 deletions
diff --git a/7p15.cpp b/7p15.cpp
index 58d5fbf..8a6662c 100644
--- a/7p15.cpp
+++ b/7p15.cpp
@@ -1,12 +1,18 @@
#include <iostream>
+#include "person.hpp"
/*
*
- * Description
+ * 7.15
*
*
*/
int main () {
+
+ Person p1("John Doe");
+ Person p2("Jane Doe", "Street Street 1");
+ std::cout << p1.GetName() << " " << p1.GetAddress() << std::endl;
+ std::cout << p2.GetName() << " " << p2.GetAddress() << std::endl;
return 0;
}
diff --git a/7p16.cpp b/7p16.cpp
new file mode 100644
index 0000000..36f2ff1
--- /dev/null
+++ b/7p16.cpp
@@ -0,0 +1,13 @@
+
+/*
+ *
+ * 7.16
+ *
+ *
+ */
+
+int main () {
+
+ // It does not really matter if there are no access specifiers or if you choose to have both or only one of them.
+ return 0;
+}
diff --git a/7p17.cpp b/7p17.cpp
new file mode 100644
index 0000000..6f54eca
--- /dev/null
+++ b/7p17.cpp
@@ -0,0 +1,14 @@
+
+/*
+ *
+ * 7.17
+ *
+ *
+ */
+
+int main () {
+
+ // class is private by default
+ // struct is public by default
+ return 0;
+}
diff --git a/7p18.cpp b/7p18.cpp
new file mode 100644
index 0000000..fa1c047
--- /dev/null
+++ b/7p18.cpp
@@ -0,0 +1,15 @@
+
+/*
+ *
+ * 7.18
+ *
+ *
+ */
+
+int main () {
+
+ // We dont need to expose functions and data members that should only be
+ // accessed or used by the public functions.
+ // There are some things that the user does not need to know about when using the class.
+ return 0;
+}
diff --git a/7p19.cpp b/7p19.cpp
new file mode 100644
index 0000000..7622cb4
--- /dev/null
+++ b/7p19.cpp
@@ -0,0 +1,14 @@
+
+/*
+ *
+ * 7.19
+ *
+ *
+ */
+
+int main () {
+
+ //Name and Address members should be private
+ // The rest public
+ return 0;
+}
diff --git a/person.hpp b/person.hpp
index 9d1e7ea..29d0150 100644
--- a/person.hpp
+++ b/person.hpp
@@ -4,6 +4,9 @@
#include <vector>
struct Person {
+ Person() = default;
+ Person(const std::string &name): Name(name) {}
+ Person(const std::string &name, const std::string &addr): Name(name), Address(addr) {}
std::string Name;
std::string Address;
std::string GetAddress() const { return Address; }