In this assignment, you will write C code for a "reaction tester". The reaction tester will measure the user's time to solve trivial sums.
The reaction tester should present 5 random one-digit addition problems with one-digit solutions to the user. As each problem is presented, the time the user takes to enter a correct solution should be measured. If the user enters an incorrect solution, replacement problems should be presented until a correct solution is obtained.
When the testing is finished, the reaction tester should present a report consisting of:
- Number of incorrect responses.
- Minimum time in milliseconds to correctly solve a problem.
- Maximum time in milliseconds to correctly solve a problem.
- Average solution time in milliseconds over all correct answers.
$ ./reaction 3 + 5 = 8 2 + 0 = 2 1 + 8 = 9 6 + 1 = 7 6 + 2 = 7 wrong: answer was 8 7 + 2 = 9 wrong answers: 1 minimum time: 1624 ms maximum time: 2192 ms average time: 1793 ms $
To make this program work, you will want:
srandom()C library functions, to produce random problems. Note that you can get a random digit via
random() % 10.
getpid()C library function, to get a "seed" value for
srandom(), so that successive runs of the program present different problems.
gettimeofday()C library function, to find out how long the user spent reacting.
Please name your program
reaction.c. Your program must
finish with a zero exit status.
Your program must be formatted according to the Linux kernel coding style https://www.kernel.org/doc/Documentation/CodingStyle, which is basically "K\&R". You will be using "C99", so take advantage of its features, including mid-block definitions and for-loop variable definitions:
for (int i = 0; i < 100; i++)
The code should be as clear and readable as you can make it: the graders and TAs are going to read a lot of programs, and if yours is hard to understand they will just subtract points and move on.
Your program must start with a comment containing a valid copyright line and a comment indicating the function of the program. For example
/* Copyright (c) 2016 Bart Massey */ /* Reaction Tester */
Each non-trivial function should have a short comment at the top indicating its behavior.
Your program must have a
Makefile that will build it
gcc as the C compiler. The default compiler flags
-std=c99 -Wall -Werror.
Your submission must include a writeup in Markdown format
http://daringfireball.net/projects/markdown/ in a file
README.md. The writeup should contain your name,
a sample run of your program (like the one above), and a
description of anything interesting about your program or
For this assignment, you are not required to use source control. However, I strongly suggest putting all your project files under source control: it will avoid backup file messes and give you a good history of work. My recommendation is Git: it's what I use.
You should submit your materials (program, Makefile,
writeup) to the course website as a ZIP archive called
reaction.zip. Use the assignment submission interface on
the course website to upload your archive.
Total 100 points - Makefile 20 points - Program 50 points - Writeup 30 points