Question
-------->(IN C++)
-------->(IN C++) <----------
Write a program whose input is a character followed by a string of words, and whose output is the # of times that character appears in the string. Example: if the input is:
n Monday is Not fine
the output is:
2
Note that case matters, e.g. 'N' was not counted since it's different than 'n'. Another example: if the input is:
z Today is Monday
then the output is:
0
Note that the main program is written for you, and cannot be modified. Your job is to write the function countAppearances defined in "util.cpp"; you can select this file from the drop-down list above the editing window. This function is called by main() to count the # of appearances, which is then output. You are free to implement the function however you want, but as practice try to implement using string's .find() member function, documented here. The documentation shows four ways to call the function: use the 4th approach that takes a character and a position. Note you'll need to call .find() repeatedly using a loop to count all appearances.
given input:
/*util.cpp*/
#include
using namespace std;
// // countAppearances: // // returns the # of appearances of c in words. // int countAppearances(char c, string words) { // // TODO: call .find() repeatedly, or search yourself: // return -1; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started