diff options
Diffstat (limited to 'CST116F2021-Lab6/LAB6Answers.txt')
| -rw-r--r-- | CST116F2021-Lab6/LAB6Answers.txt | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/CST116F2021-Lab6/LAB6Answers.txt b/CST116F2021-Lab6/LAB6Answers.txt index a93ff77..1e1c990 100644 --- a/CST116F2021-Lab6/LAB6Answers.txt +++ b/CST116F2021-Lab6/LAB6Answers.txt @@ -295,3 +295,178 @@ Press any key to close this window . . . --------------------------------------------------------------- +11c +10.15 Programming Exercises +pp 292-293 +10 pts #1 +Submit: code & runs + + +CODE: + +#include <iostream> +#include <string> +#include <iomanip> + +using namespace std; +bool isPalindrome(char str[100]); +bool isAlphaStr(char str[100]); +int countChar(char str[100], char character); + +int main() { + + char str1[100]; + char str2[100]; + char str3[100]; + char repeatedletter; + + cout << "Enter word that you would like to count repeated character of: "; + cin >> str3; + cout << endl; + cout << "Enter letter you would like to find: "; + cin >> repeatedletter; + cout << endl; + cout << countChar(str3, repeatedletter); + + cout << endl; + + cout << "ENter word where you want all alphabet: "; + cin >> str2; + cout << endl; + + if (isAlphaStr(str2) == true) { + + cout << "TRUE"; + + } + + else { + + + cout << "FALSE"; + + } + + cout << endl; + + + cout << "Enter Palindrome word: "; + cin >> str1; + + if (isPalindrome(str1)) { + + cout << "true" << endl; + + } + else { + + cout << "false" << endl; + + } + + +} + + +bool isPalindrome(char str[100]) { + + char tempString[100]; + bool condition = true; + + int j = strlen(str) - 1; + + for (int i = 0; i < strlen(str); i++) { + + if (str[i] != str[j]) { + + condition = false; + + } + + j--; + + + } + + return condition; + + +} + + +bool isAlphaStr(char str[100]) { + + for (int i = 0; i < strlen(str); i++) { + + if (!isalpha(str[i])) { + + return false; + + } + + } + + return true; + + +} + + +int countChar(char str[100], char character) { + + int amount = 0; + for (int i = 0; i < strlen(str); i++) { + + if (str[i] == character) { + + amount++; + + } + + + } + + return amount; + + +} + + +OUTPUT(1): + +Enter word that you would like to count repeated character of: Hellooooo + +Enter letter you would like to find: o + +5 +ENter word where you want all alphabet: hjkdfsn0 + +FALSE +Enter Palindrome word: referr +false + +C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 19652) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +OUTPUT(2): + + +Enter word that you would like to count repeated character of: hheeellloooom + +Enter letter you would like to find: m + +1 +ENter word where you want all alphabet: Hello + +TRUE +Enter Palindrome word: refer +true + +C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 14748) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + |