|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I need to do a program for my Discrete math class. Main idea Program should have 2 textboxes .. one to enter the domain such as "1 2 3 4 5" (This syntax) and the second one to enter a set of relations as this syntax "(1,1) (2,2) (3,1)" Then When user clicks on the "Find properties" button, I should show him (in labels) each property such as: IF reflexive or not IF symmetric or not IF anti symmetric or not IF transitive or not I have done the first 3 functions (properties) and i couldn't do the last one "Transitive". Transitive is if there was (1,2) AND (2,3) Then there should be (1,3) in the entered set. ------------------------------------------ This is the first procedure to do it: Code:
string2 = txt_relations.Text string2 = Trim(string2) array2 = Split(string2, " ", -1, vbTextCompare) Now if user enteres (1,2) (2,3) (1,3) so: array2(0) = "(1,2)" array2(1) = "(2,3)" array2(2) = "(1,3)" And i did something like: Code:
string2 = Replace(string2, "(", "")
string2 = Replace(string2, ")", "")
string2 = Replace(string2, ",", " ")
string2 = Trim(string2)
array3 = Split(string2, " ", -1, vbTextCompare)
So array3 have: array3(0) = 1 array3(1) = 2 array3(2) = 2 array3(3) = 3 array3(4) = 1 array3(5) = 3 These are some ideas i thought but I couldn't complete it, also I thought about comparing array2 and string2 (before removing braces) and do some operations on them such as Instr etc... For example This what I did to say wether the relation is reflexive or not (Reflexive means if the domain was 1 2 3 then the relations should contain (1,1) (2,2) (3,3)" Code:
Function CheckIsR(ByVal array1, ByVal array2)
Dim i As Integer
Dim TempString1 As String
Dim TempString2 As String
Dim TempArray
Dim counter
counter = 0
'MADE SOMETHING LIKE (1,1) (2,2) OR (A,A) (B,B) FROM THE DOMAIN ELEMENTS
For i = 0 To UBound(array1)
If TempString1 = "" Then
TempString1 = "(" + array1(i) + "," + array1(i) + ")"
Else
TempString1 = TempString1 + " " + "(" + array1(i) + "," + array1(i) + ")"
End If
Next i
'MADE IT AS ARRAY EACH NEW RELATION AS AN ARRAY ELEMENT
TempArray = Split(TempString1, " ", -1, vbTextCompare)
'MADE A STRING FROM THE RELATIONS (THE ORIGINAL RELATIONS ENTERED BY USER)
For i = 0 To UBound(array2)
If TempString2 = "" Then
TempString2 = array2(i)
Else
TempString2 = TempString2 + " " + array2(i)
End If
Next i
'CHECK IF THE NEW RELATIONS SUCH AS (1,1) (2,2) THAT ARE MADE FROM DOMAIN ARE FOUND IN THE RELATIONS STRING
'IF ONE OF THEM WAS NOT FOUND THEN COUNTER = COUNTER + 1
For i = 0 To UBound(TempArray)
If InStr(1, TempString2, TempArray(i), vbTextCompare) = 0 Then
counter = counter + 1
Else
'SKIP ONLY (OR DO NOTHING)
lbl_skip.Caption = ""
End If
Next i
'IF COUNTER IS EQUAL TO ZERO THEN IT'S REFLEXIVE, ELSE IT'S NOT REFLEXIVE
If counter = 0 Then
CheckIsR = True
Else
CheckIsR = False
End If
End Function
I really need to do this, I hope someone can help me, Thanks in advance, zeid |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Transitive relation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|