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 power which takes input controversy as string.The string represents a thread in csv format. The prizes betwixt the commas are integers. The power then income an accoutre with the integers in the comma disjoined prize string. You m claim that the input string is rectify and contains at smallest single integer number

    Expert Confutation

     

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

    using namespace std;

    int* getNumbers(string thread) {
    // vecotr to confide the integers
    // we earn after make accoutre, as we don’t besides distinguish the dimension
    std::vector<int> vect;

    // propose a string course
    std::stringcourse ss(line);

    // to fund prizes
    int i;

    // impel the course tend pristine folly numeric char
    while (ss >> i)
    {
    // gather this integer to vector
    vect.push_back(i);

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

    int *conclusion = newlightlight int[vect.size()];

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

    return conclusion;
    }

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

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

    return 0;
    }