Homework: the semester summary
The folder hw/02 already has a main.c stub and the tests. You write the program.
The semester summary: hw/02/main.c
The program reads four values, in this order and with these questions:
| Question | What to type | Function |
|---|---|---|
Practical work (P): |
the P score (practical work), e.g. 9 |
read_double |
Tests (K): |
the K score (the two tests), e.g. 7.5 |
read_double |
Exam (E): |
the E score (the exam) | read_double |
Minutes missed: |
minutes missed, a whole number | read_int |
Then it prints three lines:
Final grade:and the final grade with 2 digits after the dot. It is worked out with the course formula: P 40 %, K 30 %, E 30 %, that is0.4 * P + 0.3 * K + 0.3 * E.Rounded:and the final grade rounded to a whole number.Missed:and the time missed in hours and minutes:X h Y min.
For example:
Practical work (P): 9
Tests (K): 7.5
Exam (E): 8
Minutes missed: 185
Final grade: 8.25
Rounded: 8
Missed: 3 h 5 min
- Round with
(int)(x + 0.5): 9.55 must become 10, and 8.25 must become 8. - For the hours and minutes you need
/and%. - No conditions (
if) yet: don't check the scores.
Tests
There are two tests with different input (hw/02/tests/1.in.txt and 2.in.txt), so one answer is not enough: the program has to calculate. The test runs the program with input from a file, and input.h shows the lines it reads in the output, so hw/02/tests/1.expected.txt looks exactly like the Run window.
All CTest → ▶, or only this topic's tests in the terminal:
ctest --preset debug -L hw02
While something is wrong, the test shows the first line that differs:
=== hw02_summary_1: FAILED ===
The output differs on line 6.
expected: |Rounded: 8|
got: |Rounded: 9|
(\t = tab, ~ = a space at the end of the line)
Here the rounding went too far: probably (int)(x + 1) or (int)x + 1.
Handing in
Commit and push. In the Actions tab, in the Points step, you see the points for HW 2 (Semester summary): 10/10 ✓ when both tests pass.