CS21 Homework 6
Due Sunday, October 5 by 11:30pm
Introduction
This assignment serves two purposes. First, you can continue to
practice using top-down design and second, you will learn to use the
random number library. This assignment has been adapted from
programming exercises 8.8 and 8.9 from our textbook The Art and
Science of C.
You should work on your own for this assignment.
Educational Software: A Math Quiz
As computers become more common in schools, it is important to find
ways to use them to aid in the teaching process. This need has led to
the development of an educational software industry that has produced
many programs that help teach concepts to children.
As an example of an educational application, write a program that
poses a series of simple arithmetic problems for a student to answer,
as illustrated by the following sample run:
Welcome to Math Quiz.
This program will ask you a series of 5 math
questions using addition and subtraction.
Have fun!
1. What is 5 - 4? 1
You rock!
2. What is 9 - 7? 2
Nice job.
3. What is 16 - 7? 8
That's incorrect. Try a different answer: 9
Well done.
4. What is 12 + 3? 16
That's incorrect. Try a different answer: 17
That's incorrect. Try a different answer: 11
No, the answer is 15
5. What is 17 - 6? 11
Yes indeed.
You answered 4 out of 5 questions correctly.
Goodbye and thanks for using Math Quiz.
Getting Started
Remember that your main program should be short and abstract. Most
of the details for solving the problem should be divided up into
functions.
Your program should meet the following requirements:
- It should ask a series of five questions. As with any such limit,
the number of questions should be coded as a #define constant
so that it can be easily changed. As you read the remaining
requirements, think about what other aspects of the program should
also be coded as constants.
- Each question should consist of a single addition or subtraction
problem involving just two numbers. The type of problem, addition or
subtraction, should be chosen randomly for each question.
- To make sure the problems are appropriate for students in the first
or second grade, none of the numbers involved, including the answer,
should be less than 1 or greater than 20. This restriction means that
your program should never ask a question like "What is 11 + 13?" or
"What is 3 - 7?" because the answers are outside the legal range.
Within these constraints, the program should choose the numbers
randomly.
- The program should give the student three chances to answer each
question. If the student gives the correct answer, your program
should indicate that fact in some properly congratulatory way and go
on to the next question. If the student does not get the answer in
three tries, the program should give the answer and go on to another
problem.
- To keep the student interested, your program should randomly
choose from at least five different congratulatory messages when the
student gives a correct answer, as demonstrated in the sample run
above.
- The program should keep track of how many questions the student
was able to answer correctly, and it should report the results at the
end.
Handing in your solution
Use cs21handin to turn in your program.