Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 10 / example2.cpp
diff options
context:
space:
mode:
Commitd3150b67f0b98c4c7a08e4b297d5fcb723cf609f (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-12-15 21:09:37 +0200
Committer
 GitHub <noreply@github.com>
2021-12-15 21:09:37 +0200
Filesf1b0e86562ee57e5a6e7325c8d379c93a290ed04 /Sem. 10/example2.cpp
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.tar
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.tar.gz
Introduction_to_programming_FMI-d3150b67f0b98c4c7a08e4b297d5fcb723cf609f.zip
Parentba3352b47a17e81e27a565de2bc531f326c9c90d (diff)
Add files via upload
1 files changed, 64 insertions, 0 deletions
-rw-r--r--Sem. 10/example2.cpp64
diff --git a/Sem. 10/example2.cpp b/Sem. 10/example2.cpp
new file mode 100644
index 0000000..5ae389c
--- /dev/null
+++ b/Sem. 10/example2.cpp
@@ -0,0 +1,64 @@
+#include <iostream>
+using namespace std;
+
+
+bool isLower(char ch)
+{
+ return 'a' <= ch && ch <= 'z';
+}
+bool isUpper(char ch)
+{
+ return 'A' <= ch && ch <= 'Z';
+}
+void countLowerAndCapitalLetters(const char* str, unsigned& lowerCount, unsigned& capitalCount)
+{
+ while (*str != '\0')
+ {
+ if (isLower(*str))
+ lowerCount++;
+ else if (isUpper(*str))
+ capitalCount++;
+
+ str++;
+ }
+}
+void getTwoStrings(const char* str, char*& lowerStr, char*& upperStr)
+{
+ unsigned lowerCount = 0;
+ unsigned upperCount = 0;
+ countLowerAndCapitalLetters(str, lowerCount, upperCount);
+
+ char* lowerSymbolsString = new char[lowerCount + 1];
+ char* upperSymbolsString = new char[upperCount + 1];
+ unsigned lowerIter = 0;
+ unsigned upperIter = 0;
+
+ while (*str != '\0')
+ {
+ if (isLower(*str))
+ lowerSymbolsString[lowerIter++] = *str;
+ else if (isUpper(*str))
+ upperSymbolsString[upperIter++] = *str;
+ str++;
+ }
+ lowerSymbolsString[lowerIter] = '\0';
+ upperSymbolsString[upperIter] = '\0';
+
+ lowerStr = lowerSymbolsString;
+ upperStr = upperSymbolsString;
+}
+
+
+int main()
+{
+ char* lowerStr = nullptr;
+ char* upperStr = nullptr;
+
+ getTwoStrings("abc34345ABCDd", lowerStr, upperStr);
+
+ cout << lowerStr << endl;
+ cout << upperStr << endl;
+
+ delete[] lowerStr, upperStr;
+
+}