'Programming Challenge#1
'Microsoft Small Basic
'Harry Hardjono
'July 2012
'
text1="I'm singing in the rain!"
text2="The quick brown fox jumps over the lazy dog."
text3="a SMALL misfortune"
t1="abcdefghijklmnopqrstuvwxyz"
t2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Tin=text1
UpperLower()
Tin=text2
UpperLower()
Tin=text3
UpperLower()
Tin1=text3
Tin2=text2
Cin="SMALL"
CharIndex()
If Cout="" then
TextWindow.WriteLine("Not found!")
else
TextWindow.WriteLine(Cout)
endif
Tin1=text3
Tin2=text2
Cin="Small"
CharIndex()
If Cout="" then
TextWindow.WriteLine("Not found!")
else
TextWindow.WriteLine(Cout)
endif
Tin=text1
MakeAlpha()
TextWindow.WriteLine(Tout)
Tin=text2
MakeAlpha()
TextWindow.WriteLine(Tout)
Tin=text3
MakeAlpha()
TextWindow.WriteLine(Tout)
Tin=text1
IsPangram()
TextWindow.WriteLine(Tout)
Tin=text2
IsPangram()
TextWindow.WriteLine(Tout)
Tin=text3
IsPangram()
TextWindow.WriteLine(Tout)
Tin1=text1
Tin2="AEIOU"
StringOut()
TextWindow.WriteLine(Tout)
Tin1=text2
Tin2="aeiou"
StringOut()
TextWindow.WriteLine(Tout)
Tin1=text3
Tin2="qwrtypsdfghjklzxcvbmn"
StringOut()
TextWindow.WriteLine(Tout)
Filename=Program.Directory+"\hangman.txt"
FileSlurp()
For i=1 To Array.GetItemCount(FileData)
TextWindow.WriteLine(FileData[i])
endfor
Sub FileSlurp
'Read a file and assign it to an array
'Input Filename (string)
'Output FileData (array)
FileLength=Text.GetLength(File.ReadContents(Filename))
FileData=""
FL=0
FS_i=1
While FL < filelength
FileData[FS_i]=File.ReadLine(Filename,FS_i)
FL=FL+Text.GetLength(FileData[FS_i])+2
If FileData[FS_i]="" Then 'Fudge for blank lines in file
FileData[FS_i]=" "
EndIf
FS_i=FS_i+1
Endwhile
EndSub
Sub UpperLower
TextWindow.WriteLine(Tin)
Text_Lower()
TextWindow.WriteLine(Tout)
Text_Upper()
TextWindow.WriteLine(Tout)
EndSub
Sub Text_Lower
'Make Tin string lowercase
'Input Tin (string)
'Output Tout (string)
Tout=""
For TL_i=1 To Text.GetLength(Tin)
tchar=text.GetSubText(Tin,TL_i,1)
tindx=text.GetIndexOf(t2,tchar)
If tindx>0 Then
tchar=text.GetSubText(t1,tindx,1)
EndIf
Tout=Text.Append(Tout,tchar)
EndFor
EndSub
Sub Text_Upper
'Make Tin string uppercase
'Input Tin (string)
'Output Tout (string)
Tout=""
For TL_i=1 To Text.GetLength(Tin)
tchar=text.GetSubText(Tin,TL_i,1)
tindx=text.GetIndexOf(t1,tchar)
If tindx>0 Then
tchar=text.GetSubText(t2,tindx,1)
EndIf
Tout=Text.Append(Tout,tchar)
EndFor
EndSub
Sub CharIndex
'Given 2 strings and a char, find the corresponding char from location t1 at t2
'return "" if not found. return char/string otherwise
'Input Tin1 = in index string
'Input Tin2 = out index string
'Input Cin = character / string
'Output Cout = character/string
tindx=text.GetIndexOf(Tin1,Cin)
If (tindx=0) Then
Cout=""
Else
Cout=text.GetSubText(Tin2,tindx,text.GetLength(Cin))
EndIf
EndSub
Sub MakeAlpha
'Given a string, pick out all alphabet. Store in UPPERCASE
'Input Tin = string (text)
'Output Tout = string (alphabets)
Tout=""
For MA_i = 1 To Text.GetLength(Tin)
tchar=text.ConvertToUpperCase(text.GetSubText(Tin,MA_i,1))
tindx=text.GetIndexOf(t2,tchar)
If tindx>0 Then
tindx=text.GetIndexOf(Tout,tchar)
If tindx=0 Then
Tout=Text.Append(Tout,tchar)
EndIf
EndIf
EndFor
EndSub
Sub IsPangram
'Given a string, see if all alphabets is represented
'Input Tin = string(text)
'Output Tout = string "TRUE" if yes. "FALSE" if false
Tin1=text.ConvertToUpperCase(Tin)
Tout="TRUE"
For IP_i=1 To Text.GetLength(t2)
tchar=Text.GetSubText(t2,IP_i,1)
tindx=text.GetIndexOf(Tin1,tchar)
If (tindx=0) Then
Tout="FALSE"
EndIf
EndFor
EndSub
Sub CharOut
'Given 2 strings return string of char found in Tin1, but not in Tin2
'return string
'Note: No character upper/lower conversion is done.
'Input Tin1 = main index string
'Input Tin2 = sub index string
'Output Tout = character/string
Tout=""
For CO_i=1 To Text.GetLength(Tin1)
tchar=text.GetSubText(Tin1,CO_i,1)
tindx=text.GetIndexOf(Tin2,tchar)
If (tindx=0) Then
Tout=Text.Append(Tout,tchar)
EndIf
EndFor
EndSub
Sub StringOut
'Given 2 strings return string of char found in Tin1, but not in Tin2
'return string
'Note: Convert all char to UPPER
'Note: Calls CharOut(), MakeAlpha()
'Input Tin1 = main index string
'Input Tin2 = sub index string
'Output Tout = character/string
Tin1=text.ConvertToUpperCase(Tin1)
Tin2=text.ConvertToUpperCase(Tin2)
CharOut()
Tin=Tout
MakeAlpha()
EndSub
No comments:
Post a Comment