Public Class Form1 'This contains homeworks from pages 257-259 problems 23, 28, 32, 33, 38, 39 'Each problem will be separated by: '-----/////\\\\\----- '-----page.prob ----- '-----\\\\\/////----- 'Created by Zeki Ozyilmaz for CST-112 Instructor: BAM '------------------------------------------------------------------ '/////////Global Declarations\\\\\\\\\\\\\\ Dim sum As Double 'For Question 258.28 Dim s, d, f As String ' For use with instructions!!! '------------------------------------------------------------------ '-----/////\\\\\----- '----- 257.23 ----- 'Creates a table from -40 degrees celsius to 40 celsius and converts them the fahrenheit '-----\\\\\/////----- Private Sub B23table_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B23table.Click 'Step0. Declarations (none) 'Step1. Input (none) 'Step2. Process table23() prob23() 'Step3. Output -Output is done through a sub in Process so none for this End Sub Function ctf(ByVal c As Double) 'formula for converting celsius to Fahrenheit Dim f As Double f = ((9 / 7) * c) + 32 Return f End Function Sub table23() 'top part of table, clears the list of other data Dim fmttbl As String = "{0,-10}{1,2}{2,15}" With Loutput.Items .Clear() .Add(String.Format(fmttbl, "Celsius", "to", "Fahrenheit")) End With End Sub Sub prob23() 'main process of this problem, loops use of formula from -40 cels to 40 cels and outputs each 5 increments Dim c, f As Double c = -40 Do f = ctf(c) output23(c, f) c += 5 Loop Until c = 45 End Sub Sub output23(ByVal c As Double, ByVal f As Double) 'formats output to loutput Dim fmttbl As String = "{0,-10}{1,2}{2,15:N1}" Loutput.Items.Add(String.Format(fmttbl, c, " ", f)) End Sub '-----/////\\\\\----- '----- 258.28 ----- 'Requests the user to input one positive value at a time then enter -1 to see them sum '-----\\\\\/////----- 'which then will output Private Sub B28AS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B28AS.Click 'Step0. Declarations Dim a As Double 'Step1. Input a = getinput28() 'Step2. Process checkinput(a) 'Step3. Output -output is done through the checkinput sub End Sub Function getinput28() 'Gets the number in the text box Dim a As Double = TInput28.Text Return a End Function Sub checkinput(ByVal a As Double) 'Checks what is entered into the box, is negative and not -1 then nothing happens, if positive, adds to sum _ ' if -1 then outputs the sum If a > 0 Then sum += a ElseIf a = -1 Then output28(sum) End If End Sub Sub output28(ByVal x As Double) 'Outputs the sum With Loutput.Items .Clear() .Add("The sum of the numbers you ") .Add("have entered is " & x) End With End Sub '-----/////\\\\\----- '-----| 258.32 |----- 'Solves how many years it takes for savings to get depleted if _ '-----\\\\\/////----- '$15,000 + 5% yearly interest - $1000 per year Private Sub B32Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B32Calc.Click 'Step0. Declarations Dim years As Integer 'Step1. Input - none 'Step2. Process years = calc32() 'Step3. Output output32(years) End Sub Function calc32() 'Calcs the amount of years it takes to get from $15000 to $0 or less using formula 'x = (x * 1.05) - 1000 Dim years As Integer, x As Double x = 15000 Do x = (x * 1.05) - 1000 years += 1 Loop Until x <= 0 Return years End Function Sub output32(ByVal years As Double) 'outputs the amount of years it takes If years > 1 Then With Loutput.Items .Clear() .Add("It will take " & years & " years to deplete the account") End With ElseIf years <= 1 Then With Loutput.Items .Clear() .Add("It will take " & years & " year to deplete the account") End With End If End Sub '-----/////\\\\\----- '-----| 258.33 |----- 'Same as 258.32 except user inputs data instead of having a base $15,000 '-----\\\\\/////----- Private Sub B33Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B33Calc.Click 'Step0. Declarations Dim years As Integer, savings As Double 'Step1. Input savings = input33() 'Step2. Process If savings >= 20000 Or savings <= 0 Then 'If over $20000, then it'll never empty, $0 or less, you owe/dont have anything output33(savings) Else 'If anything else, it'll eventually empty, even if its 19999.99 years = calc33(savings) End If 'Step3. Output If years > 0 Then 'Used so it doesnt output the $20000 exception output32(years) 're-uses output from 32 since it works with this problem without changing anything End If End Sub Function input33() ' Gets intput from tinput33 to use in calculations Dim savings As Double If TInput33.Text = "" Then 'Checks if user inputed any data! savings = 0 Else savings = TInput33.Text 'If uer inputed data then this is used End If Return savings End Function Function calc33(ByVal savings As Double) 'Main process, calculates how many years it'll take to empty the bank if theres an amount Dim years As Integer Do savings = (savings * 1.05) - 1000 years += 1 Loop Until savings <= 0 Return years End Function 'There isn't any return value needed Sub output33(ByVal savings As Double) 'Outputs saying if the savings acount will always have money in it or if you don't _ 'have money in the bank or you owe the bank money If savings > 20000 Then 'You'll never run out of money With Loutput.Items .Clear() .Add("There will always be some amount") .Add(" of money in the bank!") End With ElseIf savings = 0 Then 'You have no money in the bank With Loutput.Items .Clear() .Add("You don't have any money in the bank!!!") End With Else 'you owe the bank money! (user inputs a negative number) With Loutput.Items .Clear() .Add("You owe the bank " & FormatCurrency(savings) & "!!!") End With End If End Sub '-----/////\\\\\----- '-----| 259.38 |----- ' User inputs a positive number greater then 1 and program checks if it is prime '-----\\\\\/////----- Private Sub B38find_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B38find.Click 'Step0. Declarations Dim num As Double, prime As Boolean 'Step1. Input num = getnum() 'Step2. Process prime = checkprime(num) 'Step3. Output outputnotprime38(num, prime) End Sub Function getnum() Dim num As Double = Tinput38.Text 'If TInput28.Text = "" Then 'num = 0 'Else 'num = TInput28.Text 'End If Return num End Function Function checkprime(ByVal num As Double) 'Dim X As Boolean = False 'For j As Double = 1 To (num - 1) 'X = num Mod j = 0 'Next 'If X = True Then 'Return (num & " is a prime number") 'End If 'Return (num & " is not a prime number") Dim f As Double = 1 Dim prime As Boolean prime = True Loutput.Items.Clear() Do f += 1 If num Mod f = 0 Then prime = False Else prime = True End If Loop Until (prime = False Or prime = True) And num <= f Return prime End Function Sub outputnotprime38(ByVal num As Double, ByVal prime As Boolean) If prime = True Then Loutput.Items.Add(num & " is prime") ElseIf prime = False Then Loutput.Items.Add(num & " is not prime") End If End Sub ''---------------------------'Have to finish above ^'-----------------------------------'' '-----/////\\\\\----- '----- 259.39 ----- 'finds the greatest common divisor of the two numbers inputed by the user '-----\\\\\/////----- Private Sub B39calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B39calc.Click 'Step0. Declarations Dim a, b, x As Integer 'Step1. Input a = get39a() 'gets the first value entered b = get39b() 'gets the second value entered 'Step2. Process x = greatcomdiv(a, b) 'finds the greatest common divisor 'Step3. Output output39(x) 'outputs the greatest common divisor End Sub Function get39a() Dim a As Integer = Ta39.Text 'gets the first value from the first input box Return a End Function Function get39b() Dim b As Integer = Tb39.Text 'gets the second value from the first input box Return b End Function Function greatcomdiv(ByVal a As Double, ByVal b As Double) Dim x As Integer Do Until b = 0 x = b b = a Mod b a = x Loop Return a End Function Sub output39(ByVal x As Integer) With Loutput.Items .Clear() .Add(x) End With End Sub '-------------------------------------------------------------------------------' 'Below this is just items added to give some effect to the program, These just_ 'turn on the visible true/false for the selected problem. Private Sub Bhw23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw23.Click 'makes the instructions/button appear for problem 23 s = "Just press the button to get the table!" d = " " f = " " say(s, d, f) TInput28.Visible = False TInput33.Visible = False Tinput38.Visible = False Ta39.Visible = False Tb39.Visible = False B23table.Visible = True B28AS.Visible = False B32Calc.Visible = False B33Calc.Visible = False B38find.Visible = False B39calc.Visible = False Loutput.Items.Clear() End Sub Private Sub Bhw28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw28.Click 'makes the instructions/button appear for problem 28 s = "Enter any number one at a time." d = "When you are done, enter -1 into the text field and click the button." f = "Once you have done that, the numbers entered will be calculated except for the -1." say(s, d, f) TInput28.Visible = True TInput33.Visible = False Tinput38.Visible = False Ta39.Visible = False Tb39.Visible = False B23table.Visible = False B28AS.Visible = True B32Calc.Visible = False B33Calc.Visible = False B38find.Visible = False B39calc.Visible = False Loutput.Items.Clear() End Sub Private Sub Bhw32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw32.Click 'makes the instructions/button apprear for Problem 32 s = "Click the button to determine when $15,000 will be depleted in a savings account when, " d = "the account pays 5% interest and $1000 is withdrawn at the end of each year." f = " " say(s, d, f) TInput28.Visible = False TInput33.Visible = False Tinput38.Visible = False Ta39.Visible = False Tb39.Visible = False B23table.Visible = False B28AS.Visible = False B32Calc.Visible = True B33Calc.Visible = False B38find.Visible = False B39calc.Visible = False Loutput.Items.Clear() End Sub Private Sub Bhw33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw33.Click 'makes the instructions/button apprear for Problem 33 s = "Click the button to determine when the amount you have entered in the text field " d = "will be depleted in a savings account when the account pays 5% interest and $1000" f = "is withdrawn at the end of each year." say(s, d, f) TInput28.Visible = False TInput33.Visible = True Tinput38.Visible = False Ta39.Visible = False Tb39.Visible = False B23table.Visible = False B28AS.Visible = False B32Calc.Visible = False B33Calc.Visible = True B38find.Visible = False B39calc.Visible = False Loutput.Items.Clear() End Sub Private Sub Bhw38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw38.Click 'makes the instructions/button apprear for Problem 38 s = "Enter a whole number greater then 1 to figure out if the number is prime or not" d = " " f = " " say(s, d, f) TInput28.Visible = False TInput33.Visible = False Tinput38.Visible = True Ta39.Visible = False Tb39.Visible = False B23table.Visible = False B28AS.Visible = False B32Calc.Visible = False B33Calc.Visible = False B38find.Visible = True B39calc.Visible = False Loutput.Items.Clear() End Sub Private Sub Bhw39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bhw39.Click 'makes the instructions/button apprear for Problem 39 s = "Enter two numbers in the text field to find the greatest common divisor between" d = "the two." f = " " say(s, d, f) TInput28.Visible = False TInput33.Visible = False Tinput38.Visible = False Ta39.Visible = True Tb39.Visible = True B23table.Visible = False B28AS.Visible = False B32Calc.Visible = False B33Calc.Visible = False B38find.Visible = False B39calc.Visible = True Loutput.Items.Clear() End Sub Sub say(ByVal s As String, ByVal d As String, ByVal f As String) With LInstructions.Items .Clear() .Add(s) .Add(d) .Add(f) End With End Sub End Class