嗨,我被分配了一项家庭作业来创建以下程序: 手机公司 Cell4U 确定他们的手机费用如下:客户为整分钟的通话支付 R2.05,每多出一秒支付 2c。他们还为每条短信支付 40 美分,但客户每满 30 分钟通话可获得 2 条免费短信。每发送 30 条短信,客户还可免费获得 1 条短信。
为公司工作的所有员工都会获得一部免费手机作为福利,他们的账户每月最多可支付 R800 兰特。该公司要求每月报告所有员工的手机账单以及他们在员工手机津贴上花费的总金额。
该计划必须提供以下内容:
• 呼叫到期金额和短信到期金额必须在子过程中计算。这必然意味着子程序必须将秒转换为分钟和秒,并且这些值以及空闲短信的数量也可用于主程序。• 必须调用第二个子程序来计算员工的总账单并累计公司需要为手机津贴支付的总金额。此子程序还必须使用布尔参数向主程序指示公司是否将支付该员工的全部金额或仅支付 R800。• 所有输出必须显示在主程序中(按钮单击事件)。• 任意数量的员工。一个空的员工编号将表示输入的结束(或者用户可以单击输入框中的取消按钮)。输入最后一个数据后,总金额必须如图 5 所示显示。请记住,如果帐户超过 R800,则公司仅向账单贡献 R800,并且总额中必须反映 R800。
我已经编写了以下代码,但返回的值为零
Option Strict On
Option Explicit On
Public Class TheCellPhoneCompany
Private Sub CalcMinAndSec(ByVal intLengthCallInSec As Integer, ByVal intCallSec As Integer, ByVal intCallMin As Integer, ByVal intNumMsgs As Integer, ByVal intNumFreeMsgs As Integer, ByVal decCallCost As Decimal, _
ByVal decSmsCost As Decimal, ByVal RatePerMin As Decimal, ByVal RatePerSec As Decimal, ByVal RatePerSms As Decimal)
intCallMin = (intLengthCallInSec \ 60I)
intCallSec = ((intLengthCallInSec Mod 60I))
intNumFreeMsgs = ((intCallMin - (intCallMin Mod 30)) \ 15) + ((intNumMsgs - (intNumMsgs Mod 30I) \ 30I))
decCallCost = (intCallMin * RatePerMin) + (intCallSec * RatePerSec)
decSmsCost = (intNumMsgs - intNumFreeMsgs) * RatePerSms
End Sub
Private Sub CalcTotals(ByVal decCallCost As Decimal, ByVal decSmsCost As Decimal, ByVal decTotCost As Decimal, ByVal decAmtPaid As Decimal, ByVal decFinalAmtPaid As Decimal, ByVal PaidByComp As Decimal)
Dim blnPaidByComp As Boolean = decTotCost > 800I
decTotCost = decCallCost + decSmsCost
If blnPaidByComp = True Then
decAmtPaid = PaidByComp
Else
decAmtPaid = decTotCost
End If
decFinalAmtPaid += decAmtPaid
End Sub
Private Sub btnEnterData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterData.Click
Dim strEmpCode, strLengthCallInSec, strNumOfSms As String
Dim intNumMsgs, intNumFreeMsgs, intCallMin, intCallSec, intEmpCode, intLengthCallInSec As Integer
Dim decCallCost, decSmsCost, decTotCost, decAmtPaid, decFinalAmtPaid As Decimal
Dim intEmpNum As Integer = 1
Const RatePerMin As Decimal = 2.05D
Const RatePerSec As Decimal = 0.02D
Const RatePerSms As Decimal = 0.4D
Const PaidByComp As Decimal = 800D
Do
strEmpCode = InputBox("Please enter employee number", "Employee " & intEmpNum)
Integer.TryParse(strEmpCode, intEmpCode)
If intEmpCode <> 0 Then
strLengthCallInSec = InputBox("Enter total calls for the month in seconds", "Employee " & intEmpNum)
Integer.TryParse(strLengthCallInSec, intLengthCallInSec)
If intLengthCallInSec > 0 Then
strNumOfSms = InputBox("Enter total number of SMS's sent for the month", "Employee " & intEmpNum)
Integer.TryParse(strNumOfSms, intNumMsgs)
If intNumMsgs > 0 Then
Else
MessageBox.Show("Invalid value - the number of SMS's must be a positive integer", "Error - please correct", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
Else
MessageBox.Show("Invalid value - the seconds must be a positive integer", "Error - please correct", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
Else
End If
Call CalcMinAndSec(intLengthCallInSec, intCallSec, intCallMin, intNumMsgs, intNumFreeMsgs, decCallCost, decSmsCost, RatePerMin, RatePerSec, RatePerSms)
Call CalcTotals(decCallCost, decSmsCost, decTotCost, decAmtPaid, decFinalAmtPaid, PaidByComp)
lstCellPhones.Items.Add("Employee: " & intEmpCode)
lstCellPhones.Items.Add("Calls: " & intCallMin & " minutes and " & intCallSec & " seconds")
lstCellPhones.Items.Add("Number of SMS messages: " & intNumMsgs & " (" & intNumFreeMsgs & ")")
lstCellPhones.Items.Add("Cost for calls: R" & decCallCost.ToString("N2"))
lstCellPhones.Items.Add("Cost for sms messages: R" & decSmsCost.ToString("N2"))
lstCellPhones.Items.Add("Total cost: R" & decTotCost.ToString("N2"))
lstCellPhones.Items.Add("Paid by company: R" & decAmtPaid.ToString("N2"))
lstCellPhones.Items.Add("")
intEmpNum = intEmpNum + 1
Loop Until intEmpCode = 0
lstCellPhones.Items.Add("Total amount paid by company for cell phones = R" & decFinalAmtPaid.ToString("N2"))
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstCellPhones.Items.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class