Lab #1: Estimating Blood Alcohol Content
Pre-Lab
This lab requires an understanding of:
-
How to lay out buttons and labels on a form and
access the click event. Tutorial 2-15 in the textbook gives an examle of
converting a kilometer to inches, feet, yards, or miles that can help you
prepare for this lab.
-
How to define variables of different data types and
perform arithmetic operations. These are covered in Chapter 3.2 and
3.3.
Lab
The following formula gives a rough estimate of your blood alcohol content (BAC)
and is derived from formulas posted by the National
Highway Traffic Safety Administration:
BAC = (4.136 × numDrinks ×
ouncesAlcohol) / (weight)
-
numDrinks is the number of drinks ingested.
-
ouncesAlcohol is the number of ounces of alcohol per drink
-
weight is the weight of the drinker in pounds
Note that this is a ROUGH estimate and doesn't include your metabolism, time spent drinking, gender differences, etc.
Write a program that calculates the blood alcohol
content of someone drinking Jagerbombs. Assume that
there are 0.55 ounces of
alcohol in one Jagerbomb. Pick values of your own choosing for the number of drinks and the weight.
The design of your form should look like the following:
Name the button btnCalculate. There are two
labels, one has the text "Blood Alcohol Content" and the second has the text
"Unknown". Name the second label lblBAC.
Next, write code that goes into the button click event for btnCalculate.
Define four variables using the Dim
statement. The variables should be numDrinks,
ouncesAlcohol, weight, and
BAC. It is up to you to determine the
appropriate data type for each variable.
Pick a value of your choice for numDrinks and use
the assignment statement to set numDrinks equal to
your selected value. Do the same for weight. Use 0.55 for the value to store into ouncesAlcohol.
Compute the blood alcohol content using the formula given above
and assign the value into the variable BAC.
Set the Text property of lblBAC to the value saved in the variable BAC.
Run the program. Upon clicking the button the estimated BAC should be
displayed in the label. Shown below is output for a 140 pound person drinking 5
jagerbombs.
Experiment with other values to see if the program is
working correctly. It's kind of a pain to change the values in your code
and recompile to see the BAC - later we will see how to modify our program to
input the weight and number of drinks on the form instead of hard-coding them
into the program.
To Turn In
- To turn in your programs you will need to submit several files.
Using the windows explorer, navigate the file system to the place where you
created your project. The default location is "My Documents/Visual
Studio 2008/Projects". There should be a directory (i.e. folder)
there that matches your project's name.
- For me to run the project, I need all of the files in this directory. This
can be done by packaging all the files into one "zip" file. The easiest
way to create a zip file is to right-click on the folder and select "Send
To --> Compressed (zipped) Folder" (this only works on Windows XP or Vista,
if you are using another OS then you'll need WinZip or another compression
program):
![](lab1files/files.gif)
- This will create a Zip compressed file that will
contain all of the selected files. The default name is the same
name as your folder, with a .ZIP extension (e.g. CS111_Lab1.zip in my example).
- Send the zip file you created to me by logging into blackboard and
submitting it under Assignments. Go to http://technology.uaa.alaska.edu/blackboard and log in using your UAA account
name and password.
- Click on CS A111 to go to the course home page
- Click on "Submit Assignments" in the left hand
panel
- Select "View/Complete Assignment" for Lab #1
-
Under "Comment" type in something about your lab (e.g. "Here's lab
#1")
- Under "Attach local file" click
"Browse", navigate to the zip file you created,and select it.
- Click Submit. If you click Save, your file will be saved
on the server under your account, but not submitted to me. I can only
view submitted files, so make sure to click Submit when you are
done.
- You are done! You will submit your assignments in the same
manner. Note that your submission will be time stamped and you can come
back later and see your grade. For future labs, you will NOT
need to send your labs in via Blackboard! Instead, flag me down in class
and I will mark you down as completing the lab. You only need to
submit labs via Blackboard if you don't finish them in
class. I only want to check this
first lab to make sure it went through, the proper files were sent,
and that you know how to complete the submission process. All of your
homeworks should be submitted this way.
- If you created any files on the local C: drive, copy them to a floppy or
USB memory drive and delete the files from the C: drive at this time.
Please do not leave files lying around on the C: drive.