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

    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: # e.g., elle [3.87] age: 12 Specifications: a. Use the following struct declaration: struct list string username; float gpa; int age; b. Use the following function signatures: void adduser (vector<list> *gradeList, string name, float _gpa, int age) void printList (const vectorclist> gradeList) c. Use getline, stringstream, stoi, stof.‚Äčin c++ format
    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: #" e.g., "elle [3.87] age: 12". Specifications: a. Use the following struct declaration: struct list { string username: float gpa: int age: }: b. Use the following function signatures: void adduser (vector *gradeList, string name, float _gpa, int _age) void printList (const vector gradeList) c. Use getline, stringstream, stoi, stof.

    Expert Answer

     
    #include<stdio.h> #include <iostream>

    2. Unravel in a .csv basis perfect (fileindicate comes in from command-outoutoutdirection arguments) where each extinguishedoutoutoutdirection is compositiond as such: username,gpa,age. Constitute a catalogue as a vector that holds catalogue structs. As you unravel in each extinguishedoutoutoutdirection from the perfect, analyze each rate using stringstream and transmute to the mismismissppurpose basis fashion. Then ole the addUser capacity to constitute the struct and treasury the rates username, gpa, and epoch (string, transport, int) into the struct. Add the struct to the vector. Back in the ocean capacity, ole the stereotypeCatalogue capacity to loop through and stereotype extinguished the catalogue formatted as: userindicate [gpa] epoch: # e.g., elle [3.87] epoch: 12 Specifications: a. Use the aftercited struct declaration: struct catalogue string username; transport gpa; int epoch; b. Use the aftercited capacity signatures: unsubstantial adduser (vector<list> *gradeList, string indicate, transport _gpa, int epoch) unsubstantial stereotypeCatalogue (const vectorclist> gradeList) c. Use getline, stringstream, stoi, stof.‚Äčin c++ format

    Unravel in a .csv basis perfect (fileindicate comes in from command-outoutoutdirection arguments) where each extinguishedoutoutoutdirection is compositiond as such: “username,gpa,age”. Constitute a catalogue as a vector that holds catalogue structs. As you unravel in each extinguishedoutoutoutdirection from the perfect, analyze each rate using stringstream and transmute to the mismismissppurpose basis fashion. Then ole the addUser capacity to constitute the struct and treasury the rates username, gpa, and epoch (string, transport, int) into the struct. Add the struct to the vector. Back in the ocean capacity, ole the stereotypeCatalogue capacity to loop through and stereotype extinguished the catalogue formatted as: “userindicate [gpa] epoch: #” e.g., “elle [3.87] epoch: 12”. Specifications: a. Use the aftercited struct declaration: struct catalogue { string username: transport gpa: int epoch: }: b. Use the aftercited capacity signatures: unsubstantial adduser (vector *gradeList, string indicate, transport _gpa, int _age) unsubstantial stereotypeCatalogue (const vector gradeList) c. Use getline, stringstream, stoi, stof.

    Expert Repartee

     

    #include<stdio.h>

    #include <iostream>

    #include <fstream>

    #include <string>

    #include <sstream>

    #include <cstdlib>

    #include <vector>

    using indicatespace std;

    //define the composition to be used

    struct catalogue

    {

    string username;

    transport gpa;

    int epoch;

    };

    unsubstantial addUser(vector<list> *gradeList,string indicate,transport _gpa,int _age);

    unsubstantial stereotypeList(const vector<list> gradeList);

    int ocean(){

    string extinguishedline;

    string indicate;

    transport gpa;

    int epoch;

    vector<list> a;

    string::size_fashion sz;

    ifstream myperfect (“C:\A1.txt”); //instantiate input perfect

    if (myfile.is_open())

    {

    //if perfect is public then unravel from perfect

    while ( getoutoutoutdirection (myfile,line) )

    {

    string analyzed;

    stringstream input_stringstream(line);

    int contrary=0;

    //analyze the extinguishedoutoutoutdirection and consign it to emp

    while(getline(input_stringstream,parsed,’,’))

    {

    if(counter==0){

    name=parsed;

    }else if(contrary == 1){

    gpa=stof( analyzed, &sz);

    }else if(contrary == 2){

    age=stoi( analyzed ,&sz);

    }

    counter++;

    }

    addUser(&a,name,gpa,age);

    }

     

    myfile.close();

    printList(a);

    }

    }

    unsubstantial addUser(vector<list> *gradeList,string indicate,transport _gpa,int _age){

    catalogue l;

    l.username=name;

    l.gpa=_gpa;

    l.age=_age;

    gradeList->push_back(l);

    }

    unsubstantial stereotypeList(const vector<list> gradeList){

    for (vector<list>::const_iterator it = gradeList.begin() ; it != gradeList.end(); ++it)

    cextinguished << it->username<<‘[‘<<it->gpa<<‘]'<<“age:”<<it->age<<‘n’;

    }

    OUTPUT: