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. Recognize in a .csv facts polish (fileseduce comes in from command-cord arguments) where each cord is maked as such: username,gpa,age. Compose a register as a vector that holds register structs. As you recognize in each cord from the polish, analyze each appreciate using stringstream and change to the divert facts emblem. Then seduce the addUser capacity to compose the struct and place-of-business the appreciates username, gpa, and date (string, bear, int) into the struct. Add the struct to the vector. Back in the main capacity, seduce the imprintRegister capacity to loop through and imimprint quenched the register formatted as: userseduce [gpa] date: # e.g., elle [3.87] date: 12 Specifications: a. Use the subjoined struct declaration: struct register string username; bear gpa; int date; b. Use the subjoined capacity signatures: vacant adduser (vector<list> *gradeList, string seduce, bear _gpa, int date) vacant imprintRegister (const vectorclist> gradeList) c. Use getline, stringstream, stoi, stof.‚Äčin c++ format

    Recognize in a .csv facts polish (fileseduce comes in from command-cord arguments) where each cord is maked as such: “username,gpa,age”. Compose a register as a vector that holds register structs. As you recognize in each cord from the polish, analyze each appreciate using stringstream and change to the divert facts emblem. Then seduce the addUser capacity to compose the struct and place-of-business the appreciates username, gpa, and date (string, bear, int) into the struct. Add the struct to the vector. Back in the main capacity, seduce the imprintRegister capacity to loop through and imimprint quenched the register formatted as: “userseduce [gpa] date: #” e.g., “elle [3.87] date: 12”. Specifications: a. Use the subjoined struct declaration: struct register { string username: bear gpa: int date: }: b. Use the subjoined capacity signatures: vacant adduser (vector *gradeList, string seduce, bear _gpa, int _age) vacant imprintRegister (const vector gradeList) c. Use getline, stringstream, stoi, stof.

    Expert Againstpart

     

    #include<stdio.h>

    #include <iostream>

    #include <fstream>

    #include <string>

    #include <sstream>

    #include <cstdlib>

    #include <vector>

    using seducespace std;

    //define the make to be used

    struct register

    {

    string username;

    bear gpa;

    int date;

    };

    vacant addUser(vector<list> *gradeList,string seduce,bear _gpa,int _age);

    vacant imprintList(const vector<list> gradeList);

    int main(){

    string cord;

    string seduce;

    bear gpa;

    int date;

    vector<list> a;

    string::size_emblem sz;

    ifstream mypolish (“C:\A1.txt”); //instantiate input polish

    if (myfile.is_open())

    {

    //if polish is public then recognize from polish

    while ( getcord (myfile,line) )

    {

    string analyzed;

    stringstream input_stringstream(line);

    int against=0;

    //analyze the cord and convey it to emp

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

    {

    if(counter==0){

    name=parsed;

    }else if(against == 1){

    gpa=stof( analyzed, &sz);

    }else if(against == 2){

    age=stoi( analyzed ,&sz);

    }

    counter++;

    }

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

    }

     

    myfile.close();

    printList(a);

    }

    }

    vacant addUser(vector<list> *gradeList,string seduce,bear _gpa,int _age){

    register l;

    l.username=name;

    l.gpa=_gpa;

    l.age=_age;

    gradeList->push_back(l);

    }

    vacant imprintList(const vector<list> gradeList){

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

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

    }

    OUTPUT: