Dating agency: Difference between revisions

Added FreeBASIC
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added FreeBASIC)
 
Line 131:
Robin
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Phix}}
<syntaxhighlight lang="vbnet">Function digitalRoot(n As Integer) As Integer
Assert(n >= 0)
While n > 9
Dim As Integer tot = 0
While n > 0
tot += (n Mod 10)
n \= 10
Wend
n = tot
Wend
Return n
End Function
 
Type Lady
nombre As String
Declare Function lovable() As Integer
Declare Function love(s As Any Ptr) As Integer
End Type
 
Function Lady.lovable() As Integer
Return (Asc(this.nombre) Mod 2)
End Function
 
Function Lady.love(s As Any Ptr) As Integer
Return (digitalRoot(Asc(this.nombre)) > 4)
End Function
 
Function newLady(nombre As String) As Lady
Dim As Lady l
l.nombre = nombre
Return l
End Function
 
Function ladyNames(ladies() As Lady) As String
Dim As String res = ""
For i As Integer = Lbound(ladies) To Ubound(ladies)
If ladies(i).nombre <> "" Then res &= ladies(i).nombre & ", "
Next i
Return Left(res, Len(res)-2) ' remove last comma and space
End Function
 
Type Marinero
nombre As String
Declare Function love(l As Any Ptr) As Integer
End Type
 
Function Marinero.love(l As Any Ptr) As Integer
Return Cast(Lady Ptr, l)->lovable()
End Function
 
Dim As String nombres(9) = {"Ada", "Crystal", "Elena", "Euphoria", "Janet", "Julia", "Lily", "Miranda", "Perl", "Ruby"}
Dim As Lady ladies(Ubound(nombres))
For i As Integer = Lbound(nombres) To Ubound(nombres)
ladies(i) = newLady(nombres(i))
Next i
Dim As Marinero sailor
sailor.nombre = "Pascal"
Dim As Integer eligiblesCount = 0
Dim As Lady eligibles(Ubound(ladies))
 
For i As Integer = Lbound(ladies) To Ubound(ladies)
If ladies(i).love(@sailor) Then
eligibles(eligiblesCount) = ladies(i)
eligiblesCount += 1
End If
Next i
 
Print "lady loves sailor lovable"
Print "---- ------------ -------"
 
For i As Integer = Lbound(ladies) To Ubound(ladies)
Print Using "\ \ & &"; ladies(i).nombre; Iif(ladies(i).love(@sailor), "True ", "False"); Iif(ladies(i).lovable(), "True ", "False")
Next i
 
Print !"\nBased on this analysis:"
Print "The dating agency should suggest the following ladies:"
Print ladyNames(eligibles())
 
Print !"\nand "; sailor.nombre; " should offer to date these ones:"
Print ladyNames(eligibles())
 
Sleep</syntaxhighlight>
 
=={{header|Julia}}==
2,130

edits