15 min

Lab experiments

The 18 experiments of the lab exam, the eight patterns they use, and the unit that prepares each one.

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:

  1. write a working C program,
  2. find and fix compile errors and run-time errors,
  3. use the eight patterns that appear in almost every experiment.

The eight patterns

PatternWhat it does
אwhile loop with a sentinelread values until a special value says "stop"
בCountingcount how many items there were
גCounting with a conditioncount only the items that meet a condition
דSummingadd up all the values
הSumming with a conditionadd up only the values that meet a condition
וMaximum / minimumfind the largest or smallest value
זMaximum / minimum with a companion valuefind the largest value and what came with it (for example, whose grade it was)
חCombining patternsfor 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 writeUnit
1Read positive integers until a negative number; print the sum, the count and the average6
2Same input; print the largest and the smallest number6
3Same input; print how many numbers are above 50 and how many are below 506
4Read grades until an impossible grade (above 100 or below 0); print the average and how many grades are above 906
5Basketball 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 m6
6Read 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 digits2, 4
7Read a character and say whether it is a digit, an uppercase letter, a lowercase letter, a space or "other"4, 5
8Check whether a positive integer is a palindrome (like 454 or 123321)6
9Print a number with its digits reversed, where the N-th digit from the right is printed N times: 123 → 322111, 4567 → 76655544446
10Read 10 integers into an array; print the sum, the average, the largest and the smallest8
11A 10 × 10 array: is the main diagonal equal to the secondary diagonal?9
12Write 10 integers to the file text.txt, read it back and print the averagelater (files)
13A function that receives two pointers to int and swaps their values; print before and afterlater (pointers)
14A struct for a point in the plane; read two points and say whether they are in the same quadrantlater (structs)
15Sort 10 integers in ascending order, then in descending order10
16A string of up to 30 characters: count uppercase letters, lowercase letters, digits and "white" characters (everything else)8
17An 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 point8
18struct student with an ID, a name and an average: read data into avi and check whether the average is 55 or morelater (structs)