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
In order to drive safely, you need to ___________. A. possess good vision B. look to the side while keeping your head and eyes s
Elena-2011 [213]
The question is vague, but answer B is absolutely incorrect so by default choice A is correct ...  "good" is hard to define and your vision can be corrected by glasses allowing you to drive, etc.
6 0
3 years ago
Consider sending a 2400-byte datagram into a link that has an mtu of 700 bytes. suppose the original datagram is stamped with th
Feliz [49]

Explanation:

Let, DG is the datagram so, DG= 2400.

Let, FV is the Value of Fragment and F is the Flag and FO is the Fragmentation Offset.

Let, M is the MTU so, M=700.

Let, IP is the IP header so, IP= 20.

Let, id is the identification number so, id=422

Required numbers of the fragment = [\frac{DG-IP}{M-IP} ]

Insert values in the formula = [\frac{2400-20}{700-20} ]

Then,        = [\frac{2380}{680} ] = [3.5]

The generated numbers of the fragment is 4

  • If FV = 1 then, bytes in data field of DG= 720-20 = 680 and id=422 and FO=0 and F=1.
  • If FV = 2 then, bytes in data field of DG= 720-20 = 680 and id=422 and FO=85(85*8=680 bytes) and F=1.
  • If FV = 3 then, bytes in data field of DG= 720-20 = 680 and id=422 and FO=170(170*8=1360 bytes) and F=1.
  • If FV = 4 then, bytes in data field of DG= 2380-3(680) = 340 and id=422 and FO=255(255*8=2040 bytes) and F=0.

3 0
3 years ago
Jason wants to open a program with the command prompt window. Which command should he type in the Run dialog box to open the com
Svetradugi [14.3K]
The name of the command prompt executable is cmd.exe so just type that.
5 0
3 years ago
Read 2 more answers
Give reasons why local efforts are required to conserve biodiversity​
mario62 [17]
The most obvious reason for conservation is to protect wildlife and promote biodiversity. Protecting wildlife and preserving it for future generations also means that the animals we love don't become a distant memory. And we can maintain a healthy and functional ecosystem.
3 0
2 years ago
Tasha purchased a new tablet. She has several questions about how to connect to the internet, download apps, install software, a
lutik1710 [3]
The answer is D because a toutourial can explain each and everey process

6 0
3 years ago
Other questions:
  • Which is the output of the formula =AND(12&gt;6;6&gt;3;3&gt;9)
    6·1 answer
  • Given a floating point variable fraction, write a statement that displays the value of fraction on the screen. Do not display an
    13·1 answer
  • what program searches the Internet for specified keywords and returns a list of the pages where the keywords were found
    6·1 answer
  • Why does my inbox keep getting notifications and then disappearing?
    15·2 answers
  • Free points,
    15·2 answers
  • Match the image to the view type in a presentation program. scroll bar tool bar status bar menu bar provides an array of buttons
    10·2 answers
  • What is the volume of a rectangular prism with a length of 812 centimeters, width of 913 centimeters, and a height of 1225 centi
    12·1 answer
  • Im lonellly whos down to date me
    7·2 answers
  • Radio spectrum is the part of the complete range of electromagnetic waves that is used for radio communication from
    14·1 answer
  • Which statement best explains the way that similar apps are used in different devices?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!