• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

storing records (1 Viewer)

raymes

Member
Joined
Jan 21, 2004
Messages
116
Location
Sydney
Gender
Male
HSC
2004
i was just wondering if anyone could give some clarification on keywords for storing an array of records in a file in psuedocode. i know how its done in VB and realise that there probably isnt one set way of doing it in psudocode but what would be acceptable?

for a set of 1-20 records, would something like the following be accpetable?

Code:
index = 1
OPEN filename as random
while index <=20
      store record(index)
      index = index + 1
end while
CLOSE filename
and then what about reading, say, a specific record from a file into an array?

Code:
index = 1
OPEN filename as random
load record(index)
CLOSE filename
in reality i know its slightly more complex than this but is that sufficent?
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Raymes, looks good to me. Obviously filename and record would be replaced with more meaningful identifiers appropriate to the question.

Furthermore they often use an end of file (EOF) marker or a sentinel (say, "ZZZ"), to mark the end of the file. So your loop and condition for a read would start with WHILE NOT end of file or WHILE NOT sentinel. Clearly it depends on the question, maybe both would be appropriate, say WHILE Index<=20 AND NOT Sentinel.

One other thing... If you're defining the structure of the record it's worth describing this just before your algorithm. Just list the fields and the name of the array of records, no need for any fancy or specific syntax. This makes it simpler for the marker, and gives them the impression you know what you're on about.

HTH
Sam
 
Last edited:

hornetfig

Member
Joined
Jun 27, 2004
Messages
65
Location
Sydney. oddly
Gender
Male
HSC
2003
raymes said:
. . .but what would be acceptable?
zoodboog said:
I would have done this
and I'd probably have been really fond of using "EOF" in lieu of length(<record array>). But given that the markers of the SDD paper are your teachers, and you know how bad at this stuff most of them are, and that their only real guide is the syllabus, if it makes sense, is syntactically correct and follows the syllabus guidelines then I cannot see why they wouldn't pay it.
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
In regard to zoodboog's post: I think Raymes was talking about a random access file not a database connection. I'd tend to avoid the word database, it implies some proprietry file format rather than a simple random access file.

Also, the loop condition Index<=Length(records) is incorrect (or at least misleading). Currently this says that we are writing the same number of records as the length of each record. For example if each record contains 20 chars then we'll write 20 records.

HTH
Sam
 

raymes

Member
Joined
Jan 21, 2004
Messages
116
Location
Sydney
Gender
Male
HSC
2004
the length of a record tends to indicate the size of the record. this is necessary when storing or accessing random files since the program needs to know where to start reading and writing. for example, if the size of each record was 5 bytes, and you wanted to write to the 3rd record in a file, the program would start writing at 3*5bytes into the file.
 

hornetfig

Member
Joined
Jun 27, 2004
Messages
65
Location
Sydney. oddly
Gender
Male
HSC
2003
zoodboog said:
bizarre, apparently I actually used that in VB, I didn't realise that I had repressed my HS memories that much

I still think it's a massive misnomer though :uhhuh:
Yes it's a misnomer because you use it to return the number of characters in the string, but that isn't the size of it, whereas for a record it will return its size for purposes of block reading/writing it.

So in Delphi, which generally makes more sense for such things, the length of a string or array is Length() but the memory footprint of a record or array is SizeOf().
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top