Question: *Do Not Use A Header File* I have a large amount of text data with student scores stored as series of integers and oating point
*Do Not Use A Header File*
I have a large amount of text data with student scores stored as series of integers and oating point values. I would like to read that data in JSON format.
Given the format: number of students, student id, number of grades, grade 0, grade 1, grade n
Read in each of the number of students students and write their id and number of grades grades to the standard output stream as indicated in the provided source code. The application should perform as follows: The program is called and and is run with no prompt for input: ./parse source The program reads from the standard input stream a series of characters in the indicated format e.g. 2 1234 3 98.7 87.92 77.32 2345 3 93.1 90.23 81.21 and parses the values as indicated in the given source le: { "students" : [ { "id" : 1234, "grades" : [ 98.7, 87.92, 77.32 ] }, { "id" : 2345, "grades" : [ 93.1, 90.23, 81.21 ] } ], "max_id" : 1234, "max_score" : 98.7 }
My code:
#include
int main(int argc, char* argv[]) { /* The following input * * 2 1234 3 98.7 87.92 77.32 2345 3 93.1 90.23 81.21 * * would result in the following output. */ while(1){ switch(students){ case id: break; case grades: break; default: std::cout << "default "; // no error break; } cout << "{" << endl; cout << " \"students\" : [" << endl; cout << " { \"id\" : 1234, \"grades\" : [ 98.7, 87.92, 77.32 ] }," << endl; cout << " { \"id\" : 2345, \"grades\" : [ 93.1, 90.23, 81.21 ] }" << endl; cout << " ]," << endl; cout << " \"max_id\" : 1234," << endl; cout << " \"max_score\" : 98.7" << endl; cout << "}"; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
