Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) Write a function split which takes four input arguments: a string to be split, a character to split on (a delimiter), an array of

(C++) Write a function split which takes four input arguments: a string to be split, a character to split on (a delimiter), an array of strings to fill with the split pieces of the input string, and an integer representing the maximum number of split string pieces. The function will split the input string in to pieces separated by the delimiter, and populate the array of strings with the split pieces up to the provided maximum number of pieces. Your function will return the number of pieces the string was split into.

Your function should be named split

Your function takes four input arguments:

The string to be split.

A delimiter character, which marks where the above string should be split up.

An array of string, which you will use to store the split-apart string pieces.

The int length of the given array

Your function returns the number of pieces the input string was split into as an integer.

Your function does not print anything.

If the input string is split into more pieces than the array of string can hold (more than the indicated length), your function should fill only as many words as it can, and return -1.

PLEASE USE THIS FORMAT FOR SPLIT FUNCTION:

int split (string str, char character) { if (str.length() == 0) { return 0; } string word = ""; int j = 0; str = str + character; for (int i = 0; i < str.length(); i++) { if (str[i] == character) { if (word.length() == 0) continue; cout << word << endl; j++; word = ""; } else { word = word + str[i]; } } return j; }

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

Intelligent Information And Database Systems Second International Conference Acids Hue City Vietnam March 2010 Proceedings Part 1 Lnai 5990

Authors: Manh Thanh Le ,Jerzy Swiatek ,Ngoc Thanh Nguyen

2010th Edition

3642121446, 978-3642121449

More Books

Students also viewed these Databases questions

Question

1. Divide the class into teams of three to four students.

Answered: 1 week ago

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago