Newbie QBasic help.

Status
Not open for further replies.

CT!!

Ars Praetorian
512
I lack the programming skillz and this is a school assignment. So far, its been pretty ok. This one is stumping me for some reason.



Here is a basic sample of what I'm trying to do.

CLS
DIM phone$(100), name$(100)
i = 0
DO
i = i + 1
READ name$(i), phone$(i)
LOOP UNTIL name$(i) = "EOD"

size = i - 1

'Bubble Sort Total number of passes = (n-1) * (n-1)
FOR scnt = 1 TO size - 1
FOR j = 1 TO size - 1
IF name$(j) > name$(j + 1) THEN '> ==> < descending order
SWAP name$(j), name$(j + 1)
SWAP phone$(j), phone$(j + 1)
END IF
NEXT j
NEXT scnt

PRINT "Name", "Phone"

FOR i = 1 TO size
PRINT name$(i), phone$(i)
NEXT i

END
DATA Jill, 555-5555, Sam, 111-1111
DATA Sue, 777-7777, Ed, 222-2222
DATA Bill, 333-3333, EOD, ***-****



This is the easy part (generic bubble sorting). Its basically two sets of data. Name and Phone number.

I need to start the program out by asking how I want to search said data (by phone or name) and after it sorts it based on my decision, it should ask if I want to do the same thing again until I say no.


Any ideas? I've speant the last few nights scrounging google, reading my testbook chapters repeatedly and I'm about dead on the matter. haha.

Thank you for any assitance!
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
Stick the whole thing in a DO - WHILE loop and make the IF statement inside the loop depend on some user-input variable.

E.g.,
code:<HR>
Code:
...
size = size - 1
DO
  CLS
  ? "Would you like to sort in ascending or descending order? (a/d)"
  DO 
    GET(in$)
  WHILE LCASE$(in$) <> "a" AND LCASE$(in$) <> "d"
  IF in$ = "a" THEN ascend = TRUE
  ELSE ascend = FALSE
  ...

  IF ascend = TRUE THEN
    'your IF statement
  ELSE
    'IF statement using '<'
  
  ...

  ? "Would you like to continue? (y/n)"
  DO 
    GET(in$)
    in$ = LCASE$(in$)
  WHILE in$ <> "y" AND in$ <> "n"

WHILE in$ <> "y"

END

...
 

CT!!

Ars Praetorian
512
Here's what I'm working with so far...again, I'm not too in to this, so all I know so far is that it doesn't work. :)

This is the actual assignment. The above was just an simple example I found during my google runs. :)



menu:
CLS
PRINT "Sort by Lastname, Firstname or Grade (L, F, G): "

DO
ans$ = INKEY$
IF ans$ = "L" THEN GOTO lastname
IF ans$ = "F" THEN GOTO firstname
IF ans$ = "G" THEN GOTO grade
DO UNTIL UCASE$(switch$) = "N"
LOOP


lastname:
'Bubble Sort Total number of passes = (n-1) * (n-1)
FOR scnt = 1 TO size - 1
FOR j = 1 TO size - 1
IF lastname$(j) > lastname$(j + 1) THEN
SWAP firstname$(j), firstname$(j + 1)
SWAP firstname$(j), firstname$(j + 1)
SWAP grade$(j), grade$(j + 1)
SWAP grade$(j), grade$(j + 1)
END IF
NEXT j
NEXT scnt
CLOSE 1
INPUT "Re-sort? (Y/N)"; switch$
GOTO menu

firstname:
'Bubble Sort Total number of passes = (n-1) * (n-1)
FOR scnt = 1 TO size - 1
FOR j = 1 TO size - 1
IF firstname$(j) > firstname$(j + 1) THEN
SWAP lastname$(j), lastname$(j + 1)
SWAP lastname$(j), lastname$(j + 1)
SWAP firstname$(j), firstname$(j + 1)
SWAP firstname$(j), firstname$(j + 1)
END IF
NEXT j
NEXT scnt
CLOSE 1
INPUT "Re-sort? (Y/N)"; switch$
GOTO menu

grade:
'Bubble Sort Total number of passes = (n-1) * (n-1)
FOR scnt = 1 TO size - 1
FOR j = 1 TO size - 1
IF grade$(j) > grade$(j + 1) THEN
SWAP lastname$(j), lastname$(j + 1)
SWAP lastname$(j), lastname$(j + 1)
SWAP firstname$(j), firstname$(j + 1)
SWAP firstname$(j), firstname$(j + 1)
END IF
NEXT j
NEXT scnt
CLOSE 1
INPUT "Re-sort? (Y/N)"; switch$
GOTO menu

END

DATA Scott, Natter, 100
DATA Kerry, Wong, 78
DATA Rick, Singer, 94
DATA Charles, Fox, 98
DATA Mark, Howle, 84
DATA Dawn, Keiser, 79
DATA Hank, Keys, 82
 

CT!!

Ars Praetorian
512

dockeen

Ars Tribunus Militum
1,600
I wonder. Where does "modern" teaching of programming start?
Do they start talking about the big picture (design, objects etc.)
before they get to the low level stuff, assignments, conditionals loops etc. or vice versa.

I'm wondering, is there a case to be made that QBasic is as good as anything if you are just starting off and looking at the low level stuff. I learned it that way. I don't think I would start someone there these days though, when there are languages such as Python that support the teaching process up through the higher level stuff. I bet we have a few cases where instructors are making the students learn things the same way they learned it.

Just thinking out loud...

Wayne
 
Status
Not open for further replies.