Question

Please write a function in C++ named nextString that will return a single 'value' (i.e. substring)...

Please write a function in C++ named nextString that will return a single 'value' (i.e. substring) from a Comma Separated Value" string. Your function will take two arguments: a string variable containing a comma separated list of values, and an integer containing the starting index; your function should return a single string object with the value that starts at that index and ends right before the next comma ',' (do not include the comma in the returned string!) :

string nextString(string str, int start_index);

If, however, the start index is after the last comma in the string, then the function should return the value starting at that index and continuing to the end of the string.

For example,

cout << nextString("my,cat,ate,my,homework",3);

will print (cat)

and

cout << nextString("my,cat,ate,my,homework",8);

will print (te)

and

cout << nextString("my,cat,ate,my,homework",18);

will print (work)

When you have written your function, then write a short test program that will take in a simple comma separated string using getline: getline(cin,somestring) and output values in the string using the nextString function.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Please write a function in C++ named nextString that will return a single 'value' (i.e. substring)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • C++ Linux Compiler Letter Frequency Write a function that will take a string and return a...

    C++ Linux Compiler Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and k. Your function should take a single string argument and return a dynamically allocated array of 26 integers representing the count of each of the letters a .. z...

  • I need only one  C++ function . It's C++ don't write any other language. Hello I need...

    I need only one  C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...

  • ****Using c++ (Check Substrings) Write the following function to check whether string s1 is a substring...

    ****Using c++ (Check Substrings) Write the following function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. int indexOf(const string& s1, const string& s2) Write a test program that reads two strings and checks whether the first string is a substring of the second string.

  • Write a function in c++: Write a function, reverseString(string &str), that reverses the characters of the...

    Write a function in c++: Write a function, reverseString(string &str), that reverses the characters of the string str, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers. string example = "Reverse"; reverseString(example), cout << example; // prints out "esreveR"

  • USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds...

    USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...

  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • In C++ Write a program that will read a string, call 2 functions to modify the...

    In C++ Write a program that will read a string, call 2 functions to modify the string, and then print the final result. The first function should take a string parameter and return the string without any vowels. The second function should take a string and double every letter (which should be all consonants at this point). Be sure to: You must use more than [ ] and at You must use erase, insert, replace, find, and/or substr to make...

  • In C++ write a program that will read three strings from the user, a phrase, a...

    In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...

  • C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses...

    C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses the linked list and prints the reverse text to the standard output, without changing the linked list. ( Pass the linked list by value, you have the freedom to create a doubly linked list that is a copy of the original list in your program before you call the function) #include "pch.h" #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512...

  • Need help in C++ #include <bits/stdc++.h> using namespace std; // Complete the fly function below. void...

    Need help in C++ #include <bits/stdc++.h> using namespace std; // Complete the fly function below. void fly(string commands) { } int main() { string commands; getline(cin, commands); fly(commands); return 0; } • "N" instructs the drone to move north 1 space - for example, from (0,0) to (0,1). • "S" instructs the drone to move south 1 space. • "E" instructs the drone to move east 1 space. • "W" instructs the drone to move west 1 space. The commands...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT