Question: C++ PROGRAM: Create the function: int countRuns(const string a[], int n); the functions you must write take 2 parameters. an array of strings a[] ,

C++ PROGRAM:

Create the function: int countRuns(const string a[], int n);

the functions you must write take 2 parameters. an array of strings a[] , and the number of items the function will consider in the array n, starting from the beginning. Return the number of sequences of one or more consecutive identical items in a. Return 1 if n is negative. passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array. when we say "the array", we mean the n elements that the function is aware of. The one error your function implementations doesn't have to handle is when the caller of the function lies and says the array is bigger than it really is. Your program must not use any function templates from the algorithms portion of the Standard C++ library.

string d[9] = {

"tony", "bruce", "steve", "steve", "diana", "diana", "diana", "steve", "steve"

};

int p = countRuns(d, 9); // returns 5

// The five sequences of consecutive identical items are

// "tony"

// "bruce"

// "steve", "steve"

// "diana", "diana", "diana"

// "steve", "steve"

--------------------------------------------------------------

string d[9] = {

"tony", "bruce", "steve", "steve", "diana", "diana", "diana", "steve", "steve"

};

int p = countRuns(d, 8); // returns 5

// The five sequences of consecutive identical items are

// "tony"

// "bruce"

// "steve", "steve"

// "diana", "diana", "diana"

// "steve"

--------------------------------------------------------------

string d[9] = {

"tony", "bruce", "steve", "steve", "diana", "diana", "diana", "steve", "steve"

};

int p = countRuns(d, 7); // returns 4

// The five sequences of consecutive identical items are

// "tony"

// "bruce"

// "steve", "steve"

// "diana", "diana", "diana"

--------------------------------------------------------------

string d[9] = {

"tony", "bruce", "steve", "steve", "diana", "diana", "diana", "steve", "steve"

};

int p = countRuns(d, 0); // returns 0

--------------------------------------------------------------

string d[9] = {

"tony", "bruce", "steve", "steve", "diana", "diana", "diana", "steve", "steve"

};

int p = countRuns(d, -7); // returns -1

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!