A Program Which Prints Time In Words
Sample Code
Task
Write your own program which prints the time in words for the input given in the format mentioned above. Print 9 time outputs; 3 for morning, 3 for afternoon and 3 for night
Input Format
There will be two lines of input:
Sample Input
5
47
Sample Output: thirteen minutes to six
Imports System.DateTime
Imports System.Math
Public Class TimeReader
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
lbReader.Text = "Time in Word" :
txtmm.Text = ""
txthh.Text = "" :
lbReader.Visible = False
End Sub
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnReader_Click(sender As Object, e As EventArgs) Handles btnReader.Click
If Not (IsNumeric(txthh.Text) And IsNumeric(txtmm.Text)) Then
Dim a = MessageBox.Show("Please enter
a numeric value", "Hampo JohnPaul||Audax", MessageBoxButtons.OK, MessageBoxIcon.Error)
If a = Windows.Forms.DialogResult.OK Then btnReset.PerformClick()
Else
If Val(txthh.Text) <= 24 Then
If Val(txtmm.Text) > 60 Then
Dim a = MessageBox.Show("Your minutes should be between 1 to 60", "Hampo
JohnPaul||Audax", MessageBoxButtons.OK, MessageBoxIcon.Information)
If a = Windows.Forms.DialogResult.OK Then btnReset.PerformClick()
Else
Dim ones() As String = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}
Dim teens() As String = {"", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}
Dim tens() As String = {"", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty"}
Dim Condition As String = ""
If (Val(txtmm.Text) >= 0 And Val(txtmm.Text) <= 30) Then
Condition = "After"
ElseIf (Val(txtmm.Text)
> 30 And
Val(txtmm.Text) <= 60) Then
Condition = "To"
End If
Dim DaySign As String = ""
If Val(txthh.Text) < 12 Then
DaySign = "Am"
ElseIf (Val(txthh.Text)
>= 12 And
Val(txthh.Text) <= 24) Then
DaySign = "Pm"
Else
End If
Dim myHours = 0 : Dim wHours As String = ""
Dim myMinutes = 0 : Dim wMinutes As String = ""
If Condition = "After" Then
myMinutes =
Val(txtmm.Text)
Else
myMinutes = 60 -
Val(txtmm.Text)
myHours =
Val(txthh.Text) + 1
End If
If DaySign = "Am" And Condition = "After" Then
myHours =
Val(txthh.Text)
ElseIf DaySign = "Pm" And Condition = "To" Then
myHours =
Val(txthh.Text + 1) - 12
ElseIf DaySign = "Pm" And Condition = "After" Then
myHours =
Val(txthh.Text) - 12
ElseIf DaySign = "Pm" Then
myHours =
Val(txthh.Text + 1) - 12
End If
Dim hTens As Integer = myHours \ 10 :
myHours = myHours Mod 10
Dim hOnes As Integer = myHours \ 1
Dim mTens As Integer = myMinutes \ 10 :
myMinutes = myMinutes Mod 10
Dim mOnes As Integer = myMinutes \ 1
If hTens > 0 Then
If hTens = 1 Then
wHours = wHours
& teens(hOnes) & " "
Else
wHours = wHours
& tens(hTens) & IIf(hOnes > 0, "-", " ")
If hOnes > 0 Then wHours = wHours &
ones(hOnes) & " "
End If
Else
If hOnes > 0 Then
wHours = wHours
& ones(hOnes)
End If
End If
If mTens > 0 Then
If mTens = 1 Then
wMinutes = wMinutes
& teens(mOnes) & " "
Else
wMinutes = wMinutes
& tens(mTens) & IIf(mOnes > 0, "-", " ")
If mOnes > 0 Then wMinutes = wMinutes &
ones(mOnes) & " "
End If
Else
If mOnes > 0 Then
wMinutes = wMinutes & ones(mOnes)
End If
End If
lbReader.Text = wMinutes + " " + "minutes " +
Condition + " " + wHours + "
(" + DaySign + ")"
lbReader.Visible = True
End If
Else
Dim a = MessageBox.Show("Your hour
should be between 1 to 24", "Hampo JohnPaul||Audax", MessageBoxButtons.OK, MessageBoxIcon.Information)
If a = Windows.Forms.DialogResult.OK Then btnReset.PerformClick()
End If
End If
End Sub
End ClassTask
Write your own program which prints the time in words for the input given in the format mentioned above. Print 9 time outputs; 3 for morning, 3 for afternoon and 3 for night
Input Format
There will be two lines of input:
H, representing the hours
M, representing the minutes
Constraints:
1 < H
< 12
0 < M
< 60
Sample Input
47
Sample Output: thirteen minutes to six
Comments
Post a Comment