1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GrogVix [38]
3 years ago
5

Now, extend your test program by adding a second function named split that will identify all the individual values in a comma se

parated value string and return them in an array of string objects: int split(string str, string a[], int max_size); Your function will take three arguments: a comma separated value string str, an array a of string objects, and the maximum size of the array. You must use the nextString function from Stretch Problem (1) to obtain each value in the string and store it in the array starting, with the first element. Return the total number of values stored in the array. For example: string varray[VALUES]; 2 int cnt

Computers and Technology
1 answer:
otez555 [7]3 years ago
7 0

Answer:

The code to copy is :

#include <iostream>

#include <string>

using namespace std;

string nextString(string str, int start_index);

int split(string str, string a[], int max_size);

int main()

{

const int VALUES = 20;

string somestring;

string varray[VALUES];

//Prompt the user to enter a comma separated string

cout << "Enter a comma seperated string: ";

//read the string

getline(cin, somestring);

//call split() method on the given string and

//store the count of individual strings in cnt

int cnt = split(somestring, varray, VALUES);

//Print the individual strings

for (int i = 0; i<cnt; i++)

cout << varray[i] << endl;

return 0;

}

//returns a sub string that starts at strat_index

//in the given string and ends before a comma

string nextString(string str, int start_index)

{

int i;

//find a comma or end of the string, after strat_index

for (i = start_index;i < str.length();i++)

{

//if comma is found, exit the loop

if (str.at(i) == ',')

break;

}

//extract the sub string

string out= str.substr(start_index, i-start_index);

return out;

}

//splits the comma separted string as individual strings

//and returns the number of individual strings

int split(string str, string a[], int max_size)

{

int i, j;

int start_index = 0;

//search for commas in the given string

for (i = 0,j=0;i < str.length();i++)

{

//if comma is identified or end of the string is identified

//, then get a strig that starts at start_index using next string

if (str.at(i) == ',' ||i==str.length()-1)

{

//save each string into an array of strings

a[j] = nextString(str, start_index);

//update the next string starting postion(starts after comma)

start_index = i + 1;

j++;

}

}

return j;

Explanation:

Please see attachments

You might be interested in
Your employer gives you a list of all chemicals in the entire building and the location of the SDS collection, and he asks you t
stepladder [879]
Employers should familiarize themselves with the training requirements that apply to their employees and their business; design and implement effective training programs; and use qualified trainers. In addition, employers should thoroughly document all training activities, and should retain records of employee attendance at all completed trainings. Training records should include the name of the trained employee, the date of training, the type of training and the training provider. It is a best practice for employers to keep documentation of all trainings provided to demonstrate compliance with all applicable laws and regulations.
4 0
3 years ago
Read 2 more answers
Which type of security threat installs to a computer without the user's knowledge and then monitors all computer activity?
STatiana [176]
That would be what is known as Spyware, a common form of this is known as a "Trojan Horse". This type of malware is typically latched on and hidden within files, such as when downloading a pirated version of a song, game, art-work, etc...
3 0
3 years ago
Read 2 more answers
Which image file format is an uncompressed raster file which may contain different depths of color depths per pixel, or may be s
dangina [55]

Answer:

BMP

Explanation:

The BMP file format, also known as bitmap image file, device independent bitmap (DIB) file format and bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device (such as a graphics adapter), especially on Microsoft Windows[2] and OS/2[3] operating system

6 0
2 years ago
1.What is Intellectual Property
Akimi4 [234]
I think the answer for 1 is c but I am not sure
4 0
3 years ago
The action in which a router divides and forwards incoming or outbound message traffic to multiple links is known as
kipiarov [429]
Load balancing is my best guess.
5 0
3 years ago
Other questions:
  • Brenda's working on improving a Google Search Ads quality score so it potentially gets a better ad rank and performs better in t
    9·1 answer
  • Data mining is ______? a process of finding meaningful patterns in data to improve decisions a strategy for locating security so
    7·1 answer
  • To name a computed field, follow the computation with the word ____ and then the name you wish to assign to the field
    8·1 answer
  • What does the Additional Clock tab do?
    11·1 answer
  • What should you do to help prepare yourself for the delivery of your presentation? you can chose more then one
    8·1 answer
  • 7.) Title text boxes on every slide must be the same format. <br> A. True <br> B. False
    15·2 answers
  • Importance of folders on a computer <br>​
    10·1 answer
  • I have a problem. I can't cycle between game packs on my strike pack, I've watched so many vids I'm on Xböx and I'm holding the
    13·1 answer
  • How are most databases organized?
    15·1 answer
  • Assume that the Vehicle class contains a virtual method named CalculateMaxSpeed(). Assume that both the MotorVehicle and Automob
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!