From 371ac940ba35f0ef95a54422cdfe8d90f75ae048 Mon Sep 17 00:00:00 2001 From: JacobAKnox <91796123+JacobAKnox@users.noreply.github.com> Date: Wed, 3 Nov 2021 20:19:40 -0700 Subject: 11c done --- 11c/10.15.1/10.15.1.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 11c/10.15.1/10.15.1.cpp (limited to '11c/10.15.1/10.15.1.cpp') 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 +#include + +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; +} + -- cgit v1.2.3