From 1792d08e9e5d56bc1ab477a8b1fec0ce1446d012 Mon Sep 17 00:00:00 2001 From: Oskar Date: Fri, 6 Sep 2024 15:05:39 +0200 Subject: more --- 6p16.cpp | 19 +++++++++++++++++++ 6p17.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6p18.cpp | 12 ++++++++++++ 6p19.cpp | 12 ++++++++++++ 6p20.cpp | 12 ++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 6p16.cpp create mode 100644 6p17.cpp create mode 100644 6p18.cpp create mode 100644 6p19.cpp create mode 100644 6p20.cpp 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 + +/* + * + * 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 +#include + +/* + * + * 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 + +/* + * + * 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 + +/* + * + * 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 + +/* + * + * Description + * + * + */ + +int main () { + return 0; +} -- cgit v1.2.3