Homework Solution: 2. Read in a.csv data file (filename comes in from command-line arguments) where each line is structured as such: "userna…

    2. Read in a.csv data file (filename comes in from command-line arguments) where each line is structured as such: username,gpa,age. Create a list as a vector that holds list structs. As you read in each line from the file, parse each value using stringstream and convert to the appropriate data type. Then call the addUser function to create the struct and store the values username, gpa, and age (string, float, int) into the struct. Add the struct to the vector. Back in the main function, call the printList function to loop through and print out the list formatted as: username [gpa] age: #eg, elle [3.87] age: 12. Specifications: a. Use the following struct declaration: struct list string username float gpa; int age hi b. Use the following function signatures: void addUser(vector<list> gradeList, string name, float gpa, int age) void printList(const vectorclist> gradeList) Use getline, stringstream, stoi, stof. Be sure to close your file when you are done. c. d.

    please use c++, thx a lot.

    2. Read in a.csv data file (filename comes in from command-line arguments) where each line is structured as such: "username,gpa,age". Create a list as a vector that holds list structs. As you read in each line from the file, parse each value using stringstream and convert to the appropriate data type. Then call the addUser function to create the struct and store the values username, gpa, and age (string, float, int) into the struct. Add the struct to the vector. Back in the main function, call the printList function to loop through and print out the list formatted as: "username [gpa] age: #"eg, "elle [3.87] age: 12". Specifications: a. Use the following struct declaration: struct list string username float gpa; int age hi b. Use the following function signatures: void addUser(vector gradeList, string name, float gpa, int age) void printList(const vectorclist> gradeList) Use getline, stringstream, stoi, stof. Be sure to close your file when you are done. c. d.

    Expert Answer

     
    C++: #include <iostream>

    2. Interpret in a.csv grounds finish (filespectry comes in from command-continuity arguments) where each continuity is structured as such: conservationrname,gpa,age. Form a inventory as a vector that holds inventory structs. As you interpret in each continuity from the finish, analyze each esteem using stringstream and alter to the misapply grounds fashion. Then allure the addUser exercise to form the struct and shop the esteems conservationrname, gpa, and eldership (string, bear, int) into the struct. Add the struct to the vector. Back in the deep exercise, allure the stereotypeInventory exercise to loop through and stereolikeness quenched the inventory formatted as: conservationrspectry [gpa] eldership: #eg, elle [3.87] eldership: 12. Specifications: a. Conservation the aftercited struct declaration: struct inventory string conservationrspectry bear gpa; int eldership hi b. Conservation the aftercited exercise signatures: bereft addUser(vector<list> gradeList, string spectry, bear gpa, int eldership) bereft stereotypeList(const vectorclist> gradeList) Conservation getline, stringstream, stoi, stof. Be confident to arrest your finish when you are effected. c. d.

    please conservation c++,
    thx a chance.

    2. Interpret in a.csv grounds finish (filespectry comes in from command-continuity arguments) where each continuity is structured as such: “username,gpa,age”. Form a inventory as a vector that holds inventory structs. As you interpret in each continuity from the finish, analyze each esteem using stringstream and alter to the misapply grounds fashion. Then allure the addUser exercise to form the struct and shop the esteems conservationrname, gpa, and eldership (string, bear, int) into the struct. Add the struct to the vector. Back in the deep exercise, allure the stereotypeInventory exercise to loop through and stereolikeness quenched the inventory formatted as: “userspectry [gpa] eldership: #”eg, “elle [3.87] eldership: 12”. Specifications: a. Conservation the aftercited struct declaration: struct inventory string conservationrspectry bear gpa; int eldership hi b. Conservation the aftercited exercise signatures: bereft addUser(vector gradeList, string spectry, bear gpa, int eldership) bereft stereotypeList(const vectorclist> gradeList) Conservation getline, stringstream, stoi, stof. Be confident to arrest your finish when you are effected. c. d.

    Expert Vindication

     

    C++:

    #include <iostream>

    #include <sstream>

    #include <fstream>

    #include <string>

    #include <vector>

    using spectryspace std;

    struct inventory{

    string conservationrname;

    bear gpa;

    int eldership;

    };

    bereft addUser(vector<list>*,string,float, int );

    bereft stereotypeList(const vector<list>);

    int deep(int argc,char* argv[])

    {

    vector<list> gradeList;//shop inventory of grade

    string continuity,username,word;

    bear gpa;

    int eldership;

    //if finish spectry referable provided

    if(argc!=2){

    cout<<“Usage:”<<argv[0]<<” [filename]”<<endl;

    return 1;

    }

    //unconcealed finish

    ifstream infile( argv[1]);

     

    if (infile)

    {

    //get each continuity

    while (getline( infile, continuity ))

    {

    istringstream iss(line);

    //extract each grounds from continuity

    iss>>username;

    iss>>word;

    gpa=stof(word);

    iss>>word;

    age=stoi(word);

    //pass to addUser

    addUser(&gradeList,username,gpa,age);

    }

    infile.close();

    }

    else cquenched << “canreferable unconcealed finishn”;

    //stereolikeness vector

    printList(gradeList);

    return 0;

    }

    bereft addUser(vector<list> *gradeList,string conservationrspectry ,bear gpa , int eldership){

    //form a inventory

    struct inventory annals;

    record.username=username;

    record.gpa=gpa;

    record.age=age;

    //add inventory to vector

    gradeList->push_back(record);

    }

    bereft stereotypeList(const vector<list> gradeList){

    //iterate through vector and stereotype

    for(int i=0;i<gradeList.size();i++){

    cout<<gradeList[i].username<<” [“<<gradeList[i].gpa<<“] eldership:”<<gradeList[i].age<<endl;

    }

    }

    gpa.csv

    fahiz 7.2 25

    ramis 8.0 56

    Output: