Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been asking for the solution of this c++ program for two weeks and no one is answering! Your task for this lab is

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed I have been asking for the solution of this c++ program for two weeks and no one is answering!

Your task for this lab is to complete the implementation of a program that processes acsv file containing raw grade data, and produces a report file as a.txt Starter Code The framework of the program has been given to you in the starter code, including useful constants, function prototypes, and the main) function. The parts of the program that you need to complete have been marked with comments I TODO (n): . Input File Format The input file will be formatted as follows: Columns, also known as fields, are separated by commas and rows, also known as records, are separated by newlines o Note: files formatted in this way can be opened and viewed as a table with a program such as MS Excel or Open Office The first row will be a header for the file containing titles for each field and should be ignored All other rows will be student records consisting of comma-separated fields: o student name student ID o test scores The test scores will be a comma-separated list of 4 test results For example, the beginning of such a file might look like this: Name, ID, scorel, score2, score3, score4 Fred Flintstone,5563w,70,82,55,80 Barney Rubble, q5771x, 65, 62,0,71 You will have to parse, or separate out, each field from a given line of text. Output File Format The output file will be a neatly formatted report showing the student name, their four scores, the lowest score (dropped), the total score, average, and resulting grade letter. For example, given the input above, the report would look like this: Name, ID, scorel, score2, score3, score4 Fred Flintstone, q5563w, 70,82,55,80 Barney Rubble,q5771x, 65, 62,0,71 You will have to parse, or separate out, each field from a given line of text. Output File Format The output file will be a neatly formatted report showing the student name, their four scores, the lowest score (dropped), the total score, average, and resulting grade letter For example, given the input above, the report would look like this: Name Scores (Low) Total AverageGrade 77.33 66.00 Fred Flintstone 70 82 55 80 55) 65 62 0 71 ) 232 Barney Rubble Note that various field widths have been defined as constants near the top of the source file. Be sure to use these named constants, rather than hard-coding "magic numbers" when you get to writing the code to output the formatted record. Implementing the helper functions The program is written in a modular way, using functions to "abstract' away details, so that the overall flow of the program is easy to understand. The main) function calls other functions to do the actual work. Your job is to fill in the details by implementing many of these 'helper" functions. The Top-Level Functions string getinputFilename The program starts by asking the user for the name of the input file. To do this it invokes the getInputFilename() function. This function should Prompt the user to enter a filename. . Validate that the filename has the form: o "rawgrades-.csv o where identifies the class to which it pertains ..for example, the above input file might be named "rawgrades-bw101 .csv" Continue prompting the user for a filename until a valid one is given. . Return the validated filename. Sample run: Enter input filename (rawgrades-.csv):what Enter input filename (rawgrades-className>csv): what.csv Enter input filename (rawgrades-className>csv): rawgrades.csv Enter input filename (rawgrades-className> .csv): rawgrades-bw101.csv Processing rawgrades-bw101.csv... Report written to grade-report-bw101.txt string deriveOutputFilename(.) This function takes an input filename as a parameter and should return the corresponding output filename. The format of the output filename is grade-report-className>.txt bool openFiles.(.) This function opens the input and output files, associating the files with the provided input/output file streams. If the input file fails to open, the following message should be output before the function returns false: Failed to open for read: If the output file fails to open, the following message should be output before the function returns false: Failed to open for write: The function should return true only if both files opened successfully. Returning false signals to the main program that some error occurred and that the run should be aborted. void processGradeFile(...) This function has been implemented for you. It writes the report header (invoking a function also written for you), then loops over the lines read in from the input file, invoking processLine(... for each one. Helper Functions To break the problem down into manageable pieces, helper functions have been defined to solve small, specific tasks. These will need to be implemented correctly, and called from the appropriate places to complete the project. You'll find them in the starter code, but as a quick summary: // Returns true if fname is of the form "rawgrades-className>.csv " bool validInputFilename (const string &fname) // Parses a record (line),placing the substrings into name, id, scores, and s1.. .s4 void parseStudentRecord (const string &line, string &name, string &id, int &s1, int &s2, int &s3, int &s4) // Returns the smaller of the two values int min(int a, int b) / Returns the smallest of all the values int min(int a, int b, int c, int d) // Returns a letter grade for the given score char gradeFromScore (double score) // Processes a line read from the raw-grades input file void processLine (ostream sout, const string &line) // Writes the report header to the given output file stream (ALREADY DONE void writeReportHeader (ofstream &out) Some notes on parsestudentRecord: .Given a line of text, stored in the variable line, you must extract the substrings that are separated by commas. There are a couple of approaches you can take for this: o Method 1: Load the line into a stringstream Use the overload of getline that takes an optional delimiter. This causes getline to read up to a comma instead of a newline o Method 2: Use use.find to find commas, then use .substr to extract substrings from in between those commas .Once you have extracted the scores as strings, you will have to convert them to ints. o For this you can use either stoi (string to int) or a stringstream

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

How do books become world of wonder?

Answered: 1 week ago