Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement a function that accepts a string parameter as well as a boolean parameter. Your function should return the number of times it finds

Please implement a function that accepts a string parameter as well as a boolean parameter. Your function should return the number of times it finds characters inside the string that are A's, B's or C's. When all three characters are found in the string and all the A's occur before any B's and all the B's occur before any C's in the string, set the boolean argument to true. Otherwise, set that boolean argument to false. If there are not any A's, B's or C's found, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will be:

int allAsBeforeBsBeforeCs( string s, bool & foundAllThree );

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

bool b = false;

assert( allAsBeforeBsBeforeCs( "", b ) == -1 ); // string argument is the empty string assert( b == false );

assert( allAsBeforeBsBeforeCs( "99912000", b ) == 0 ); // zero A's B's or C's found assert( b == false ); // no A's B's or C's found

assert( allAsBeforeBsBeforeCs( "1CC2BB3AA", b ) == 6 ); // six A's B's and C's found assert( b == false ); // all A's do not come before all B's before all C's

assert( allAsBeforeBsBeforeCs( "123A456B789C", b ) == 3 ); // three A's B's and C's found assert( b == true ); // all A's come before B's come before C's

assert( allAsBeforeBsBeforeCs( "1CC2BB3AABC", b ) == 8 ); // eight A's B's and C's found assert( b == false ); // A's are not coming before all B's before all C's

Write your allAsBeforeBsBeforeCs 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions