From c6d7e8e9a6cd4e31b259f9671510f7bee4d47b65 Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 19 Sep 2024 21:50:27 +0200 Subject: more --- 7p15.cpp | 8 +++++++- 7p16.cpp | 13 +++++++++++++ 7p17.cpp | 14 ++++++++++++++ 7p18.cpp | 15 +++++++++++++++ 7p19.cpp | 14 ++++++++++++++ person.hpp | 3 +++ 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 7p16.cpp create mode 100644 7p17.cpp create mode 100644 7p18.cpp create mode 100644 7p19.cpp diff --git a/7p15.cpp b/7p15.cpp index 58d5fbf..8a6662c 100644 --- a/7p15.cpp +++ b/7p15.cpp @@ -1,12 +1,18 @@ #include +#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 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; } -- cgit v1.2.3