CPSC 124, Spring 2006
Programming Assignment 1: Random Math Quiz
In addition to the labs, there will be three longer programming assignments, including a final programming project of your choice. The first of the assignments is due on Friday, March 3. We will be covering material from Chapter 4 on subroutines before the assignment is due, but you should do the assignment using only material from Chapters 2 and 3. That is, you should write the entire program as a single main() routine.
This is an individual assignment. You should not give help to or receive help from any other member of the class. You should not discuss your program or show your work to other people in the class. You can get help from me or from the computer science TA's, but not from anyone else. You should not copy code from the Internet or from any other source. This is a matter of academic honesty and is covered by the Colleges' academic honesty policy.
The assignment is to write a more advanced version of the quiz program from the fourth lab. In the new version, you will create random math questions of several types, so that no two people taking the quiz will see the same questions.
You should ask ten questions. There should be at least four different types of questions, such as addition, subtraction, multiplication, and division problems. (You can substitute or add other types of math problems if you want, such as exponentiation or solving simple equations. One idea is a simple algebra quiz where the user has to solve equations of the forms x + A= B, x - A= B, A * x= B, and A * x + B = C, where A, B, and C are randomly chosen constants and the objective is to solve for x.)
Use a for loop to ask the questions; do not simply copy-and-paste the same code ten times.
For each of the ten questions, you should randomly select which type of question you are going to ask. Then, you should pick the numbers used in the question at random. For example, for an addition problem, you need to pick two integers at random from some reasonable range of values (say 0 to 99). You should present the question to the user, read the user's answer, and tell the user whether or not their answer is correct. If the user gets the answer wrong, you should give the user a second chance to give the correct answer. If the user gets the question wrong on the second try, you should tell them the correct answer.
The user should receive ten points for a correct answer on the first try, and should receive five points for a correct answer on the second try. At the end of the quiz, tell the user their total score on the quiz, how many questions were answered correctly on the first try, and how many questions were answered correctly on the second try.
Note that you should be careful about the numbers used in the questions that you ask. Think about what you want to do. Do you want to allow subtraction problems that have negative answers? Do you want to allow division problems where the denominator does not evenly divide the numerator? One way to get reasonable problems is to choose the answer at random, along with one of the numbers in the problem, and then calculate the other number in the problem.
Most of your grade on the project will be based on whether it works correctly. However, the program will also be graded partly on design (such as how you select the problems) and partly on style (such as commenting, variable names, and formatting). Some style rules were listed in Lab 4. Be sure to give a complete description of the program in your comments, including a discussion of exactly what types of questions can appear on the quiz.
I suggest that you write a pseudocode algorithm for the program before you begin and that you discuss your algorithm with me if you have any doubts about how to proceed. Remember that part of the assignment is for you to make sure that you understand what you are being asked to do.
You should turn in a printout of your program on March 3, and the program should be available for testing in your account. Use the a2ps or a2pslong command to make the printout. (Use a2pslong if you have any long lines in your program that are wrapped over two lines when the program is printed with a2ps.)
David Eck, February 2006