Assignment: Design a Visual Basic application for the followinf Assgnment: Most
ID: 3529155 • Letter: A
Question
Assignment: Design a Visual Basic application for the followinf Assgnment: Most calculatorshave an operation called "factorial" which is shown on a calculator key as an exclamation point. For example 5! (5 factorial) multiplies 5*4*3*2*1 to calculate the result of 120. Using loops to compute the factorial, display the following factorials in a ListBox object: 1! 1 2! 2 3! 6 4! 24 5! 120 6! 720 7! 5040 8! 40320 9! Code: ' Program Name: Factorial Calculator ' Author: xxxxxx ' Date: February 26, 2013 ' Purpose: The Factorial Calculator program uses loops ' to calculate the factorial of a number. It ' After all numbers have been entered, it displays ' the factorial for each result. Option Strict Off Public Class frmFactorialCalculator Private Sub btnCompute_Click(sender As System.Object, e As System.EventArgs) Handles btnCompute.Click Dim intNumber As Integer = 0 Dim IntFactorial As Integer = 0 Dim fnGetFactorial As Integer ' Declare and initialize variables Dim strEnterNumber As String Dim decEnterNumber As Decimal Dim decFactorialCalc As Decimal = 0D Dim strInputMessage As String = "Enter the number for factorial calculation #" Dim strInputHeading As String = "Factorial Calculator" Dim strNormalMessage As String = " Enter the number for factorial calculation #" Dim strNonNumericError As String = "Error - Enter the number for factorial calculation #" Dim strNegativeError As String = "Error - Enter a number range between 0 and 170 for factorial calculation" ' Declare and initialize loop variables Dim strCancelClicked As String = "" Dim intMaxNumberOfEntries As Integer = 10 Dim intNumberOfEntries As Integer = 1 strEnterNumber = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ") Do Until intNumberOfEntries > intMaxNumberOfEntries Or strEnterNumber = strCancelClicked If IsNumeric(strEnterNumber) Then decEnterNumber = Convert.ToDecimal(strEnterNumber) If decEnterNumber >= 0 And decEnterNumber <= 170 Then lstFactorialCalc.Items.Add(fnGetFactorial) decFactorialCalc += fnGetFactorial intNumberOfEntries += 1 strInputMessage = strNormalMessage Else strInputMessage = strNegativeError End If Else strInputMessage = strNonNumericError End If If intNumberOfEntries <= intMaxNumberOfEntries Then strEnterNumber = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ") End If Loop Try intNumber = Val(lstFactorialCalc.Text.Trim) IntFactorial = fnGetFactorial lstFactorialCalc.Text = IntFactorial Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 'Factorial Function Codes Private Function fnGetFactorial(ByVal num As Integer) As Integer Dim intfac As Integer = 1 Dim i As Integer For i = 2 To num intfac *= i Next fnGetFactorial = intfac End Function Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click ' This event handler is executed when the user clicks the ' Reset button. It clears the factorial calculator ListBox. lstFactorialCalc.ClearSelected() End Sub Private Sub mnuClearItem_Click(sender As System.Object, e As System.EventArgs) Handles mnuClearItem.Click ' The mnuClear click event clears the ListBox object and hides ' the average speed label. It also enables the Calculate Factorial button lstFactorialCalc.Items.Clear() btnCompute.Enabled = True End Sub Private Sub mnuExit_Click(sender As System.Object, e As System.EventArgs) Handles mnuExit.Click ' The mnuExit click event closes the window and exits the application Close() End Sub End ClassExplanation / Answer
Dim lookupTable(170), returnTable(170), currentPosition, input currentPosition = 0 Do While True input = InputBox("Please type a number (-1 to quit):") MsgBox "The factorial of " & input & " is " & factorial(CDbl(input)) Loop Function factorial (x) If x = -1 Then WScript.Quit 0 End If Dim temp temp = lookup(x) If xRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.