Question

c++ only help, thank you.

Using the MOCK_DATA.csv file which contains names and scores, write a program that reads the data into a map (string, int). O

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include<bits/stdc++.h>

#include<fstream>

using namespace std;

int main(){

//creating map;

map<string,int>mock_data;

//input file path(MOCK_DATA.csv)

ifstream data("MOCK_DATA.csv");

string line;

vector<vector<string> > parsedCsv;

while(getline(data,line))

{

stringstream lineStream(line);

string cell;

vector<string> parsedRow;

//reading from CSV file with ',' (comma) as delimiter

while(getline(lineStream,cell,','))

{

parsedRow.push_back(cell);

}

//parsedRow[0] has name and parsedRow[1] has scores

string name = parsedRow[0];

string s = parsedRow[1];

int score;

//creating a class for stringstream

stringstream geek(s);

//converting string to int

geek >> score;

//inserting data into map

mock_data.insert(pair<string, int>(name, score));

}

//Getting input from user

cout<<"Enter name : ";

string name;

cin>>name;

//iterator for map

map<string, int>::iterator it ;

//it (iterator) will find name(key) and its value

it = mock_data.find(name);

//if it reaches end => values is not present

if(it == mock_data.end())

cout << "name is not present in map" ;

else

//if name is present it->first will have name and it->second will have score

cout << "name : "<< it->first << " score : " << it->second ;

cout << endl ;

}

CSV DATAFILE:

name score bb

CODE:

1 2 3 #include<bits/stdc++.h> #include<fstream> using namespace std; 5 - int main() { //creating map; map<string, int>mock_da//converting string to int geek >> score; //inserting data into map mock_data.insert(pair<string, int>(name, score)); //Getti

OUTPUT: clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/finala Clang++-7 -pthread -o main main.cpp ./main Enter name : cc nam

Add a comment
Know the answer?
Add Answer to:
c++ only help, thank you. Using the MOCK_DATA.csv file which contains names and scores, write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Must be done in python and using linux mint Write a program to create a text...

    Must be done in python and using linux mint Write a program to create a text file which contains a sequence of test scores. Each score will be between 0 and 100 inclusive. There will be one value per line, with no additional text in the file. Stop adding information to the file when the user enters -1 The program will first ask for a file name and then the scores. Use a sentinel of -1 to indicate the user...

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT