CS201
Lab 6 - Multiple File Compilation
Objectives:
- Solve a hospital supply problem using a C program.
- Understand differences between passing parameters "by value", and "by
reference".
Readings:
- Read Chapter 6 in the Hanly/Koffman text.
Deliverables: (DUE 48 HRS AFTER THE END OF YOUR LAB!)
- Submittal of the following files:
- Makefile
- proto.h
- lab6.c
- get_problem.c
- get_rate_drop_factor.c
- get_kg_rate_conc.c
- get_units_conc.c
- fig_drops_min.c
- fig_ml_hr.c
- by_weight.c
- by_units.c
TO DO (for today's lab)
- Design and Write a program to solve Programming Project #2
on page 321-323 of the Hanly/Koffman text.
- You will need to build 11 separate source files (listed above!) and modify
your Makefile to properly rebuild the run image. Here is
more info on linking the source files.
- File proto.h should include prototypes of all functions mentioned in your
textbook (p. 322). Here is more
info on the role of proto.h.
- Use redirection to enter your data for all five different types of runs.
Go ahead and prompt for these values. This will allow you to
hand test your program before submittal.
- Make sure to test your program thoroughly. You may use testing files and use
input/output redirections to perform the tests, as we do when checking your work. Here
is more info on this topic.
-
Note: There will be quite a few prompts coming out of your
program. You will need to have them formatted exactly as shown in the
text to be sure that our tests script run properly. I know it is a pain in your
... neck, but it
speeds up the grading significantly (think in "55 students to 1
grader" scale...).
- Use integers for all parameters except the rate
in mg/kg/hr (job no.3 in your project) which will need to be a float.
- Comment your code appropriately. We would like to see characterization of
function, variables, Pre- and Post-conditions, and etc. for every function you
write. I hope you already know what to
do. If not go back to Chapter 3 and have a nice reading. :)
- You do not need to submit your sample data file. We have test data files
for the automatic script to use to test your program. Each of the files test all four problems and
then terminate with a problem choice of 5.
- And now study the hints below... :)
Helpful Hints (I put graphics below, so you would not just copy this stuff...)
Declaring prototypes in a
header file
I like to put all my prototypes in a separate file (here, I called it proto.h)
and then to include this file in my main program (#include
“./proto.h”). When you do it this way, you may need some additional
pre-processor directives to avoid duplications of your declarations (just to
play it safe...). This time, file proto.h should include prototypes of all functions mentioned in your textbook
(p. 322). Here is a sample proto.h file (I included pre-processor directives to avoid
accidental duplications of my functions' prototypes):
Linking the source files
OK, so here is an example of what you want to do (using your Makefile):
And here is how you can get there:
References to
proto.h in the Makefile
can be omitted, if you included it as I mentioned
above. Repetitions do
not bother us, since we used Conditional Compilation in our header file.
Testing the program
You can test your program by controlling it from your screen and keyboard. For a test run
of only problem 4 you can enter:
4
1000
25
5
The above data should produce the following results.
The rate in milliliters per hour is 40.
You can also write test files (with job selections and relevant data entries)
and use input redirection. For instance if you enter to test numbers
to your test file as presented on the left-hand side of the figure below, you can simulate
some
cases, as presented on the right-hand side of the figure.
To perform automatically more detailed tests, you can redirect BOTH input and output (type:
lab6 < MyInput > MyOutput). MyOutput will
NOT have the responses to the input prompts, just the prompts all run together.
Formatting the output
There will be quite a few prompts coming out of your
program. You will need to have them formatted exactly as shown in the
text to be sure that our tests script run properly. I know it is a pain, but it
speeds up the grading significantly so we are stuck with it. The following are two sample outputs. The first
is with normal blanks, and the second is with the long strings of
blanks replaced by small b's. This should help you count
the spacing of the expected output. I try to post more examples here shortly...
Make sure you match the outputs exactly! Good luck!
INTRAVENOUS RATE ASSISTANT
Enter the number of the problem you wish to solve.
GIVEN A MEDICAL ORDER IN
CALCULATE RATE
IN
(1) ml/hr & tubing drop factor
drops / min
(2) 1 L for n hr
ml / hr
(3) mg/kg/hr & concentration in mg/ml
ml / hr
(4) units/hr & concentration in units/ml
ml / hr
(5) QUIT
INTRAVENOUS RATE ASSISTANT
Enter the number of the problem you wish to solve.
bbbbGIVEN A MEDICAL ORDER INbbbbbbbbbbbbbbbbCALCULATE RATE
IN
(1) ml/hr & tubing drop factorbbbbbbbbbbbbbbdrops /
min
(2) 1 L for n hrbbbbbbbbbbbbbbbbbbbbbbbbbbbbml / hr
(3) mg/kg/hr & concentration in mg/mlbbbbbbbml / hr
(4) units/hr & concentration in units/mlbbbbml / hr
(5) QUIT
Here are some results I got, maybe you will find it useful when programming:
