Q:

Modify our vowel-counting program so that it counts the number of occurrences of the following two-character sequences: ff, fl, and fi

0

 Modify our vowel-counting program so that it counts the number of occurrences of the following two-character sequences: ff, fl, and fi.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main() {
  unsigned aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0;
  unsigned spaceCnt = 0, tabCnt = 0, newlineCnt = 0, otherCnt = 0;
  unsigned ffCnt = 0, flCnt = 0, fiCnt = 0;
  bool fPresent = false;
  char ch;
  while (std::cin.get(ch)) {  // `<<` operator will omit whitespace characters
    switch(ch) {
      case 'A': case 'a':
        ++aCnt;
        break;
      case 'E': case 'e':
        ++eCnt;
        break;
      case 'I':
        ++iCnt;
        break;
      case 'i':
        ++iCnt;
        if (fPresent) {
          ++fiCnt;
          fPresent = false;
        }
        break;
      case 'O': case 'o':
        ++oCnt;
        break;
      case 'U': case 'u':
        ++uCnt;
        break;
      case ' ':
        ++spaceCnt;
        break;
      case '\t':
        ++tabCnt;
        break;
      case '\n':
        ++newlineCnt;
        break;
      case 'f':
        if (fPresent)
          ++ffCnt;
        else
          fPresent = true;
        break;
      case 'l':
        if (fPresent) {
          ++flCnt;
          fPresent = false;
        }
        break;
      default:
        ++otherCnt;
    }
  }
  std::cout << "Number of vowel a:\t" << aCnt << '\n'
            << "Number of vowel e:\t" << eCnt << '\n'
            << "Number of vowel i:\t" << iCnt << '\n'
            << "Number of vowel o:\t" << oCnt << '\n'
            << "Number of vowel u:\t" << uCnt << '\n'
            << "Number of space:\t" << spaceCnt << '\n'
            << "Number of tab:\t" << tabCnt << '\n'
            << "Number of newline:\t" << newlineCnt << '\n'
            << "Number of sequence ff:\t" << ffCnt << '\n'
            << "Number of sequence fl:\t" << flCnt << '\n'
            << "Number of sequence fi:\t" << fiCnt << '\n'
            << "Number of others:\t" << otherCnt << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now