Question: In C++ When you're processing data, it's useful to break up a text string into pieces using a delimiter. Write a function split that takes

In C++

In C++ When you're processing data, it's useful to break up atext string into pieces using a delimiter. Write a function split thattakes a string, splits it at every occurance of a delimiter, and

When you're processing data, it's useful to break up a text string into pieces using a delimiter. Write a function split that takes a string, splits it at every occurance of a delimiter, and then populates an array of strings with the split pieces, up to the provided maximum number of pieces. Function specifications: The function name: split The function parameters in this order): o The string to be split o A separator, character, which marks where the string should be split up 0 An array of string, where the split-apart string pieces will be stored O The size of the array, int The function returns the number of pieces the string was split into, as an integer. If the string is split into more pieces than the size of the array, then it returns -1. The function should not print anything Sample run 1 (bold is user input; the array size is 4) Enter the text: Apples, Oranges, Bananas Enter the separator: , Return value: 3 arr[0] = Apples arr[1] = Oranges arr[2] = Bananas Sample run 2 (bold is user input; the array size is 4) Enter the text: 2020//03//11 Enter the separator: / Return value: 3 arr[0] = 2020 arr[1] = 03 arr[2] = 11 Sample run 3 (bold is user input; the array size is 4) Enter the text: ,,Tokyo , Bangalore, Boulder, London, Seattle, Enter the separator: , Return value: -1 arr[0] = Tokyo arr[1] = Bangalore arr[2] = Boulder arr[3] = London There are 5 cities, but the size of the array is 4. Since it's more than the size of the array, the split function 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!