| Lecture notes for the Introduction to Computer Science I by James Tam | Return to the course web page |
General assignment hints
How to solve your fifth assignment
in stages:
Version 1: Learning about the basics of modular design (functions and
procedures). Since I've outlined in the assignment description some of the
functions and procedures that you must implement you won't have spend a great of
time planning out how to break things down but you do have to get very familiar
with the details of how to define and execute the code for these modules.
Your first version could simply be a "skeleton" of all the modules in your
program, meaning that all your functions and procedures will be listed but there
will be no statements in the body of each module save for some output messages so
you know when a particular module is being run. You can implement the code
for the modules in successive versions, the idea for the first version is to
determine EXACTLY what you need to create a compilable program that uses and
calls functions and procedures. Also for this version I would write
modules that take no parameters because you can always rewrite your function and
procedure definitions later. The first version of your program could look
something like this.
Once you have a compilable and working version back it up and DO NOT touch the
backup. Only make your modifications on the copy so that you will
always have at least a partially working version if disaster strikes and you
have insurmountable logic errors in later versions that you just can't figure
out before the assignment deadline.
Version 2: Learning about parameter passing. You can write your solution as a simpler version of the assignment, e.g., it only allows a single student (stored as a character variable and not as a character array) so that you can teach yourself the more advanced concepts of modular design such as parameter passing. In this version you'll likely only implement a few modules:
With this version of the program, instead of declaring an array of characters as described in the assignment) you should declare only a single character variable in the main procedure and learn how to pass it as a both a value and variable parameter. The second version of your program could look like this. This will allow to work figure the logic of some assignment even before you learn about the syntax of how to use an array.
Again: Once you have a compilable and working version back it up and DO NOT touch the backup.
Version 3: Implementing some more of the required functionality of the assignment program without using an array. In this version of your program you can actually try to implement some of the more difficult code (e.g., finding the mean grade) for the remaining functions and procedures with a class size of two students. You can do this by declaring two variables that are characters and passing these variables into each module. Note: This version (which uses multiple declarations of real variables) is NOT the way you should implement your final version. However doing it in this incorrect way first will give you a much better appreciation for why arrays are so useful... Once you get this version working it should be a fairly easy to replace the character variables with a single array whose elements are characters and to make a few slight changes to your modules so that they manipulate a single array rather than just separate variables.
1 In case skeptical about how true my statements are because you have worked out a few numbers and are wondering how I ended from starting out as a first year student to graduate student to full time faculty member so quickly, I finished my undergrad degree in a little over two years and was hired to work full time while I was still a full-time grad student so my time here was somewhat 'compressed'.