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
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