need help please

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
taichai
Newbie
Posts:1
Joined:Tue Dec 03, 2002 3:15 am
need help please

Post by taichai » Tue Dec 03, 2002 3:28 am

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.

vbmike56
Newbie
Posts:5
Joined:Sat Nov 30, 2002 7:51 am

Re: need help please

Post by vbmike56 » Tue Dec 03, 2002 8:16 am

&nbsp; 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.
&nbsp; Once we have that understanding we can proceed.

Guest

Re: need help please

Post by Guest » Tue Dec 03, 2002 9:44 am

DIM SHARED dayseachmonth(1 TO 12) &nbsp;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. &nbsp;(A)bort or (R)etry?"


'wait until the user presses a or r. &nbsp;lcase$ makes the keypress lowercase
DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
&nbsp;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
&nbsp;INPUT #1, pairup(getteams%, 1)
&nbsp;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. &nbsp;(A)bort or (R)etry?"

DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
&nbsp;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. &nbsp;(A)bort or (R)etry?"

DO UNTIL LCASE$(keybd$) = "a" OR keybd$ = "r"
&nbsp;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. &nbsp;
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??

vbmike56
Newbie
Posts:5
Joined:Sat Nov 30, 2002 7:51 am

Re: need help please

Post by vbmike56 » Tue Dec 03, 2002 12:02 pm

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

Guest

Re: need help please

Post by Guest » Wed Dec 04, 2002 4:16 am

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 &nbsp;
9 14 99 13 12 6 15 8 3 10 5 11 7 9 2 1 16 4 14 &nbsp;
9 21 99 9 16 8 14 15 10 11 3 5 2 7 13 4 12 1 6 &nbsp;
9 28 99 7 4 1 10 14 11 15 2 3 13 16 5 6 9 12 8 &nbsp;
10 5 99 8 5 2 12 13 1 14 16 15 4 6 3 10 7 9 11 &nbsp;
10 12 99 10 3 9 13 12 16 4 1 6 14 15 8 5 11 2 7 &nbsp;
10 19 99 15 11 7 16 4 9 12 6 8 1 10 14 3 2 13 5 &nbsp;
10 26 99 6 7 11 1 2 14 8 9 10 12 5 4 15 13 16 3 &nbsp;
11 2 99 4 13 15 3 11 8 1 14 2 16 12 9 7 5 6 10 &nbsp;
11 9 99 12 1 10 8 3 5 2 4 14 9 13 16 11 6 7 15 &nbsp;
11 16 99 11 10 13 2 16 4 5 15 7 3 8 6 9 1 14 12 &nbsp;
11 23 99 2 6 4 11 9 15 3 12 13 8 14 7 16 10 5 1 &nbsp;
11 30 99 5 9 12 7 6 13 16 11 1 15 4 10 14 3 8 2 &nbsp;
12 7 99 14 15 16 6 1 7 13 10 12 5 2 11 8 4 3 9 &nbsp;
12 14 99 16 8 14 5 10 2 9 7 4 6 3 1 12 15 11 13 &nbsp;
12 21 99 4 3 12 11 14 13 16 15 2 1 8 7 10 9 6 5 &nbsp;
1 11 0 15 6 2 9 16 1 14 4 12 13 5 10 7 11 3 8 &nbsp;
1 18 0 14 8 13 7 12 4 6 1 16 9 3 11 2 5 10 15 &nbsp;
1 25 0 10 1 5 16 9 6 8 12 4 7 2 15 13 3 11 14 &nbsp;
2 1 0 12 2 3 6 7 10 11 9 5 8 16 14 4 15 1 13 &nbsp;
2 8 0 13 9 8 15 11 5 7 2 3 10 1 4 14 6 16 12 &nbsp;
2 15 0 16 7 14 10 2 3 5 13 11 15 6 12 1 8 9 4 &nbsp;
2 22 0 1 11 4 5 13 15 3 16 7 6 9 8 12 10 14 2 &nbsp;
2 29 0 3 15 9 12 5 7 10 6 13 4 14 1 16 2 8 11 &nbsp;
3 7 0 8 10 16 13 6 11 15 7 1 12 4 2 9 14 5 3 &nbsp;
3 14 0 2 13 6 8 1 9 12 14 10 11 15 5 3 7 4 16 &nbsp;
3 21 0 11 4 7 14 10 16 1 5 6 2 12 3 8 13 15 9 &nbsp;
3 28 0 7 12 10 4 3 14 2 8 9 5 11 16 15 1 13 6 &nbsp;
4 4 0 6 16 11 2 4 8 9 3 15 14 10 13 5 12 7 1 &nbsp;
4 11 0 5 14 1 3 15 12 13 11 8 16 7 9 6 4 2 10 &nbsp;
4 18 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 &nbsp;
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?

Guest

Re: need help please

Post by Guest » Wed Dec 04, 2002 4:17 am

just do one line and ill follow it and finish the rest. thank you

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: need help please

Post by frankiebaby » Wed Dec 04, 2002 3:18 pm

Ok, providing that the file's numbers are all seperated by ONLY spaces OR commas, CR+LF:

TYPE DATE
&nbsp; &nbsp; DAY AS INTEGER
&nbsp; &nbsp; MONTH AS INTEGER
&nbsp; &nbsp; 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%

&nbsp; input #1, NUM
&nbsp; if TEAMPLAY(NUM) = 0 THEN
&nbsp; &nbsp; TEAMPLAY(NUM) = -1
&nbsp; ELSE
&nbsp; &nbsp; PRINT "ERROR....."
&nbsp; &nbsp; GOSUB HAVEERROR:
&nbsp; 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

Post Reply