help with college stats program

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
ludacris

help with college stats program

Post by ludacris »

I have to create a program that retrieves information from a data file.
Ex. of questions that have to be answered:
How many colleges/universities are in NC?
what school has the most faculty members (all ranks)?


The data file has information on division I II and III colleges in the U.S. and is saved in a txt file.

The character positions of the data found within this file has been organized in the following manner:

1-5 FICE (Federal ID number)
7-37 College name
38-39- State (postal code)
40-43 Type (I, IIA, or IIB)

I need help trying to figure out how to at least start this program, so that when a question is asked the info is read from the file. My code so far looks like this

CLS

FILE$ = "A:\college.txt"
OPEN FILE$ FOR INPUT AS #1

PRINT "Search our database for information on colleges"

DO WHILE NOT EOF(1)
INPUT #1, FICE, COLLEGE$, STATE$
IF STATE$ = "NC" THEN
LET s = s + 1
END IF
PRINT s



Please help
Y-12

What you need is random access files.

Post by Y-12 »

The best solution for you problem is random access files. You should read some good tutorial on random access files.

Here is a code that might help. This is for reading data:

CLS

TYPE URec
FICE AS SINGLE
COLLEGE AS STRING * 90
STATE AS STRING * 50
END TYPE

DIM orec AS URec

INPUT "Number of record>", rec%

OPEN "college.txt" FOR RANDOM AS #1 LEN = 145

GET #1, rec, orec

PRINT "FICE: "; orec.FICE
PRINT "COLLEGE: "; orec.COLLEGE
PRINT "STATE: "; orec.STATE

CLOSE #1








And this is for inputting data:

CLS

TYPE URec
FICE AS SINGLE
COLLEGE AS STRING * 90
STATE AS STRING * 50
END TYPE

DIM orec AS URec

FILE$ = "college.txt"

OPEN FILE$ FOR RANDOM AS #1 LEN = 145

INPUT "FICE>", orec.FICE
LINE INPUT "College>", orec.COLLEGE
LINE INPUT "State>", orec.STATE
PUT #1, , orec

CLOSE #1






I don't think this code answers your question exactly, but when you learn how to use random access files, you will be able to modify it.

?Y12
ludacris

Post by ludacris »

thanks, y-12 all info is useful!!
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Hi ludacris,

You might be interested in reading my Random Access File Tutorial I wrote for the QB express Magazine #6 ...

http://www.petesqbsite.com/sections/exp ... ccessfiles

There's this issue of a grey rectangle hiding everything in firefox, I suggest you open it in Internet Explorer :-).

or go to my website http://www.ascii-world.com and click on intermediate techniques (menu on the left) and you'll see it there too, and the forumatting there doesn't cause this hiding grey area :-)...choice is yours :-).

Hope this helps
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
guest

Re: help with college stats program

Post by guest »

you forgot TYPE (I, IIA or IIB) in your input#1 line
that could cause some errors...

1-5 FICE (Federal ID number)
7-37 College name
38-39- State (postal code)
40-43 Type (I, IIA, or IIB)



CLS

FILE$ = "A:\college.txt"
OPEN FILE$ FOR INPUT AS #1

PRINT "Search our database for information on colleges"

DO WHILE NOT EOF(1)
INPUT #1, FICE, COLLEGE$, STATE$
IF STATE$ = "NC" THEN
LET s = s + 1
END IF
PRINT s



Please help[/quote]
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

I am suprised this didn't turn into a flamewar about homework... even though I guess he did try... sorta...
Image
Y-12

Post by Y-12 »

People who really want to learn QBasic wouldn't use someone's code. They would try to some how understand it. I thought I should post the code because the OP started. I wouldn't post if he just said: "Make a database program for a college."

?Y-12
ludacris

Post by ludacris »

Nathan, Grow UP!
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

Y-12 wrote:People who really want to learn QBasic wouldn't use someone's code. They would try to some how understand it. I thought I should post the code because the OP started. I wouldn't post if he just said: "Make a database program for a college."

?Y-12
well said...
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Hey... my post got deleted... oh... no... my internet connection shut down... so Ill post it again.

I won't grow up because I am only 12. I enjoy NOT growing up while I still can.
Image
Post Reply