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