In: Computer Science
Write a VB program to provide a health analysis. The higher the point total, the less healthy you are. Input will consist of the user's name, age group, smoker status, weight, sex, blood pressure, and cholesterol readings.
Risk Points are assigned as follows:
Age Group
18 or below0 points
19 - 301 point
31 - 602 points
over 604 points
Smoker?
Yes 5 points
No 0 points
Systolic Blood Pressure?
60 - 139 (Normal) 0 points
140 - 159 (Borderline) 2 points
over 159 (High) 4 points
Diastolic Blood Pressure?
40 - 89 (Normal) 0 points
90 - 94 (Borderline) 2 points
over 94 (High) 4 points
LDL (Bad) Cholesterol
< 110 0 points
110 and up 2 points
HDL (Good) Cholesterol
> 1/5 of Total Cholesterol 0 points
≤ 1/5 of Total Cholesterol 2 points
Weight
Female, over 200 lbs 3 points
Female, 150 - 200 lbs 2 points
Female, < 150 lbs 0 points
Male, over 260 lbs 3 points
Male, 200 - 260 lbs 2 points
Male, < 200 lbs 0 points
A sample user-interface design is attached for your use. Note that the user's name, and cholesterol readings are to be entered into textboxes. The sex and smoking status are entered via radio buttons. The weight and blood pressure (systolic and diastolic) are entered via Numeric UpDown controls. The age group is chosen from a combo box control.
The primary button on your form (Analyze Data) will contain all the code to solve this problem in its Click event procedure. You should also make this event procedure executable by simply pressing the ENTER key when the program runs.
Two other buttons...Quit (to pop up a "Farewell Greeting" message box to the user and stop program execution), and a Clear button (to reset all controls back to original values, and move the cursor back to the "Name" textbox), should also have their click event procedures coded.
Finally, a listbox should be included on your form to output the user's results as follows.
Note:
Total Cholesterol is LDL Cholesterol plus HDL Cholesterol.
Health Status is determined as follows:
Total Points Status
0 - 9Good
10 - 18Average
19 - 24Poor
Programming Notes
1. All code to solve this problem will be written in the "Analyze Data" Click event procedure. Therefore, all variables (meaningful, and properly data-typed) will be declared locally to this event procedure. No global (form-level) variables should be used.
2. The following variables and corresponding data types are suggested (You can add prefixes as needed).
Variable Data Type
namestring
weightinteger
HDLinteger
LDLinteger
TotalCholesterolinteger
SystolicBPinteger
DiastolicBPinteger
SmokePointsinteger
WtPointsinteger
AgePointsinteger
LDL Pointsinteger
HDL Pointsinteger
SystolicPointsinteger
DiastolicPointsinteger
TotalPointsinteger
HealthStatusstring
3. Code OPTION STRICT ON at class level to ensure all variables are properly declared in your program.
4. Use IF statements (single, dual, or multiple alternative, as needed) to determine points from Smoking, Systolic blood pressure, Diastolic blood pressure, HDL Cholesterol, LDL Cholesterol, and weight.
For example, suppose you want to assign points for user's smoking status. You would code the following:
Dim SmokePoints As Integer
If radSmokeYes.Checked = True Then
SmokePoints = 5
Else
SmokePoints = 0
End If
5. Use a Select/Case statement to determine points from the age group of the user.
6. Although you set the min/max for 40/300 for Systolic nud (in the Initial Properties Window), use data validation to ensure that user enters an integer between 60 and 200 inclusive into the Systolic Blood Pressure numeric updown control. If not, display an appropriate error message (via titled, descriptive message box), set insertion point back to Systolic Blood Pressure numeric updown control to allow the user to try again and Exit Sub to prevent further execution without having all the "input data.".
7. Do the same as in Step 6 above but set the min/max for 20/200 for Diastolic nud, for the Diastolic Blood Pressure reading, ensuring the user enters an integer between 40 and 120 inclusive.
I just need help with the coding of the project. Any help would be appreciated :)
hi,
Please find the output below:
when you click on CLear button
when you click on the Quit button
Belwo are the code
Public Class UserControl1
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles gpSex.Enter
End Sub
''Button clear click
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtnamestring.Text = ""
txtHDLCholesterol.Text = ""
txtLDLCholesteorol.Text = ""
txtSystolicBloodPressure.Text = ""
txtDiastolicBloodPressure.Text = ""
txtWeight.ResetText()
cmbAge.Text = ""
rbtnFemale.Checked = False
rbtnMale.Checked = False
rbtnSmokeNo.Checked = False
rbtnSmokerYes.Checked = False
lstBox.Items.Clear()
End Sub
''Button quit click
Private Sub btnQuit_Click(sender As Object, e As EventArgs) Handles btnQuit.Click
MessageBox.Show("Farewell Greeting")
Application.Exit()
End Sub
''Button Analyze data click
Private Sub btnAnalyzeData_Click(sender As Object, e As EventArgs) Handles btnAnalyzeData.Click
Dim namestring = txtnamestring.Text.Trim() ''get the name string
Dim HDLChol = txtHDLCholesterol.Text.Trim() ''get the HDL cholestrol string
Dim LDLChol = txtLDLCholesteorol.Text.Trim() ''get LDL the cholestrol string
'' LDLPointsinteger HDLPointsinteger DiastolicPointsinteger TotalPointsinteger SystolicPointsinteger
Dim SystolicBP = txtSystolicBloodPressure.Value()
Dim DiastolicBP = txtDiastolicBloodPressure.Value()
Dim SmokePointsinteger = rbtnSmokerYes.Checked
Dim Weight = txtWeight.Value()
Dim Age = cmbAge.SelectedItem()
''Check the Age range and add points in integer based on Age
Dim AgePointsinteger As Integer
Select Case Age
Case "18 or below"
AgePointsinteger = 0
Case "19 - 30"
AgePointsinteger = 1
Case "31 - 60"
AgePointsinteger = 2
Case Else
AgePointsinteger = 4
End Select
''Check Smoke radio checked or not and accordigly add the points
Dim SmokePointInteger As Integer
If rbtnSmokerYes.Checked = True Then
SmokePointInteger = 5
Else
SmokePointInteger = 0
End If
''Check the BP Points Systolic range and add the points
Dim SystolicBPPointsInteger As Integer
If SystolicBP >= 60 AndAlso SystolicBP <= 139 Then
SystolicBPPointsInteger = 0
ElseIf SystolicBP >= 140 AndAlso SystolicBP <= 159 Then
SystolicBPPointsInteger = 2
ElseIf SystolicBP > 159 Then
SystolicBPPointsInteger = 4
End If
''Check the BP Points Diastolic range and add the points
Dim DiastolicBPPointsInteger As Integer
If DiastolicBP >= 40 AndAlso DiastolicBP <= 89 Then
DiastolicBPPointsInteger = 0
ElseIf DiastolicBP >= 90 AndAlso DiastolicBP <= 94 Then
DiastolicBPPointsInteger = 2
ElseIf DiastolicBP > 94 Then
DiastolicBPPointsInteger = 4
End If
''Check the LDL Pints based on LDL Chol range and assign value to LDLPintsinteger
Dim LDLPointsinteger As Integer
If LDLChol < 110 Then
LDLPointsinteger = 0
ElseIf LDLChol >= 110 Then
LDLPointsinteger = 2
End If
''Check total chlestroel and calculate the number
Dim TotalCholesterolinteger As Integer = (LDLChol + HDLChol) / 5
Dim HDLPointsinteger As Integer
If TotalCholesterolinteger > HDLChol Then
HDLPointsinteger = 0
ElseIf TotalCholesterolinteger <= HDLChol Then
HDLPointsinteger = 2
End If
''Chck the sex of user and based on that finalize the range and output
Dim sex As Integer
If rbtnMale.Checked Then
sex = 1
Else
sex = 2
End If
''Check che weight based on range and do the calculations
Dim WeightPointsinteger As Integer
If sex = 1 Then
If Weight > 200 Then
WeightPointsinteger = 3
ElseIf Weight >= 150 AndAlso Weight < 200 Then
WeightPointsinteger = 2
ElseIf Weight < 150 Then
WeightPointsinteger = 1
End If
Else
If Weight > 260 Then
WeightPointsinteger = 3
ElseIf Weight >= 200 AndAlso Weight < 260 Then
WeightPointsinteger = 2
ElseIf Weight < 200 Then
WeightPointsinteger = 1
End If
End If
''get the status based on total calories
Dim TotalPointsinteger = AgePointsinteger + SmokePointInteger + SystolicBPPointsInteger + DiastolicBPPointsInteger + LDLPointsinteger + HDLPointsinteger + WeightPointsinteger
Dim sStatus As String
If TotalPointsinteger >= 0 AndAlso TotalPointsinteger <= 9 Then
sStatus = "Good"
ElseIf TotalPointsinteger >= 10 AndAlso TotalPointsinteger <= 18 Then
sStatus = "Average"
Else
sStatus = "Poor"
End If
lstBox.Items.Clear()
lstBox.Items.Add(sStatus)
End Sub
Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Thanks