Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me with this lab on swaps.. thank you. In this lab, you will co

ID: 3772103 • Letter: C

Question

Can someone help me with this lab on swaps.. thank you.

In this lab, you will complete a Visual Basic program that swaps values stored in three Integer variables and determines maximum and minimum values. The Visual Basic file provided for this lab contains the necessary variable declarations, as well as the input and output statements. You want to end up with the smallest value stored in the variable named First and the largest value stored in the variable named Third. You need to write the statements that compare the values and swap them if appropriate. Comments included in the code tell you where to write your statements.

1. Open the source code file named Swap.vb using the text editor of your choice.

2. Write the statements that test the first two integers, and swap them if necessary.

3. Write the statements that test the second and third integer, and swap them if necessary.

4. Write the statements that test the first and second integers again, and swap them if necessary.

5. Save this source code file in a directory of your choice, and then make that directory your working directory.

6. Compile the source code file, Swap.vb.

7. Execute the program using the following sets of input values, and record the output.

101

22

-23

630

1500

9

21

2

2

' Swap.vb - This program determines the minimum and maximum of three values input by
' the user and performs necessary swaps.
' Input: Three integer values.
' Output: The numbers in numerical order.

Option Explicit On
Option Strict On
Module Swap
Sub Main()
   ' Declare variables.
   Dim FirstNumber As String   ' String version of first number.
   Dim SecondNumber As String   ' String version of second number.
   Dim ThirdNumber As String   ' String version of third number.
   Dim First As Integer = 0   ' First number.
   Dim Second As Integer = 0    ' Second number.
   Dim Third As Integer = 0   ' Third number.
   Dim Temp As Integer       ' Used to swap numbers.
          
   ' Get user input.       
   FirstNumber = InputBox$("Enter first number: ")
   SecondNumber = InputBox$("Enter second number: ")
   ThirdNumber = InputBox$("Enter third number: ")
   ' Convert Strings to Integer.
   First = Convert.ToInt32(FirstNumber)
   Second = Convert.ToInt32(SecondNumber)
   Third = Convert.ToInt32(ThirdNumber)
   ' Test to see if the first number is greater than the second number.
  
   ' Test to see if the second number is greater than the third number.
  
   ' Test to see if the first number is greater than the second number again.
  

   ' Print values in numerical order.
   System.Console.WriteLine("Smallest: " & First)
   System.Console.WriteLine("Next largest: " & Second)
   System.Console.WriteLine("Largest: " & Third)

End Sub ' End of Main() procedure.
End Module ' End of Swap module.

101

22

-23

630

1500

9

21

2

2

Explanation / Answer

Option Explicit On
Option Strict On
Module Swap
Sub Main()
   ' Declare variables.
   Dim FirstNumber As String   ' String version of first number.
   Dim SecondNumber As String   ' String version of second number.
   Dim ThirdNumber As String   ' String version of third number.
   Dim First As Integer = 0   ' First number.
   Dim Second As Integer = 0    ' Second number.
   Dim Third As Integer = 0   ' Third number.
   Dim Temp As Integer       ' Used to swap numbers.
          
   ' Get user input.       
   FirstNumber = InputBox$("Enter first number: ")
   SecondNumber = InputBox$("Enter second number: ")
   ThirdNumber = InputBox$("Enter third number: ")
   ' Convert Strings to Integer.
   First = Convert.ToInt32(FirstNumber)
   Second = Convert.ToInt32(SecondNumber)
   Third = Convert.ToInt32(ThirdNumber)
' Test to see if the first number is greater than the second number.
            If First > Second Then
                 Temp = Second
              
                 First = Second
                 Second = Temp
            End If
  
    ' Test to see if the second number is greater than the third number.
        If Second > Third Then
                 Temp = Second
              
                 Second = Third
                 Third = Temp
        End If
  
    ' Test to see if the first number is greater than the second number again.
    If First > Third Then
                 Temp = First
              
                 First = Third
                 Third = Temp
        End If
   
  

   ' Print values in numerical order.
   System.Console.WriteLine("Smallest: " & First)
   System.Console.WriteLine("Next largest: " & Second)
   System.Console.WriteLine("Largest: " & Third)

End Sub ' End of Main() procedure.
End Module ' End of Swap module.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote