Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Write a function split which takes two input arguments: a string to be split, a character to split on (also known as a delimiter

c++

Write a function split which takes two input arguments: a string to be split, a character to split on (also known as a delimiter). The function will split the input string into smaller substrings, separated by the delimiter, and print each substring. Your function will return the number of pieces the string was split into.

  • Your function should be named split

  • Your function takes two input parameter arguments in the following order:

    • The string to be split.

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

  • Your function must return the number of substrings that the input string was split into as an integer.

  • Your function prints to the screen each substring that the delimiter separates the string into, each on its own line.

split("cow/chicken/fish", '/'); 

would return the count of 3 and prints

cow

chicken

fish

Note 1: Its possible that the string to be split will have the delimiter character more than once in a row. Sequences of repeated delimiters should be treated as a single delimiter. Its also possible for a string to start or end with a delimiter, or a sequence of delimiters. These leading and trailing delimiters should be ignored by your function; see the examples.

Note 2: Consider the case where the delimiter is not present. What, then, should be the substring(s) that your function returns?

image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

=+31-4 Discuss the information we process automatically.

Answered: 1 week ago