You are looking at lesson 2. Your place is still lesson 12, task 1: malloc.
hw/02/main.c: read P, K, E and the minutes missed, print the final grade, the rounded grade and the time in hours and minutes.
Checklist
The folder hw/02 already has a main.c stub and the tests. You write the program.
hw/02/main.cThe 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 is 0.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
(int)(x + 0.5): 9.55 must become 10, and 8.25 must become 8./ and %.if) yet: don't check the scores.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.
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.
Each one ticks itself when you do it.
All six done. You know your way around.
It is laid out like CLion: the same panels in the same places. This tour shows each one, and you can reopen it any time with Tour.
Switches the left panel: Lesson plan, Project files, Changes. Click the active icon again to hide the panel.
In CLion: the tool window bar runs down the left edge, too.
This part is not on this task: it appears when a task needs it.
Every task in this lesson. Now marks your place. Clicking a task only lets you look; it never moves your place. Project files and Changes open here too.
In CLion: this spot holds the Project view (the file tree).
This part is not on this task: it appears when a task needs it.
Opens the file for your task by itself. A tab appears for each file the step opens. The breadcrumbs above the code show the folder.
In CLion: the same editor tabs and breadcrumbs.
This part is not on this task: it appears when a task needs it.
Diff shows what changed, like git diff: red is the old code, green the new.
In CLion: the diff view in the Commit window looks the same.
This part is not on this task: it appears when a task needs it.
Terminal for build commands, Database to see your tables. They open by themselves when a task needs them. Drag the top edge to resize.
In CLion: Terminal, and the Database tool window.
This part is not on this task: it appears when a task needs it.
What to do now, right above the code, so you never miss it. Numbered notes in the code explain the important lines. Details shows what you should see and a hint.
In CLion: no equivalent: this is your lecturer's guide.
This part is not on this task: it appears when a task needs it.
Done is the only button that moves you forward. Look back lets you review without losing your place.
This part is not on this task: it appears when a task needs it.
Guided, Focus code or Floating. You can drag the panel edges too. Your layout is remembered for next time.
In CLion: you can also rearrange and hide tool windows.
This part is not on this task: it appears when a task needs it.
Six small missions. Each one ticks itself when you do it, so you know you have found everything.