In this exercise, you will implement a medical diagnosis system.
Before you begin, look through the rules below and draw a decision tree so that you can see the full structure. You need this to test your program.
Use stepwise refinement. Don't try to implement all the rules all at once. If you try to do everything at once, you will most likely end up with many errors that are hard to track down. If you implement a little at a time, you will have less trouble pinpointing where the problems are. To start, only implement the outermost if-else statements. That is, write a program that prompts the user for their name (string) and temperature (integer) and then prints out to the screen whether the temperature is 1) 95 degress or less, 2) 101 or greater, or 3) is normal:
if the patient's body temperature is 95 degrees or less
print "The temperature is 95 degrees or less"
else if the patient has a temperature of 101 or greater
print "The temperature is 101 or greater"
else // the temperature is normal
print "The temperature is normal"
Use your decision tree to help direct the testing of your program each time you implement a little more. Don't wait until the end to test everything!
Be very careful with your indentation and with where you place brackets. The indentation helps you see where logical errors might occur. If the brackets are not correct, the program may run but not be correct (run-time error).
Once you have the above rules working and you are comfortable using if-else statements, try implementing the full set of rules given below (also see the Decision Tree). The implementation will require nested if-else statements.
Once again, before you begin, look through the rules and draw a decision tree so that you can see the full structure. You will need this see where leaves are missing and to test your program.
if the patient's body temperature is 95 degrees or less
ask if the patient has a pulse
if so,
tell the doctor to run a hot bath
else
tell the doctor to call the morgue
else if the patient has a temperature of 101 or greater
ask if the patient has a bad cough
if so,
ask if he/she has blue fingernails
if so
tell the doctor to give antibiotics
else
tell the doctor to give Tylenol
else
find out if the patient is foaming at the mouth
if so
find out if the patient was recently bitten by a dog, cat, or bat
if so,
tell the doctor to notify the next of kin that the patient might not get better
else // normal temperature
ask if the patient's head itches and has white egglike dots or crawling things in his hair
if so
tell the doctor to soak the patient's head in insecticide
else
ask if the patient has been losing extremities, such as fingers, toes, or nose, for unexplained reasons
if so,
caution the doctor not to give direct mouth-to-mouth resuscitation
Some of the sequences of answers for the questions above will lead to no diagnosis (these are the missing leaves). Rather than have no diagnosis, add additional code so that the program tells the patient that the doctor doesn't know what's wrong. No matter what, your program should give some answer even if it is to say it doesn't know the answer.
Test you program: For each leaf, enter the sequence of answers that should lead to that leaf. Does it give the right answer?