Page 1 of 1
need help please
Posted: Tue Dec 03, 2002 3:28 am
by taichai
can someone help me write this program
Assume someone has typed in a schedule for a league of teams in a sport, and that the schedule has been saved to disc in a plain text file. the project is to create a program which will check that file for correctness. in a file for a league with N teams, there will be (or should be) N+3 numbers in each line. for example, each record for an 8-team league would contain 11 numbers - the date, consisting of month, day, and year, followed by 8 team numbers.
6 29 02 1 3 2 4 5 7 6 8
this suggests that on 6/29/02, team 1 plays team 3, team 2 plays team 4, and so on.
this program should ask the user for the file name and number of teams. you may assume:
a. 4 teams minimum and 20 max
b. no more than 50 dates in a season
the program should check the dates and team numbers in every way you can think of. as a starting point, you are supplied with these things to test for:
a. the month should be 1 <= month <= 12
b. on a given day, no team should be scheduled twice
c. on a given day, every team must be scheduled once
when an error is found, output the offending record to the screen with some appropriate and intelligent error message that tells the user what error was found. the user should be allowed to ignore and continue, or abort the program.
Re: need help please
Posted: Tue Dec 03, 2002 8:16 am
by vbmike56
I think I can help you. However, I will need more information.
I also assume that this is a homework assignment. Therefore, I will help you and NOT do the project for you.
Once we have that understanding we can proceed.
Re: need help please
Posted: Tue Dec 03, 2002 9:44 am
by Guest
DIM SHARED dayseachmonth(1 TO 12) AS INTEGER
'get the number of days each month
FOR getdays% = 1 TO 12
READ dayseachmonth(getdays%)
NEXT getdays%
start:
CLS
'ask for the file and number of teams
INPUT "Schedule file: "; schedulefile$
INPUT "Number of teams: "; numteams%
'check for an odd number of teams.
IF numteams% AND 1 THEN
CLS
'tell user error
PRINT "Odd number of teams not supported. (A)bort or (R)etry?"
'wait until the user presses a or r. lcase$ makes the keypress lowercase
DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
keybd$ = INKEY$
LOOP
'check to see which key the user pressed, end if its a and go back
' to start if its r
IF LCASE$(keybd$) = "a" THEN END
IF LCASE$(keybd$) = "r" THEN GOTO start:
END IF
'create a 2d array, one column with half the number of teams
'and the other with 2 entries for teh two teams
DIM SHARED pairup(1 TO (numteams% \ 2), 1 TO 2) AS INTEGER
'open the schedule file
OPEN schedulefile$ FOR INPUT AS 1
'get the date info
INPUT #1, month%
INPUT #1, day%
INPUT #1, year%
'pair up the teams
FOR getteams% = 1 TO numteams% \ 2
INPUT #1, pairup(getteams%, 1)
INPUT #1, pairup(getteams%, 2)
NEXT getteams%
CLOSE 1
'check the month
IF month% < 1 OR month% > 12 THEN
'same error code as before
CLS
PRINT "Invalid month. (A)bort or (R)etry?"
DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
keybd$ = INKEY$
LOOP
IF LCASE$(keybd$) = "a" THEN END
IF LCASE$(keybd$) = "r" THEN GOTO start:
END IF
'check the day to the maximun days each month, stored in an array
IF day% < 1 OR day% > dayseachmonth%(month%) THEN
CLS
PRINT "Invalid day. (A)bort or (R)etry?"
DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
keybd$ = INKEY$
LOOP
IF LCASE$(keybd$) = "a" THEN END
IF LCASE$(keybd$) = "r" THEN GOTO start:
END IF
'print date
PRINT
PRINT "On "; month%; "/"; day%; "/"; year%; " The games are:"
'print data
FOR printpairs% = 1 TO numteams% \ 2
PRINT "Team "; pairup(printpairs%, 1); " is playing team "; pairup(printpairs%, 2)
NEXT
'Number of days in each month.
DATA 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
here are the data
9 7 99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
9 14 99 13 12 6 15 8 3 10 5 11 7 9 2 1 16 4 14
9 21 99 9 16 8 14 15 10 11 3 5 2 7 13 4 12 1 6
9 28 99 7 4 1 10 14 11 15 2 3 13 16 5 6 9 12 8
10 5 99 8 5 2 12 13 1 14 16 15 4 6 3 10 7 9 11
10 12 99 10 3 9 13 12 16 4 1 6 14 15 8 5 11 2 7
10 19 99 15 11 7 16 4 9 12 6 8 1 10 14 3 2 13 5
10 26 99 6 7 11 1 2 14 8 9 10 12 5 4 15 13 16 3
11 2 99 4 13 15 3 11 8 1 14 2 16 12 9 7 5 6 10
11 9 99 12 1 10 8 3 5 2 4 14 9 13 16 11 6 7 15
11 16 99 11 10 13 2 16 4 5 15 7 3 8 6 9 1 14 12
11 23 99 2 6 4 11 9 15 3 12 13 8 14 7 16 10 5 1
11 30 99 5 9 12 7 6 13 16 11 1 15 4 10 14 3 8 2
12 7 99 14 15 16 6 1 7 13 10 12 5 2 11 8 4 3 9
12 14 99 16 8 14 5 10 2 9 7 4 6 3 1 12 15 11 13
12 21 99 4 3 12 11 14 13 16 15 2 1 8 7 10 9 6 5
1 11 0 15 6 2 9 16 1 14 4 12 13 5 10 7 11 3 8
1 18 0 14 8 13 7 12 4 6 1 16 9 3 11 2 5 10 15
1 25 0 10 1 5 16 9 6 8 12 4 7 2 15 13 3 11 14
2 1 0 12 2 3 6 7 10 11 9 5 8 16 14 4 15 1 13
2 8 0 13 9 8 15 11 5 7 2 3 10 1 4 14 6 16 12
2 15 0 16 7 14 10 2 3 5 13 11 15 6 12 1 8 9 4
2 22 0 1 11 4 5 13 15 3 16 7 6 9 8 12 10 14 2
2 29 0 3 15 9 12 5 7 10 6 13 4 14 1 16 2 8 11
3 7 0 8 10 16 13 6 11 15 7 1 12 4 2 9 14 5 3
3 14 0 2 13 6 8 1 9 12 14 10 11 15 5 3 7 4 16
3 21 0 11 4 7 14 10 16 1 5 6 2 12 3 8 13 15 9
3 28 0 7 12 10 4 3 14 2 8 9 5 11 16 15 1 13 6
4 4 0 6 16 11 2 4 8 9 3 15 14 10 13 5 12 7 1
4 11 0 5 14 1 3 15 12 13 11 8 16 7 9 6 4 2 10
4 18 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4 25 0 13 12 6 15 8 3 10 5 11 7 9 2 1 16 4 14
the first number is the month, second is the date, third is the year and the rest are just the team #
how can i put this in as schedulefile$ and numteams% for the data input??
Re: need help please
Posted: Tue Dec 03, 2002 12:02 pm
by vbmike56
Nice work Puni. A lot better than my way. I'll post it anyway.
Text file=Drive:\north.txt
6 29 02 1 3 2 4 5 7 6 8
1 10 02 1 1 4 5 6 8 2 3
3 30 02 2 4 1 3 5 6 7 8
12 29 02 1 2 3 4 5 6 7 9
13 1 02 1 2 3 4 5 6 7 8
1 1 02 1 2 3 4 5 6 7 8
Qbasic File=Teams.bas
CLS
teams% = 0
PRINT "Enter File Name:"
INPUT filename$
DO WHILE teams% < 4 OR teams% > 20
PRINT "Enter number of teams:"
INPUT teams%
LOOP
LET filename$ = LTRIM$(RTRIM$(filename$)) + ".txt"
OPEN "Drive:\" + filename$ FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, aline$
REM I'm going to assume that all dates with end with 02
LET GameDay$ = LEFT$(aline$, INSTR(1, aline$, "02") + 1)
LET TeamMatch$ = MID$(aline$, INSTR(1, aline$, "02") + 3)
PRINT GameDay$
PRINT TeamMatch$
REM Check dates
IF VAL(LEFT$(GameDay$, 2)) < 1 OR VAL(LEFT$(GameDay$, 2)) > 12 THEN
PRINT "*** Date Error ***", GameDay$
END IF
REM No Game Error
FOR i = 1 TO teams%
IF INSTR(1, TeamMatch$, LTRIM$(STR$(i))) = 0 THEN
PRINT "*** No Game Error ***"
PRINT "On day:"; GameDay$; "For team"; i; "*"; TeamMatch$
END IF
NEXT i
REM MultiGame error
PRINT TeamMatch$
FOR i = 1 TO teams%
count% = 0
position% = INSTR(TeamMatch$, LTRIM$(STR$(i)))
DO WHILE position% <> 0
count% = count% + 1
position% = INSTR(position% + 1, TeamMatch$, LTRIM$(STR$(i)))
IF count% > 1 THEN
PRINT "Scheduling Error for Team:"; i; "Scheduled"; count%; "Times"
END IF
LOOP
NEXT i
SLEEP
CLS
LOOP
CLOSE #1
END
Re: need help please
Posted: Wed Dec 04, 2002 4:16 am
by Guest
but how do i turn all this into the appropriate area, such as what day, month and year, this team play against this team
9 7 99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
9 14 99 13 12 6 15 8 3 10 5 11 7 9 2 1 16 4 14
9 21 99 9 16 8 14 15 10 11 3 5 2 7 13 4 12 1 6
9 28 99 7 4 1 10 14 11 15 2 3 13 16 5 6 9 12 8
10 5 99 8 5 2 12 13 1 14 16 15 4 6 3 10 7 9 11
10 12 99 10 3 9 13 12 16 4 1 6 14 15 8 5 11 2 7
10 19 99 15 11 7 16 4 9 12 6 8 1 10 14 3 2 13 5
10 26 99 6 7 11 1 2 14 8 9 10 12 5 4 15 13 16 3
11 2 99 4 13 15 3 11 8 1 14 2 16 12 9 7 5 6 10
11 9 99 12 1 10 8 3 5 2 4 14 9 13 16 11 6 7 15
11 16 99 11 10 13 2 16 4 5 15 7 3 8 6 9 1 14 12
11 23 99 2 6 4 11 9 15 3 12 13 8 14 7 16 10 5 1
11 30 99 5 9 12 7 6 13 16 11 1 15 4 10 14 3 8 2
12 7 99 14 15 16 6 1 7 13 10 12 5 2 11 8 4 3 9
12 14 99 16 8 14 5 10 2 9 7 4 6 3 1 12 15 11 13
12 21 99 4 3 12 11 14 13 16 15 2 1 8 7 10 9 6 5
1 11 0 15 6 2 9 16 1 14 4 12 13 5 10 7 11 3 8
1 18 0 14 8 13 7 12 4 6 1 16 9 3 11 2 5 10 15
1 25 0 10 1 5 16 9 6 8 12 4 7 2 15 13 3 11 14
2 1 0 12 2 3 6 7 10 11 9 5 8 16 14 4 15 1 13
2 8 0 13 9 8 15 11 5 7 2 3 10 1 4 14 6 16 12
2 15 0 16 7 14 10 2 3 5 13 11 15 6 12 1 8 9 4
2 22 0 1 11 4 5 13 15 3 16 7 6 9 8 12 10 14 2
2 29 0 3 15 9 12 5 7 10 6 13 4 14 1 16 2 8 11
3 7 0 8 10 16 13 6 11 15 7 1 12 4 2 9 14 5 3
3 14 0 2 13 6 8 1 9 12 14 10 11 15 5 3 7 4 16
3 21 0 11 4 7 14 10 16 1 5 6 2 12 3 8 13 15 9
3 28 0 7 12 10 4 3 14 2 8 9 5 11 16 15 1 13 6
4 4 0 6 16 11 2 4 8 9 3 15 14 10 13 5 12 7 1
4 11 0 5 14 1 3 15 12 13 11 8 16 7 9 6 4 2 10
4 18 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4 25 0 13 12 6 15 8 3 10 5 11 7 9 2 1 16 4 14
how would i put all this together and must i save it separately?
Re: need help please
Posted: Wed Dec 04, 2002 4:17 am
by Guest
just do one line and ill follow it and finish the rest. thank you
Re: need help please
Posted: Wed Dec 04, 2002 3:18 pm
by frankiebaby
Ok, providing that the file's numbers are all seperated by ONLY spaces OR commas, CR+LF:
TYPE DATE
DAY AS INTEGER
MONTH AS INTEGER
YEAR AS INTEGER
END TYPE
DIM THISDAY AS DATE
MANYTEAMS% = 4
DIM TEAMPLAY( 1 to MANYTEAMS) as int
FOR COUNT = 1 to MANYTEAMS
TEAMPLAY(COUNT) = 0
NEXT
open "file.ext" for input as #1
DO
input #1, THISDAY.DAY
input #1, THISDAY.MONTH
input #1, THISDAY.YEAR
FOR COUNT = 1 to MANYTEAMS%
input #1, NUM
if TEAMPLAY(NUM) = 0 THEN
TEAMPLAY(NUM) = -1
ELSE
PRINT "ERROR....."
GOSUB HAVEERROR:
END IF
NEXT COUNT
'do your date checking here,
'if everything check out, you'll end up here:
FOR COUNT = 1 to MANYTEAMS
TEAMPLAY(COUNT) = 0
NEXT
'and then do it again
LOOP UNTIL EOF (1)
END
HAVEERROR:
'ask for abort or retry here
if "USERSAYSNO" then END
RETURN