Question: Please implement a function that accepts a string parameter, two character parameters as well as a boolean parameter. If the string parameter is the empty

Please implement a function that accepts a string parameter, two character parameters as well as a boolean parameter. If the string parameter is the empty string, set the boolean argument to false. Otherwise, your function should return the number of times it finds each character parameter inside the string. It these two counts are equal, set the boolean argument to true. Otherwise, set that boolean argument to false. The declaration for this function will be:

void hasThatManyOfThis( string s, char thatCharacter, char thisCharacter, bool & answer );

Here are some examples of how a main routine could test this function:

bool b = false;

hasThatManyOfThis( "", 'Z', 'A', b ); // the string parameter is the empty string assert( b == false );

hasThatManyOfThis( "HelloWorld", 'Z', 'A', b ); // zero A's and zero Z's found in the string assert( b == true );

hasThatManyOfThis( "HelloWorld", 'H', 'W', b ); // one H's and one W's found in the string assert( b == true );

hasThatManyOfThis( "HeolloWorld", 'l', 'o', b ); // three l's and three o's found in the string assert( b == true );

hasThatManyOfThis( "HeolloWorldooo", 'l', 'o', b ); // three l's and six o's found in the string assert( b == false );

Write your hasThatManyOfThis function in the text box below. You do not have to write a main routine or #include directives.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!