-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path#31 (3) - Count Letters ( Match Case ).txt
More file actions
60 lines (50 loc) · 1.12 KB
/
Copy path#31 (3) - Count Letters ( Match Case ).txt
File metadata and controls
60 lines (50 loc) · 1.12 KB
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
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string ReadString()
{
string Word;
cout << "Please enter yor string ?" << endl;
getline(cin, Word);
return Word;
}
char ReadCharacter()
{
char Character;
cout << "Please enter a Character ?" << endl;
cin >> Character;
return Character;
}
short CountLetter(string Word, char Character, bool MatchCase = true)
{
short Counter = 0;
for (short i = 0;i < Word.length();i++)
{
if (MatchCase)
{
if (Word[i] == Character)
Counter++;
}
else
{
if (tolower(Word[i]) == tolower(Character))
Counter++;
}
}
return Counter;
}
char InvertLetterCase(char Character)
{
return isupper(Character) ? tolower(Character) : toupper(Character);
}
int main()
{
string Word = ReadString();
cout << endl;
char Character = ReadCharacter();
cout << "\nLetter \'" << Character << "\' Count = " << CountLetter(Word, Character) << endl;
cout << "Letter \'" << Character << "\' or \'"<< InvertLetterCase(Character) <<"\' Count = "
<< CountLetter(Word, Character, false) << endl;
return 0;
}