diff options
Diffstat (limited to '11c/10.15.1/10.15.1.cpp')
| -rw-r--r-- | 11c/10.15.1/10.15.1.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/11c/10.15.1/10.15.1.cpp b/11c/10.15.1/10.15.1.cpp new file mode 100644 index 0000000..2228f7a --- /dev/null +++ b/11c/10.15.1/10.15.1.cpp @@ -0,0 +1,84 @@ +// 10.15.1.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include <iostream> +#include <string> + +using namespace std; + +bool isPalindrome(char str[50]); + +bool isAlphaStr(char str[50]); + +int countChar(char str[50], char c); + +int main() +{ + char str[50]{}; + char check; + int count; + + cout << "Input a string: "; + cin.getline(str, 50); + cout << "Input a charcter to check: "; + cin >> check; + cout << "\n\n"; + + if (isPalindrome(str)) + { + cout << "\"" << str << "\" is a palindrome.\n"; + } + else + { + cout << "\"" << str << "\" is not a palindrome.\n"; + } + + if (isAlphaStr(str)) + { + cout << "\"" << str << "\" only contains alpahbetic charcters.\n"; + } + else + { + cout << "\"" << str << "\" contains one or more non alphabetic charcters.\n"; + } + + count = countChar(str, check); + cout << "\"" << str << "\" contains " << count << " " << check << "'s."; +} + +bool isPalindrome(char str[50]) +{ + string s = str, p = s; + reverse(p.begin(), p.end()); + + return s == p; +} + +bool isAlphaStr(char str[50]) +{ + int i = 0; + while (str[i]) + { + if (!isalpha(str[i])) + { + return false; + } + i++; + } + return true; +} + +int countChar(char str[50], char c) +{ + int count = 0, i = 0; + while (str[i]) + { + if (str[i] == c) + { + count++; + } + i++; + } + return count; +} + |