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
What are the advantages of using the internet as theinfrastructure for electronic commerce and electronicbusiness?
Mrac [35]

Answer and Explanation:

E-commerce and e-business is a major business of the present time using the internet. It is basically defined as the online selling of goods or making any business online. Internet is the basic requirement for the e-commerce or e-business as

  • it helps in providing the internet connectivity so that the e-business can be displayed online and users can buy goods or interact with seller regarding the business.
  • Due to internet service users get to know about the online business and thus the business attains economic growth and benefit.

6 0
3 years ago
Based on the condition.
e-lub [12.9K]

Answer:

A subroutine is a block of statements that carries out one or more tasks. ... they share all variables with the rest of the main program. ... Once you have defined a function in your program, you may use it in any appropriate expression, such as: ... Thus, functions can- not change the values of the arguments passed to them.

Explanation:

5 0
3 years ago
Unit testing:_________. A. provides the final certification that the system is ready to be used in a production setting. B. incl
NARA [144]

Answer:

Option (C) is the correct option to the following question.

Explanation:

The following option is correct because the unit testing is the process of testing a single unit of software at a time, which means the testing of each and every program separately.

In simple words, Unit testing a process of testing in which the developer executes the single method or a function, statements or loop in the program of the software to checking is it working fine or not.

7 0
2 years ago
Professor Midas drives an automobile from Newark to Reno along Interstate 80. His car’s gas tank, when full, holds enough gas
zmey [24]

Answer:

The GREEDY Algorithm

Explanation:

Based on the situation given in question, the Greedy algorithm shall give the optimal solution to professor

Suppose that the cities are at locations0 =x0< x1< . . . < x

We shall use the induction method to prove that G is the optimal solution valid for numbers less than n

We assume another solution Z which we initially consider to be optimum as well, based on that when Z fills the tank, it fills it to full level

Let us state the values in case of n intervals. Given below, we say that g1 is the first stop and z1 is also the first stop.

This can be written as ;

G=g1, g2, . . . , gk

Z=z1, z2, . . . , zk’

Here k’ <= k and k < n

Let I be an idex where for the first time gi is not equal to zi

Considering t= maxi Zi

Z′=g1, z2, z3, . . . , zk′

Now since z2, z3, . . . , zk′ should be an optimal stopping pattern for the problem otherwise we have chosen Z, with smaller gas filling (not feasible)

Using induction hypothesis we conclude thatg2, . . . , gk is an optimal stopping pattern, which is based on greedy algorithm

7 0
3 years ago
Which of the following is not an ideal habitat for a strong time-management plan
Maurinko [17]
The answer to this question is, A. Cramming.


PLEASE MARK BRAINLIEST!! :)
5 0
3 years ago
Read 2 more answers
Other questions:
  • You can access a button s screentip by _____.
    6·1 answer
  • It is important for security practitioners to take into consideration the __________ element when devising password security pol
    15·1 answer
  • Explain why it is not necessary for a program to Explain why it is not necessary for a program to be completely free of defects
    13·1 answer
  • COMPUTER CODING
    5·1 answer
  • What are examples of templates the Input Mask Wizard offers? Check all that apply.
    12·2 answers
  • To date, what has most propelled the digital revolution?
    10·1 answer
  • Is the flow of power reversible in a leadscrew?
    11·1 answer
  • What power points feature will you use to apply motion effects to different objects of a slide
    5·1 answer
  • Which of the following best describes a hotspot as
    10·1 answer
  • In a database, what term is used to describe a group of fields that are all associated with and accessed using single primary ke
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!