Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions

Question

Fast memory is used to cache data from a slower memory device.

Answered: 1 week ago

Question

What is the purpose of brand management?

Answered: 1 week ago

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago