aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab6/CST116F2021-Lab6.cpp
blob: 083198e4f80fd62593ca8f6ad97e38e89f62dd0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#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;


}