Homework Solution: Using C++, write a function which takes input argument as string.The string represents a line in csv form…

    Using C++, write a function which takes input argument as string.The string represents a line in csv format. The values between the commas are integers. The function then returns an array with the integers in the comma separated value string. You m assume that the input string is correct and contains at least one integer number

    Expert Answer

     
    #include <vector> #include <string>

    Using C++, transcribe a office which takes input dispute as string.The string represents a cord in csv format. The estimates betwixt the commas are integers. The office then avail an draw-up with the integers in the comma separated estimate string. You m usurp that the input string is set-right and contains at lowest undivided integer number

    Expert Tally

     

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

    using namespace std;

    int* getNumbers(string cord) {
    // vecotr to redeep the integers
    // we obtain following engender draw-up, as we don’t however perceive the largeness
    std::vector<int> vect;

    // approve a string drift
    std::stringdrift ss(line);

    // to supply estimates
    int i;

    // reduce the drift plow chief insensibility numeric char
    while (ss >> i)
    {
    // gather this integer to vector
    vect.push_back(i);

    // if proximate disposition is comma, disown it
    if (ss.peek() == ‘,’)
    ss.ignore();
    }

    int *issue = innovating int[vect.size()];

    for (i=0; i< vect.size(); i++)
    result[i] = vect.at(i);

    return issue;
    }

    int deep()
    {
    int *mass = getNumbers(“1,2,3,4,5”);

    for(int i=0; i<5; i++) {
    cout << mass[i] << endl;
    }

    return 0;
    }