Professional Documents
Culture Documents
KJNKN
KJNKN
CODE:!
!
Module Module1!
!
Sub Main()!
!
!
!
!
!
End Sub!
!
Sub S0(ByVal input, ByVal position, ByRef answer, ByRef state)!
!
If Mid(input, position, 1) = 0 Then!
!
answer = "0" + answer!
!
ElseIf Mid(input, position, 1) = 1 Then!
!
!
!
!
End If!
Atharva
End Sub!
!
Sub S1(ByVal input, ByVal position, ByRef answer, ByVal state)!
!
If Mid(input, position, 1) = 0 Then!
!
answer = "1" + answer!
!
ElseIf Mid(input, position, 1) = 1 Then!
!
answer = "0" + answer!
!
End If!
!
End Sub!
!
!
End Module!
!
!
TESTING:!
Input!
Output
00010011
11101101
00010100
11101100
00010010
11101110
!
2. Vending Machine!
!
FINITE STATE MACHINE:!
Atharva
CODE:!
!
Module Module1!
!
Sub Main()!
!
!
!
!
!
Loop Until state > 49!
!
!
Console.ReadLine()!
!
End Sub!
!
Sub validate(ByRef input)!
!
Do While input <> 10 And input <> 20 And input <> 50!
Console.WriteLine("Please enter a 10, 20 or 50 coin")!
input = Console.ReadLine()!
!
Loop!
!
End Sub!
!
Sub choosestate(ByVal input, ByRef total, ByRef state)!
!
!
Atharva
!
!
!
!
End Sub!
!
!
!
!
End Sub!
!
!
End Sub!
!
!
End Sub!
!
!
End Sub!
!
End Module!
!!
!
!!
TESTING:!
!!
!
!
!
!
Input!
Output
10,10,10,10,10
20,20,50
Reject
50
Atharva
3. Parity Bit!
!
!
Module Module1!
!
Sub Main()!
!
CODE:!
!
!
!
!
!
!
!
Atharva
End Sub!
!
Sub S0(ByVal input, ByVal position, ByRef odd)!
!
If Mid(input, position, 1) = "0" Then!
odd = False!
ElseIf Mid(input, position, 1) = "1" Then!
odd = True!
End If!
!
End Sub!
!
Sub S1(ByRef input, ByVal position, ByRef odd)!
!
If Mid(input, position, 1) = "0" Then!
odd = True!
ElseIf Mid(input, position, 1) = "1" Then!
odd = False!
End If!
!
!
End Sub!
!
End Module!
!!
!
TESTING!
Input!
Output
1001
10010
0000
00000
1011
10111
Atharva