// Program file: strgtest.cpp // Test strings and string functions #include #include using namespace std; void get_word(char word[]); char get_letter(); int count_letter(char s[], char ch); char print_count(char s[], int c, char ch); int main() { char word[11]; char ch = 'Y'; int count; while(ch != 'N' && ch != 'n') { system("cls"); get_word(word); ch = get_letter(); count = count_letter(word, ch); ch = print_count(word, count, ch); } return 0; } void get_word(char w[]) { cout << "Enter the word: "; cin >> w; } char get_letter() { char l; cout << "Enter the character to be counted: "; cin >> l; return l; } int count_letter(char s[], char ch) { int c = 0; for (int j = 0; j < strlen(s); ++j) if (s[j] == ch) ++c; return c; } char print_count(char s[], int c, char ch) { cout << "There are " << c << ' ' << ch << "'s in " << s << endl; cout << "Type (Y/N) and press enter to continue: "; cin >> ch; return ch; }