15 דק׳
ניסויי המעבדה
18 הניסויים של בחינת המעבדה, שמונה התבניות שהם משתמשים בהן, והיחידה שמכינה לכל אחד.
באנגלית בלבד
השיעור הזה כתוב באנגלית בלבד.
How the lab exam works
In the lab exam you get one experiment from the list below, drawn at random, and you write it at the computer in front of an examiner. The examiner checks that you can:
- write a working C program,
- find and fix compile errors and run-time errors,
- use the eight patterns that appear in almost every experiment.
The eight patterns
| Pattern | What it does | |
|---|---|---|
| א | while loop with a sentinel | read values until a special value says "stop" |
| ב | Counting | count how many items there were |
| ג | Counting with a condition | count only the items that meet a condition |
| ד | Summing | add up all the values |
| ה | Summing with a condition | add up only the values that meet a condition |
| ו | Maximum / minimum | find the largest or smallest value |
| ז | Maximum / minimum with a companion value | find the largest value and what came with it (for example, whose grade it was) |
| ח | Combining patterns | for example counting and summing together to get an average |
All eight are taught in unit 6 (loops) and used again with arrays in unit 8.
The 18 experiments
| # | What you write | Unit |
|---|---|---|
| 1 | Read positive integers until a negative number; print the sum, the count and the average | 6 |
| 2 | Same input; print the largest and the smallest number | 6 |
| 3 | Same input; print how many numbers are above 50 and how many are below 50 | 6 |
| 4 | Read grades until an impossible grade (above 100 or below 0); print the average and how many grades are above 90 | 6 |
| 5 | Basketball tryout: for each student read the hits (out of 10) and the height, until the hits are negative; count the students with more than 6 hits who are taller than 1.5 m | 6 |
| 6 | Read a three-digit number. If it is even and divisible by 5, print the tens digit; if it is even and not divisible by 5, print the units digit; if it is odd, print the sum of its digits | 2, 4 |
| 7 | Read a character and say whether it is a digit, an uppercase letter, a lowercase letter, a space or "other" | 4, 5 |
| 8 | Check whether a positive integer is a palindrome (like 454 or 123321) | 6 |
| 9 | Print a number with its digits reversed, where the N-th digit from the right is printed N times: 123 → 322111, 4567 → 7665554444 | 6 |
| 10 | Read 10 integers into an array; print the sum, the average, the largest and the smallest | 8 |
| 11 | A 10 × 10 array: is the main diagonal equal to the secondary diagonal? | 9 |
| 12 | Write 10 integers to the file text.txt, read it back and print the average | later (files) |
| 13 | A function that receives two pointers to int and swaps their values; print before and after | later (pointers) |
| 14 | A struct for a point in the plane; read two points and say whether they are in the same quadrant | later (structs) |
| 15 | Sort 10 integers in ascending order, then in descending order | 10 |
| 16 | A string of up to 30 characters: count uppercase letters, lowercase letters, digits and "white" characters (everything else) | 8 |
| 17 | An array of 13 integers: the largest and how many times it appears, the smallest and how many times it appears, and the average with 3 digits after the decimal point | 8 |
| 18 | struct student with an ID, a name and an average: read data into avi and check whether the average is 55 or more | later (structs) |