HI, A detailed solution on how to complete Programming challenge number 6 from c
ID: 674090 • Letter: H
Question
HI, A detailed solution on how to complete Programming challenge number 6 from chapter 6 in Starting out with visual basic 2012 would be great. Thank you!
Create an application that calculates and displays the total travel expenses for a business trip. The user must provide the following information
Number of days on the trip
Amount of airfare, if any
Amount of car rental fees, if any
Number of miles driven, if a private vehicle was used
Amount of parking fees, if any
Amount of Taxi charges, if any
Conference or seminar registration fees, if any
Lodging charges, per night
The company reimburses travel expenses according to the following policy:
$37.00 per day for meals
parking fees, up to $10.00 per day
Taxi charges up to $20.00 per day
Lodging charges up to $95.00 per day
If a private vehicle is used, $0.27 per mile driven
The application should calculate and display the following:
Total expenses incurred by the business person
The total allowable expenses for the trip
The excess that must be paid by the business person, if any
The amount saved by the business person if the expenses were under the total allowed
The application should have the following functions:
CalcMeals: Calculates and returns the amount reimbursed for meals
CalcMileage: Calculates and returns the amount reimbursed for mileage driven in a private vehicle
CalcParkingFees: Calculates and returns the amount reimbursed for parking fees.
CalcTaxiFees: Calculates and returns the amount reimbursed for taxi charges
CalcLodging: Calculates and returns the amount reimbursed for lodging.
CalcTotalReimbursement: Calculates and returns the total amount reimbursed
CalcUnallowed: Calculates and returns the total amount of expenses that are not allowable, if any. These are parking fees that exceed $10.00 per day, taxi charges that exceed $20.00 per day and lodging charges that exceed $95.00 per day.
CalcSaved: Calculates and returns the total amount of expenses under the allowable amount, if any. For example, the allowable amount for lodging is $95.00 per day. If a business person stayed in a hotel for $85.00 per day for five days, the savings would be $50.00.
Input validation: Do not accept negative numbers for any dollar amount or for miles driven in a private vehicle. Do not accept numbers less than 1 for the number of days.
Here are the Variables, Constants and Pseudo code:
Constants declared at the Form level
' Class-level constants
Const intMIN_DAYS As Integer = 1 ' Minimum number of days of the trip is 1.
Const decMEALS_PER_DAY As Decimal = 37D ' Reimbursement for meals each day is $37.00
Const decPARKING_PER_DAY As Decimal = 10D ' Reimbursement for parking each day is $10.00
Const decTAXI_PER_DAY As Decimal = 20D ' Reimbursement for taxi each day is $20.00
Const decLODGING_PER_DAY As Decimal = 95D ' Reimbursement for lodging each day is $95.00
Const decCENTS_PER_MILE As Decimal = 0.27D ' Reimbursement per mile driven is $0.27
Local variables in the btnCalculate_Click procedure
Dim intDays As Integer = 0 ' To hold the number of days of the trip
Dim intMiles As Integer = 0 ' To hold the number of miles driven in a private vehicle
Dim decAirfare As Decimal = 0D ' To hold the amount of airfare
Dim decCarRental As Decimal = 0D ' To hold the amount of car rental fees
Dim decParking As Decimal = 0D ' To hold the amount of parking fees
Dim decTaxi As Decimal = 0D ' To hold the amount of taxi charges
Dim decRegistration As Decimal = 0D ' To hold the conference or seminar registration fees
Dim decLodging As Decimal = 0D ' To hold the lodging charges per night
Dim decMeals As Decimal = 0D ' To hold the amount charged for meals
Dim decMilesReimbursed As Decimal ' To hold the amount reimbursed for miles driven in a private vehicle
Dim decParkingReimbursed As Decimal ' To hold the amount reimbursed for parking fees
Dim decTaxiReimbursed As Decimal ' To hold the amount reimbursed for taxi charges
Dim decLodgingReimbursed As Decimal ' To hold the amount reimbursed for lodging
Dim decMealsReimbursed As Decimal ' To hold the amount reimbursed for meals
Dim decParkingSavings As Decimal ' To hold the amount saved on parking fees
Dim decTaxiSavings As Decimal ' To hold the amount saved on taxi charges
Dim decLodgingSavings As Decimal ' To hold the amount saved on lodging
Dim decMealsSavings As Decimal ' To hold the amount saved on meals
Dim decParkingExcess As Decimal ' To hold the amount exceeded on parking fees
Dim decTaxiExcess As Decimal ' To hold the amount exceeded on taxi charges
Dim decLodgingExcess As Decimal ' To hold the amount exceeded on lodging
Dim decMealsExcess As Decimal ' To hold the amount exceeded on meals
Dim decExpenses As Decimal = 0D ' To hold the total expenses incurred
Dim decReimbursements As Decimal = 0D ' To hold the total allowable expenses for the trip
Dim decExceedings As Decimal = 0D ' To hold the excess that must be paid
Dim decSavings As Decimal = 0D ' To hold the amount saved if the expenses were under the total
Calculate Event Pseudocode
If Travel Days is a number and meets the minimum number required Then
If Private Vehicle Miles is Empty or value is a positive whole number Then
If Airfare is Empty or value is a positive real number Then
If Car Rental Fees is Empty or value is a positive real number Then
If Parking Fees is Empty or value is a positive real number Then
If Taxi Charges is Empty or value is a positive real number Then
If Registration Fees is Empty or value is a positive real number Then
If Lodging Per Night is Empty or value is a positive real number Then
If Meals is Empty or value is a positive real number Then
Calculate reimbursement for each reimbursable expense (using following functions)
CalcMeals(Travel Days, Meals)
CalcParkingFees(Travel Days, Parking Fees)
CalcTaxiFees(Travel Days, Taxi Charges)
CalcLodging(Travel Days, Lodging Per Night)
CalcMileage(Private Vehicle Miles)
Calculate savings for each reimbursable expense (possibly using following functions)
CalcMealsSavings(Travel Days, Meals)
CalcParkingSavings(Travel Days, Parking Fees)
CalcTaxiSavings(Travel Days, Taxi Charges)
CalcLodgingSavings(Travel Days, Lodging Per Night)
Calculate excess spending for each reimbursable expense (possibly using functions)
CalcMealsUnallowed(Travel Days, Meals)
CalcParkingUnallowed(Travel Days, Parking Fees)
CalcTaxiUnallowed(Travel Days, Taxi Charges)
CalcLodgingUnallowed(Travel Days, Lodging Per Night)
Calculate the total of all expenses incurred by the business person
Calculate the total amount to be reimbursed for reimbursable expenses (using following function)
CalcTotalReimbursement(Meals Reimbursed, Private Vehicle Miles Reimbursed, Parking Fees Reimbursed, Taxi Charges Reimbursed, Lodging Per Night Reimbursed)
Calculate the total amount of excess spending for reimbursable expenses (using following function)
CalcUnallowed(Meals Excess, Parking Excess, Taxi Excess, Lodging Excess)
Calculate the total amount of savings for reimbursable expenses (using following function)
CalcSaved(Meals Savings, Parking Savings, Taxi Savings, Lodging Savings)
Display the information as output to the user
Else
Display a message to the user indicating that the amount for meals is invalid
End If
Else
Display a message to the user indicating that the amount for lodging charges is invalid
End If
Else
Display a message to the user indicating that the amount of registration fees is invalid
End If
Else
Display a message to the user indicating that the amount of the taxi charges is invalid
End If
Else
Display a message to the user indicating that the amount of parking fees is invalid
End If
Else
Display a message to the user indicating that the amount of car rental fees is invalid
End If
Else
Display a message to the user indicating that the amount of airfare is invalid
End If
Else
Display a message to the user indicating that the number of miles driven is invalid
End If
Else
Display a message to the user indicating that the number of days of the trip is invalid
End If
Travel Expenses Calculator Information Summary Travel Daya Pivate Vehicle Mles Expenses Reimbursements: Enceedng: Savings Car Rental Fees $ .. Parking Fees $ Tasa Charges ! Registraton Fees $ Lodging per Night $ Meals CleaExplanation / Answer
Answer:
Note: code modified as per the instructions provided.
Vb.net code:
Public Class Form1
Inherits System.Windows.Forms.Form
Const decReMeals As Decimal = 37.0
Const decReParkFees As Decimal = 10.0
Const decReTaxi As Decimal = 20.0
Const decReLodge As Decimal = 95.0
Const decReMiles As Decimal = 0.27
Dim miles As Decimal
'Const decReTotal As Decimal = decReMeals + decReParkFees + decReTaxi + decReLodge + decReMiles
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intNumberOfDays As Integer
Dim decAirFare As Decimal
Dim decCarRent As Decimal
Dim decMiles As Decimal
Dim decParkFees As Decimal
Dim decTaxi As Decimal
Dim decSemReg As Decimal
Dim decLodge As Decimal
Dim decTotalInc As Decimal
Dim decTotalRe As Decimal
Dim decSaved As Decimal
Dim decTotalExc As Decimal
Try
intNumberOfDays = CInt(CInt(txtNumberOfDays.Text) >= 1)
Catch ex As Exception
MessageBox.Show("Number of days cannot be less than 1.")
Return
End Try
Try
decAirFare = CDec(CDec(txtAirFare.Text) >= 0)
decCarRent = CDec(CDec(txtCarRent.Text) >= 0)
decMiles = CDec(CDec(txtMiles.Text) >= 0)
decParkFees = CDec(CDec(txtParkFees.Text) >= 0)
decTaxi = CDec(CDec(txtTaxi.Text) >= 0)
decSemReg = CDec(CDec(txtSemReg.Text) >= 0)
decLodge = CDec(CDec(txtLodge.Text) >= 0)
Catch ex As Exception
MessageBox.Show("Input amounts cannot be less than zero." & " Please enter a zero for any empty fields.", "Imput Error")
Return
End Try
miles = CDec(txtMiles.Text)
Dim totalMilescost As Decimal = miles * decReMiles
decTotalInc = CDec(CDec(txtAirFare.Text) + CDec(txtCarRent.Text) + CDec(txtParkFees.Text) + CDec(txtTaxi.Text) + CDec(txtSemReg.Text) + CDec(txtLodge.Text) + CDec(txtMeals.Text) + totalMilescost.ToString)
txtTotalInc.Text = FormatCurrency(decTotalInc.ToString)
decTotalRe = CalcTotalReimbursement()
txtTotalRe.Text = FormatCurrency(decTotalRe.ToString("c"))
decTotalExc = CalcUnallowed()
txtTotalExc.Text = FormatCurrency(decTotalExc.ToString("c"))
decSaved = CalcSaved(decTotalRe)
txtTotalSav.Text = FormatCurrency(decSaved.ToString)
End Sub
Function CalcMeals(ByRef decReMeals As Decimal) As Decimal
Dim decMealsRe As Decimal
decMealsRe = CDec(txtNumberOfDays.Text) * decReMeals
Return decMealsRe
End Function
Function CalcMileage(ByRef decReMiles) As Decimal
Dim decMilesRe As Decimal
decMilesRe = CDec(txtMiles.Text) * decReMiles
Return decMilesRe
End Function
Function CalcParkingFees(ByRef decReParkFees) As Decimal
Dim decParkFeesRe As Decimal
decParkFeesRe = CDec(txtNumberOfDays.Text) * decReParkFees
Return decParkFeesRe
End Function
Function CalcTaxiFees(ByRef decReTaxi) As Decimal
Dim decTaxiFeesRe As Decimal
decTaxiFeesRe = CDec(txtNumberOfDays.Text) * decReTaxi
Return decTaxiFeesRe
End Function
Function CalcLodging(ByRef decReLodge) As Decimal
Dim decLodgingRe As Decimal
decLodgingRe = CDec(txtNumberOfDays.Text) * decReLodge
Return decLodgingRe
End Function
Function CalcTotalReimbursement() As Decimal
Dim decTotalRe As Decimal
Dim decMealsRe As Decimal
Dim decMilesRe As Decimal
Dim decParkFeesRe As Decimal
Dim decTaxiFeesRe As Decimal
Dim decLodgingRe As Decimal
decMealsRe = CalcMeals(decReMeals)
decMilesRe = CalcMileage(decReMiles)
decParkFeesRe = CalcParkingFees(decReParkFees)
decTaxiFeesRe = CalcTaxiFees(decReTaxi)
decLodgingRe = CalcLodging(decReLodge)
decTotalRe = decMealsRe + decMilesRe + decParkFeesRe + decTaxiFeesRe + decLodgingRe
txtTotalRe.Text = FormatCurrency(decTotalRe)
Return decTotalRe
End Function
Function CalcUnallowed() As Decimal
Dim decTotalExc As Decimal
Dim decTotalInc As Decimal
Dim decTotalRe As Decimal
decTotalExc = decTotalInc - decTotalRe
txtTotalExc.Text = FormatCurrency(decTotalExc.ToString)
Return decTotalExc
End Function
Function CalcSaved(ByRef decTotalRe As Decimal) As Decimal
Dim decSaved As Decimal
Dim decTotalAll As Decimal
decSaved = decTotalRe - decTotalAll
Return decSaved
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtNumberOfDays.Clear()
txtAirFare.Clear()
txtCarRent.Clear()
txtMeals.Clear()
txtLodge.Clear()
txtMiles.Clear()
txtParkFees.Clear()
txtSemReg.Clear()
txtTaxi.Clear()
txtTotalInc.Text = String.Empty
txtTotalRe.Text = String.Empty
txtTotalExc.Text = String.Empty
txtTotalSav.Text = String.Empty
txtNumberOfDays.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.