Homework
Homework: exam results
The folder hw/03 has a main.c stub and two tests.
Exam results: hw/03/main.c
Print the text exactly as below, because that is what the tests check.
- Ask
How many students?. While the answer is less than 1:At least one student is needed.and ask again. - For each student write the number (
1.) and askPoints:. While the points are not 0–100:Points must be between 0 and 100.and ask again (without the number now). - Turn the points into a grade by the table and write
Grade:, the grade, a space and as many stars*as the grade. - After all the students, two lines: how many passed (a grade of 5 or more) and what share that is in percent, with one digit after the dot; then the best number of points.
| Points | 95–100 | 85–94 | 75–84 | 65–74 | 55–64 | 45–54 | 35–44 | 25–34 | 15–24 | 0–14 |
|---|---|---|---|---|---|---|---|---|---|---|
| Grade | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
An example (hw/03/tests/1.in.txt):
How many students? 4
1. Points: 87
Grade: 9 *********
2. Points: 120
Points must be between 0 and 100.
Points: 97
Grade: 10 **********
3. Points: 44
Grade: 4 ****
4. Points: 63
Grade: 6 ******
Passed: 3 of 4 (75.0 %)
Best result: 97 points
- The stars are a loop inside a loop: the inner
forruns as many times as the grade. - You can write the table as an
if/else ifchain. There is a shorter way with/too: notice that the limits come every 10. - A
%in a printf string is written%%.
Tests
The second test (2.in.txt) checks what the example doesn't: 0 students, negative points and the limits 0 and 100.
ctest --preset debug -L hw03
Handing in
Commit and push. Actions → Points: HW 3 (Exam results), 10 points when both tests pass.