The main program for this chapter is a fun and powerful tool that can be used in many different ways. It is not simply one program, but a system of programs that work together to let you create, administer, and grade multiple choice quizzes automatically.
It would be reasonably easy to build an HTML page that presents a quiz and a PHP program to grade only that quiz. However, if you will want several quizzes, it might be worth the investment in time and energy to build a system that can automate the creation and administration of quizzes. The real power of programming comes into play not just when you solve one particular immediate problem, but when you can generate a general solution that can be applied to an entire range of related problems. The quiz machine is an example of exactly such a system. It takes a little more effort to build such a system in the beginning, but the effort really pays off when you have a system you can re-use many times.
Figure 6.1 shows the main page of the system. The user will need a password to take a test, and a different administrator password to edit a test. In this case, I've entered the administrative password (it's "absolute" - like in "absolute beginner's guide") into the appropriate password box, and I'm going to edit the Monty Python quiz.
If the user has the correct password, the screen shown in Figure 6.2 appears, displaying the requested quiz in a special format on the screen.
The quiz administrator can edit the quiz in a number of ways. Each quiz has a name, instructor e-mail address, and a password. Each question is stored in a single line with the question, four possible answers, and the correct answer separated by colon (:) characters.
Users with knowledge of the appropriate password can take any of the quizzes known to the system. If a user chooses to take the Monty Python quiz, the screen shown in Figure 6.3 appears.
When the user takes a quiz, the user's responses are sent to a program that grades the quiz and provides immediate feedback, as shown in Figure 6.4
The system keeps a log file for each quiz so the administrator can tell the scores of each person who took the quiz. Figure 6.5 shows how people have done on the Monty Python quiz.
Although the resulting log looks very simplistic, it is generated in a format that can easily be imported into most gradebook programs and spreadsheets. This is very handy if the quiz will be used in a classroom setting.