Project 3 Comments
CS35: Programming and Problem Solving
Ray Ontko
Department of Computer Science
Earlham College
The following are comments that apply to programs submitted by
students for the assigned
Project 3.
Since similar suggestions apply to many programs, and because
it may be useful for students to see other suggestions about the
program in addition to the ones pertinent to their particular
program, I have collected the comments here.
- File header comment. Each C source file should begin with
a comment which includes the name of the file, a brief description
or summary of its contents, the author, and the approximate date
of authorship. Although a one-line description may be
adequate, you should consider including a paragraph or two
containing a complete specification for the program. You may
also wish to reference (by URL for example) any external
specification documents, and any extensions or deviations
to the original specification which you may have implemented.
- Eliminating duplicate balls. When randomly drawing balls from
a drum, we wish to eliminate any balls previously drawn. Although
there are many ways to do this, perhaps the easiest is to simply
draw a new ball in the range 1 through 49 and compare it to each of the
previously drawn balls. If the new ball is a duplicate of a previously
drawn ball, we simply "throw away" the ball and try again.
- Sorting player picks. Although the specification of the program
doesn't explicitly mention sorting the numbers picked by the player,
you may have noticed that the example run of the program shows them
in sorted order, even though the user entered them out of order.
What changes would you need to make to cause the program to display
the player picks in order?
- Listing of program output. For this class, always include a
listing showing the output of your program, or other evidence that
the program runs correctly. Although I can usually tell what the
program should do, it's easier for me to give you feedback
on what it actually does, and helps me understand the
circumstances under which you tested it (i.e., demonstrated for
yourself that the program worked).
- Using srand(). In any program which uses rand(), you should
probably being the program with a call to srand(time(NULL)) to
"randomize" the random number sequence. Without a call to srand(),
your program will get the same sequence of random numbers from rand().
By using time(NULL) to initialize the "seed" for rand(), you'll get a
different sequence depending on the number of seconds past midnight
when your program begins execution.
- Order of picks. Note that the order in which the player
picks numbers, and the order in which the numbers are picked
does not matter. In other words, if the player picked
"1 3 5 7 9 PB 29", but the simulated powerball game picked
"9 5 1 7 3 PB 29", the player would still win. Your program
should allow the player to pick in any order, and the game
balls to be picked in any order; winning should be without
regard to the order picked.
- Sorting game picks. Note that the balls drawn by the game
should be listed in ascending order, followed by the powerball
pick.
- Function description. Each function definition should
be preceded by a comment which gives a summary of what the
function does, in English. This may take the form of a
brief specification for the function.
- Disallow duplicates. One of the requirements of the
powerball program is to prevent the user from picking
the same number twice. For example "3 23 32 13 3 PB 41"
would be an invalid pick by the user, because "3" occurs
twice. Your program should print an error and perhaps
allow the user to re-enter their picks. While you're at
it, you might also make sure that the numbers entered are
in the correct ranges (1 through 49 for the white balls,
and 1 through 42 for the powerball).
- Invalid operator. Suppose the user enters an invalid
operator for the fraction program. Does the program give
an error message? Does the program still attempt to
reduce the result or print a solution? Your program should
behave reasonably if invalid input is given.
- scanf() returns value. Remember that scanf() returns a
value: the number of "things" read. Consider modifying read_fraction()
to return a 1 if the fraction was read, a 0 if it wasn't read, and
EOF if an EOF occurred while trying to read the fraction.
You would then be able to use the return value to help your program
decide whether to continue processing after a read_fraction().
- Not just one calculation. Note that the specification for the
fractions program calls for a program that reads a number of fraction
operations, one per line. Your program should include a loop which
reads fraction/operator/fraction lines until EOF.
Copyright © 1999,
Ray Ontko
(rayo@ontko.com)