Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
84
Task/Filter/QBasic/filter-1.basic
Normal file
84
Task/Filter/QBasic/filter-1.basic
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
' OPTION EXPLICIT
|
||||
|
||||
' Filter
|
||||
' This program selects certain elements from an array into a new array in a generic way
|
||||
|
||||
' Var
|
||||
' $DYNAMIC
|
||||
|
||||
TYPE regSub
|
||||
aNum AS INTEGER
|
||||
END TYPE
|
||||
CONST Even = 2
|
||||
CONST Uneven = 1
|
||||
CONST cFile = "DUMMY$$$.$$$"
|
||||
CONST False = 0, True = NOT False
|
||||
|
||||
DIM t AS INTEGER
|
||||
DIM t2 AS INTEGER
|
||||
DIM f AS INTEGER
|
||||
DIM i AS INTEGER
|
||||
DIM iFlag AS INTEGER
|
||||
DIM iGetWhat AS INTEGER
|
||||
DIM iArray%(1 TO 1)
|
||||
DIM iArray2%(1 TO 1)
|
||||
DIM rSub AS regSub
|
||||
|
||||
' Initialize vars
|
||||
iFlag = False
|
||||
f = FREEFILE
|
||||
iGetWhat = Even
|
||||
RANDOMIZE TIMER
|
||||
t = INT(RND * 300) + 1
|
||||
REDIM iArray%(1 TO t)
|
||||
|
||||
' Main program cycle
|
||||
OPEN cFile FOR OUTPUT AS #f
|
||||
CLOSE
|
||||
|
||||
OPEN cFile FOR RANDOM AS #f LEN = LEN(rSub)
|
||||
|
||||
CLS
|
||||
PRINT "Select items in an array into a new array in a generic way."
|
||||
PRINT "Base array:"
|
||||
FOR i = 1 TO t
|
||||
iArray%(i) = INT(RND * 2000) + 1
|
||||
PRINT iArray%(i);
|
||||
IF (iArray%(i) MOD 2) = 0 AND iGetWhat = Even THEN
|
||||
iFlag = True
|
||||
ELSEIF (iArray%(i) MOD 2) <> 0 AND iGetWhat = Uneven THEN
|
||||
iFlag = True
|
||||
END IF
|
||||
|
||||
IF iFlag THEN
|
||||
rSub.aNum = iArray%(i)
|
||||
PUT #f, , rSub
|
||||
iFlag = False
|
||||
END IF
|
||||
NEXT i
|
||||
|
||||
' Redims the array
|
||||
t2 = LOF(f) / LEN(rSub)
|
||||
REDIM iArray2%(1 TO t2)
|
||||
|
||||
FOR i = 1 TO t2
|
||||
GET #f, i, rSub
|
||||
iArray2%(i) = rSub.aNum
|
||||
NEXT i
|
||||
|
||||
CLOSE #f
|
||||
KILL cFile
|
||||
|
||||
PRINT
|
||||
|
||||
' Shows the result
|
||||
IF t2 > 0 THEN
|
||||
PRINT "Selected items from the array (total:"; t2; "of"; t; "):"
|
||||
FOR i = 1 TO t2
|
||||
PRINT iArray2%(i);
|
||||
NEXT i
|
||||
END IF
|
||||
|
||||
PRINT
|
||||
PRINT "End of program."
|
||||
END
|
||||
84
Task/Filter/QBasic/filter-2.basic
Normal file
84
Task/Filter/QBasic/filter-2.basic
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
' OPTION EXPLICIT
|
||||
|
||||
' Filter
|
||||
' This program selects certain elements from an array into a new array in a generic way
|
||||
' Extra points: Destroys the original values in the array
|
||||
|
||||
' Var
|
||||
' $DYNAMIC
|
||||
|
||||
TYPE regSub
|
||||
aNum AS INTEGER
|
||||
END TYPE
|
||||
CONST Even = 2
|
||||
CONST Uneven = 1
|
||||
CONST cFile = "DUMMY$$$.$$$"
|
||||
CONST False = 0, True = NOT False
|
||||
DIM t AS INTEGER
|
||||
DIM t2 AS INTEGER
|
||||
DIM f AS INTEGER
|
||||
DIM i AS INTEGER
|
||||
DIM iFlag AS INTEGER
|
||||
DIM iGetWhat AS INTEGER
|
||||
DIM iArray%(1 TO 1)
|
||||
DIM rSub AS regSub
|
||||
|
||||
' Initialize vars
|
||||
iFlag = False
|
||||
t = INT(RND * 300) + 1
|
||||
f = FREEFILE
|
||||
iGetWhat = Even
|
||||
REDIM iArray%(1 TO t)
|
||||
|
||||
' Main program cycle
|
||||
OPEN cFile FOR OUTPUT AS #f
|
||||
CLOSE
|
||||
|
||||
OPEN cFile FOR RANDOM AS #f LEN = LEN(rSub)
|
||||
|
||||
CLS
|
||||
RANDOMIZE TIMER
|
||||
PRINT "Select items in an array into a new array in a generic way."
|
||||
PRINT "Base array:"
|
||||
FOR i = 1 TO t
|
||||
iArray%(i) = INT(RND * 2000) + 1
|
||||
PRINT iArray%(i);
|
||||
IF (iArray%(i) MOD 2) = 0 AND iGetWhat = Even THEN
|
||||
iFlag = True
|
||||
ELSEIF (iArray%(i) MOD 2) <> 0 AND iGetWhat = Uneven THEN
|
||||
iFlag = True
|
||||
END IF
|
||||
|
||||
IF iFlag THEN
|
||||
rSub.aNum = iArray%(i)
|
||||
PUT #f, , rSub
|
||||
iFlag = False
|
||||
END IF
|
||||
NEXT i
|
||||
|
||||
' Redims the array
|
||||
t = LOF(f) / LEN(rSub)
|
||||
REDIM iArray%(1 TO t)
|
||||
|
||||
FOR i = 1 TO t
|
||||
GET #f, i, rSub
|
||||
iArray%(i) = rSub.aNum
|
||||
NEXT i
|
||||
|
||||
CLOSE #f
|
||||
KILL cFile
|
||||
|
||||
PRINT
|
||||
|
||||
' Shows the result
|
||||
t2 = UBOUND(iArray%)
|
||||
IF t2 > 0 THEN
|
||||
PRINT "Selected items from the array (total:"; t2; "of"; t; "):"
|
||||
FOR i = 1 TO t2
|
||||
PRINT iArray%(i);
|
||||
NEXT i
|
||||
END IF
|
||||
|
||||
PRINT
|
||||
PRINT "End of program."
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue