Question: C++ PROGRAM create the function: int split(string a[], int n, string splitter); The functions you must write take 3 parameters. an array of strings a[]

C++ PROGRAM 

create the function: int split(string a[], int n, string splitter);

The functions you must write take 3 parameters. an array of strings a[] , and the number of items the function will consider in the array n, starting from the beginning. And the third one is splitter which you will Rearrange the elements of the array so that all the elements whose value is < splitter come before all the other elements, and all the elements whose value is > splitter come after all the other elements. Return the position of the first element that, after the rearrangement, is not < splitter, or n if there are no such elements. return -1 if n is negative. To make your life easier, whenever this specification talks about strings being equal or about one string being less than or greater than another, the case of letters matters. This means that you can simply use compason operators like == or < to compare strings. Because of the character collating sequence, all upper case letters come before all lower case letters, so don't be surprised. examples:

string hero[6] = { "clark", "peter", "reed", "tony", "diana", "bruce" }; int x = split(hero, 6, "logan"); // returns 3 // hero must now be // "clark" "diana" "bruce" "peter" "tony" "reed" // or "diana" "bruce" "clark" "reed" "peter" "tony" // or one of several other orderings. // All elements < "logan" (i.e., "diana", "bruce", and "clark") // come before all others // All elements > "logan" (i.e., "tony", "peter", and "reed") // come after all others 

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

string hero[6] = { "clark", "peter", "reed", "tony", "diana", "bruce" }; int z = split(hero, 5, "logan"); // returns 2 (we only see the first 5) // hero must now be // "clark" "diana" "peter" "tony" "reed" "bruce" // or "diana" "clark" "reed" "peter" "tony" "bruce" // or one of several other orderings. // All elements < "logan" (i.e., "diana" and "clark") // come before all others // All elements > "logan" (i.e., "tony", "peter", and "reed") // come after all others 

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

string hero2[4] = { "reed", "sue", "peter", "steve" }; int y = split(hero2, 4, "steve"); // returns 2 // hero2 must now be either // "reed" "peter" "steve" "sue" // or "peter" "reed" "steve" "sue" // All elements < "steve" (i.e., "peter" and "reed") come // before all others. // All elements > "steve" (i.e., "sue") come after all others. 

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!