Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write A Program: //Please DONT use stdio.h or fancy things like classes Give

ID: 3674883 • Letter: C

Question

C++ Write A Program: //Please DONT use stdio.h or fancy things like classes

Given the following header:

implement the function split so that it returns a vector of the strings in target that are separated by the string delimiter.

For example: split("10,20,30", ",") should return a vector with the strings "10", "20", and "30". Similarly, split("do re mi fa so la ti do", " ") should return a vector with the strings "do", "re", "mi", "fa", "so", "la", "ti", and "do".

Write a program that inputs two strings and calls your function to split the first target string by the second delimiter string and prints the resulting vector all on line line with elements separated by commas.

The program should print a string of text to the terminal before getting each line of input from the user. A session should look like one of the following examples (including whitespace and formatting), with possibly different numbers in the output:

Note: the fourth line in the second example has a single space character (it is not an empty line).

The strings printed by the program should include a newline at the end.

Explanation / Answer

Please find the required program below :

#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>

using namespace std;

vector<string> split(string target, string delimiter){
char d = delimiter[0];
vector<string> v;
istringstream buf(target);
for(std::string token; getline(buf, token, d); )
v.push_back(token);
  
return v;
}

int main()
{
string s,d;
  
  
while(true) {
cout << "Enter string to split:" << endl;
getline(cin,s);

cout << "Enter delimiter string:" << endl;
getline(cin,d);

vector<string> v = split(s,d);

cout << "The substrings are:" << flush;
for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i)
cout <<"""<< *i <<"", ";
cout << "" << endl;
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote