Homework: the gradebook in modules
The gradebook, version 2: the same behaviour, but in modules. The hw/07-gradebook folder already has four files for you to fill in and two test files you don't need to change.
What to do
gradebook.c– move your functions fromhw/06-gradebook/main.chere:read_grades,print_grades,average,highest,lowest,sort_grades,find_grade,print_distribution. Each with anassertfor its precondition, as in topic 6. Delete the(void)lines and theTODOs.main.c– movemainhere. No functions stay in it, andMAX_GRADEScomes fromgradebook.h.gradebook.h– the list of functions is already written; don't change it, because the tests call it. Rewrite the comments as Doxygen:@fileand@briefat the top, and for every function@brief,@param,@return(if it returns something) and@pre. Delete theTODO.
CMakeLists.txt is ready, as in step 7: gradebook.c is the library hw07_gradebook_lib and main.c the program hw07_gradebook. Read it: these are the same commands.
Tests
ctest --preset debug -L hw07
-
hw07_functions–unit_tests.ccalls your functions throughgradebook.hwith the known grades8 10 7 9 10. While the functions are empty:Assertion failed: nearly_equal(average(grades, 5), 8.8), file .../hw/07-gradebook/unit_tests.c, line 20The message says which function returned the wrong thing, and with what data.
-
hw07_precondition–average(grades, 0)must stop at yourassert. -
hw07_gradebook_1–3– the same three output tests as in topic 6: the program must behave exactly the same. -
hw07_doxygen,hw07_contracts,hw07_main– file tests:gradebook.hhas the Doxygen tags,gradebook.chasassert(, noTODOis left anywhere, andMAX_GRADES 30is defined only ingradebook.h.
Handing in
Commit and push. Actions → Points: HW 7 (Gradebook in modules), 10 points when all eight tests pass.
In topic 9 the gradebook gets students' names, so the list in gradebook.h will grow.