Assignment Description (100 points) The purpose of this project is to write a pr
ID: 3817092 • Letter: A
Question
Assignment Description (100 points) The purpose of this project is to write a program to help record every students' grades in a spreadsheet roster. When TAs collect results from an online quiz platform, the platform can only provide the grades of students who have submitted their quizzes. If a student skips them, the online platform will not keep track of their grades. Therefore, when a TA downloads data from the platform, he/she will only have the submitted results which is actually a spreadsheet that is given in the Fig. 1. accumsan.neque acmetus com Candace Bishop adipistingsbibendum com Conan Daugherty aliquam.arcu Aliquam6nequenon.net arcuVestibulumeEtiam vestibulummassa com augue tempus edu Beatrice Morgan Ruth Woods augue vitae org congue.InPvelsapien.com consecitetuereturpis net Sydnee Holloway cubilia.curae Phaselius6nibihdolor,net Tarik Sargent cubilia.curaeevehiculaet edu Kiona Santana Cum socis natoque tristiq uealquetPhasellus.co. wk 800000069 Travis House Donecat8risusMorbi.net DonecnibheDonecnonjusto.org Barbara Walter DonecpplaceratelitQuisque edu Echo Haynes duiin sodales8eget net duleanteipsumprimis co.uk Keely Graham Taylor Roberson DuismienimePaceleifendvitaeedu Bertha Rodriguez Duisvolutpat nun uterosca. eget dictumeeget com Mikayla Grant eget dictumetincidunttempusrisus edu Tucker Mullen eget metus.eu6 acusnet 31 Ruth Marquez egete Fusce Jorg eltpellentesqueebibendumedu Figure 1: Students quiz score (input file)Explanation / Answer
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<sstream>
#include<stdlib.h>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main() {
int std_id, std_grade;
string email, name;
ifstream fs("input.csv");
string line = "";
map<string,vector<int> > std_map;
while (getline(fs, line)) {
stringstream linestream(line);
string token = "";
if(getline(linestream, token, ';')){}
if(getline(linestream, token, ';')){}
int k=0;
string keyis="";
while(getline(linestream, token, ';')) {
if(k==2 and std_map.find(token)==std_map.end()) {
vector<int> v;
std_map[token]=v;
keyis=token;
} else if(k==3) {
vector<int> v=std_map[keyis];
v.push_back(atoi(token.c_str()));
std_map[keyis]=v;
}
++k;
}
}
ifstream fs2("roster.csv");
ofstream myfile;
myfile.open ("output.csv");
while (getline(fs2, line)) {
std::stringstream linestream(line);
string token = "", temp="";
int k=0;
while(getline(linestream, token, ';')) {
temp+=token;
temp+=",";
if(k==2) {
if(std_map.find(token)!=std_map.end()) {
vector<int> v=std_map[token];
char buf[10];
sprintf(buf,"%d",v[0]);
temp+=string(buf);
temp+=", ";
myfile << temp;
} else {
temp+=" ";
myfile << temp;
}
}
++k;
}
}
myfile.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.