Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C++, please! When you're processing data, it's useful to break up a text string into pieces using a delimiter. Write a function split that
In C++, please!
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 and split a string on a delimiter, then it populates the 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. A separator, character, which marks where the string should be split up An array of string, where the split-apart string pieces will be stored The size of the array, int The function returns the number of pieces the string was split into as an integer. Your function does not print anything. Important considerations: If the string is split into more pieces than the size of the array, then the function returns -1. If the delimiter character is not found, then the function returns 1 and the entire string is placed in the array as the first element. You can assume: 1. There will not be consecutive delimiters 2. The delimiter will not be the first or the last character in the string For example: string words [10]; split("cow/chicken/fish", '/', words, 10); would return 3 and fill the array with "Cow", "chicken", "fish". 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 -1Step 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