summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-06 15:05:39 +0200
committerOskar <[email protected]>2024-09-06 15:05:39 +0200
commit1792d08e9e5d56bc1ab477a8b1fec0ce1446d012 (patch)
tree37ee250d758d93c37de41c927661269fb82bfe81
parent60789ab73d4987068114b0342e71a63f81f65c68 (diff)
more
-rw-r--r--6p16.cpp19
-rw-r--r--6p17.cpp66
-rw-r--r--6p18.cpp12
-rw-r--r--6p19.cpp12
-rw-r--r--6p20.cpp12
5 files changed, 121 insertions, 0 deletions
diff --git a/6p16.cpp b/6p16.cpp
new file mode 100644
index 0000000..f522098
--- /dev/null
+++ b/6p16.cpp
@@ -0,0 +1,19 @@
+#include <iostream>
+
+/*
+ *
+ * 6.16
+ *
+ *
+ */
+
+bool is_empty(const std::string &a) {
+
+ return a.empty();
+}
+
+int main () {
+
+ std::cout << is_empty("Hello") << std::endl;
+ return 0;
+}
diff --git a/6p17.cpp b/6p17.cpp
new file mode 100644
index 0000000..fcebb9c
--- /dev/null
+++ b/6p17.cpp
@@ -0,0 +1,66 @@
+#include <iostream>
+#include <cctype>
+
+/*
+ *
+ * 6.17
+ *
+ *
+ */
+
+bool contains_captial(const std::string &cs) {
+
+ bool cc = false;
+ for(auto a : cs) {
+ if(isupper(a)) {
+ cc = true;
+ break;
+ }
+ }
+
+ return cc;
+}
+
+void tolower_str(std::string &cs) {
+
+ for(auto &a : cs) {
+ a = tolower(a);
+ }
+}
+
+std::string tolower_str_literals_incl(const std::string &cs) {
+
+ std::string ret = cs;
+ for(auto &a : ret) {
+ a = tolower(a);
+ }
+
+ return ret;
+}
+
+int main () {
+
+ /*
+ They do need to have different types. With contains_capital we only need to read
+ the string and tell if it has an uppercase or not.
+
+ With tolower we actually need to change a string. Or perhaps return a lowercase version.
+ This does mean that we can't use string literals as arguments. Well... If we use a reference.
+
+ We don't actually NEED to use a reference if we really wanted to use literals as well.
+ Because then we need a different approach for the function.
+ There are several different ways we can define this function really.
+ */
+
+ std::cout << contains_captial("hello") << std::endl;
+ std::cout << contains_captial("Hello") << std::endl;
+ std::string aa = "HELLO!!!";
+ std::cout << aa << std::endl;
+ tolower_str(aa);
+ std::cout << aa << std::endl;
+ std::string aa2 = "WOWZA!";
+ std::string aa3 = tolower_str_literals_incl(aa2);
+ std::cout << aa3 << std::endl;
+ std::cout << tolower_str_literals_incl("HIIII!") << std::endl;
+ return 0;
+}
diff --git a/6p18.cpp b/6p18.cpp
new file mode 100644
index 0000000..58d5fbf
--- /dev/null
+++ b/6p18.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * Description
+ *
+ *
+ */
+
+int main () {
+ return 0;
+}
diff --git a/6p19.cpp b/6p19.cpp
new file mode 100644
index 0000000..58d5fbf
--- /dev/null
+++ b/6p19.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * Description
+ *
+ *
+ */
+
+int main () {
+ return 0;
+}
diff --git a/6p20.cpp b/6p20.cpp
new file mode 100644
index 0000000..58d5fbf
--- /dev/null
+++ b/6p20.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * Description
+ *
+ *
+ */
+
+int main () {
+ return 0;
+}