Question
C++ Assignment parse_scores.h #include /* Description: * Extracts a single grade for a given student and given grade number. * Preconditions: * - If file
C++ Assignment
parse_scores.h
#include
/* Description: * Extracts a single grade for a given student and given grade number. * Preconditions: * - If file exists, it is correctly formatted * Parameters: * - student_id: the id of the student for grade * - grade_no: the grade to be returned for matching student_id * - file_name: path and name of gradebook file * Returns: * - Grade selected * - floating point -1.0 when student is not found (or no students exist) * - floating point -2.0 when grade_no is not found (or no student grades) * - floating point -3.0 when file cannot be opened */ double GetGrade(int student_id, int grade_no, const char* file_name);
/* Description: * Extracts the id of the student with the highest grade. * Preconditions: * - If file exists, it is correctly formatted * - Grades are nonnegative. * Parameters: * - file_name: path and name of gradebook file * Returns: * - The id of the student with the highest grade. * - Integer -1 when no students exist * - Integer -2 when no grades exist for students * - Integer -3 when the file cannot be opened */ int GetMaxGradeStudentId(const char* file_name);
/* Description: * Calculates the average for all students in file. * Preconditions: * - If file exists, it is correctly formatted * - Grades are nonnegative. Adjust accordingly. * Parameters: * - file_name: path and name of gradebook file * Returns: * - The highest grade found. * - Floating point -1.0 when no students exist * - Floating point -2.0 when no grades exist * - Floating point -3.0 when the file cannot be
test_parse_scores.cc
#include
#include "../hw2/parse_scores.h"
bool TestGetGradeGood(const char* filename); bool TestGetGradeNoStudent(const char* filename); bool TestGetGradeNoGrades(const char* filename); bool TestGetGradeNoFile(const char* filename);
bool TestGetMaxGradeGood(const char* filename); bool TestGetMaxGradeNoStudents(const char* filename); bool TestGetMaxGradeNoGrades(const char* filename); bool TestGetMaxGradeNoFile(const char* filename);
bool TestGetAvgGradeGood(const char* filename); bool TestGetAvgGradeNoStduents(const char* filename); bool TestGetAvgGradeNoGrades(const char* filename); bool TestGetAvgGradeNoFile(const char* filename);
int main(int argc, char* argv[]) { int return_val = 0;
const int kFilenameIdx = 1; if (argc
std::cout
std::cout
std::cout
return return_val; }
bool TestGetGradeGood(const char* filename) { return GetGrade(101, 2, filename) == 40.0 && GetGrade(294, 3, filename) == 30.0 && GetGrade(376, 1, filename) == 75.0; }
bool TestGetMaxGradeGood(const char* filename) { return GetMaxGradeStudentId(filename) == 376; }
bool TestGetAvgGradeGood(const char* filename) { return GetAvgGrade(filename) == (60.0 + 40.0 + 10.0 + 20.0 + 30.0 + 75.0) / 6.0; }
makefile
CC = g++ # use g++ compiler
FLAGS = -std=c++17 # compile with C++ 11 standard FLAGS += -Wall # compile with all warnings
LINK = $(CC) $(FLAGS) -o # final linked build to binary executable
COMPILE = $(CC) $(FLAGS) -c # compilation to intermediary .o files
test_parse_scores : test_parse_scores.cc parse_scores.o $(LINK) $@ $^
parse_scores.o : parse_scores.cc parse_scores.h $(COMPILE) $
clean: rm -f parse_scores.o test_parse_scores
Tue 13:02 Activities 1 @ Document Viewer of 1 a @ hw2 hw2.pdf 100% v Q = 0 Thu... * * CSCE 240 HOMEWORK 2 DUE: 18 FEBRUARY 2020 You shall submit a zipped, and only zipped, archive of your homework directory, hw2. The directory shall contain, at a minimum, the files parse_scores.cc and parse_scores.h. Name the archive submission file hw2.zip I will use my own makefile to compile and link to your parse_scores.cc and parse_scores.h files. You must submit, at least, these two files. This assignment tests your ability to parse data based on a provided format. The premise is a text-based grade book with which you will interact using basic file I/O. You will provide a small library of three functions: GetGrade GetMaxGradeStudentId . GetAvgGrade The functions shall accept a character string which can be used to open a file with an fstream object. The file format is described as: number of students student_id number_of_grades grade_0 grade_1 grade.nl Read the provided header file documentation for instructions on how the functions should work. I have provided you a basic test app which you can use to ensure that your code is somewhat passing I would suggest a much more rigorous testing scheme. Your code must behave as indicated in the documen- tation. Passing the tests is not enough to get full credit. You may call the test by using ./test-parse_scores gradebook.txt Late assignments will lose 10% per day late, with no assignment begin accepted after 3 days. Check your syllabus for the breakdown of grading Tue 13:02 Activities 1 @ Document Viewer of 1 a @ hw2 hw2.pdf 100% v Q = 0 Thu... * * CSCE 240 HOMEWORK 2 DUE: 18 FEBRUARY 2020 You shall submit a zipped, and only zipped, archive of your homework directory, hw2. The directory shall contain, at a minimum, the files parse_scores.cc and parse_scores.h. Name the archive submission file hw2.zip I will use my own makefile to compile and link to your parse_scores.cc and parse_scores.h files. You must submit, at least, these two files. This assignment tests your ability to parse data based on a provided format. The premise is a text-based grade book with which you will interact using basic file I/O. You will provide a small library of three functions: GetGrade GetMaxGradeStudentId . GetAvgGrade The functions shall accept a character string which can be used to open a file with an fstream object. The file format is described as: number of students student_id number_of_grades grade_0 grade_1 grade.nl Read the provided header file documentation for instructions on how the functions should work. I have provided you a basic test app which you can use to ensure that your code is somewhat passing I would suggest a much more rigorous testing scheme. Your code must behave as indicated in the documen- tation. Passing the tests is not enough to get full credit. You may call the test by using ./test-parse_scores gradebook.txt Late assignments will lose 10% per day late, with no assignment begin accepted after 3 days. Check your syllabus for the breakdown of gradingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started