diff options
author | Oskar <[email protected]> | 2024-09-06 15:05:39 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-06 15:05:39 +0200 |
commit | 1792d08e9e5d56bc1ab477a8b1fec0ce1446d012 (patch) | |
tree | 37ee250d758d93c37de41c927661269fb82bfe81 /6p17.cpp | |
parent | 60789ab73d4987068114b0342e71a63f81f65c68 (diff) |
more
Diffstat (limited to '6p17.cpp')
-rw-r--r-- | 6p17.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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; +} |