• 0

Pseudo code help. Don't quite understand the question


Question

Record separation problem

Let us assume that a particular database program manages a simple mailing list which consists of one record for each person on the list, and a number of fields containing information about each person (their name, address, etc). The program can read in data produced by a word processor provided that data is structured in the following way

Each record to be read must be a single paragraph terminated by a return character, and each field within a record is separated by a tab character. For Example:

Colin Jameson|tab|33Falcon Street|tab|Waverly|tab|NSW|tab|2114|return|

Would be read as one record containing five fields. The end of the data is marked with the # (Hash) character which immediately follows the return ending the last paragraph.

Assuming that there is at least one line of valid data at the start of the input file, describe an algorithm that the program might use to read such data one character at a time and place the information into separate fields and records. The algorithm reports the number of records read when all records have been processed.

The question as said above I'm trying to understand it as to what it's asking from me is it asking for me to create a pseudocode which sorts random details into the form as shown above or to create like a database with everything sorted out? I was given a hint to use a array but I have no idea how.

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

It asks to read any data file with the given structure into memory one character at a time and to count how many records (persons) are there.

Nothing about sorting, don't overcomplicate.

Also, pseudocode usually doesn't go into details about data structures. Rather, it's an informal, abstract explanation of how things are to be done regardless of language or tools.

Link to comment
Share on other sites

  • 0

Thanks for the response

So it's asking for me to create a pseudocode that can read what is on each line and sort it into how each one is formatted with a tab at the end of one and a return at the end? Would this mean the program would read what is there and decide whether or not it's a address, name ect?

Or is the word document that is being read off of written by someone like me where it would be structured out correctly with the tabs and returns and the program needs to read it to be put into the record?

While also counting how many records there are which is easy

Link to comment
Share on other sites

  • 0

Yes, one shall assume that the document is always structured correctly - just read the data and count stuff. Must not even decide what a certain value means - the name always comes first, then comes street, then city, then state and then area code or whatever the number is as the last.

Link to comment
Share on other sites

  • 0

I'll get started doing this asap not at home at the moment but when I get back and have it complete or near complete could you have a look over it and let me know if there's any problems or something I missed out?

Also not sure but am I allowed to write something like

Get next field or would I have to use something else to figure out what the next field is?

Link to comment
Share on other sites

  • 0

Of course! Either me or many other more skilled people on these forums will.

You'll have to read the file by one character, because you don't really know where a field, a record or whole file ends - until you've read the very last character of it.

I think you can even discard the actual values (unless there's another, more advanced assignment to which this will serve as a template).

Link to comment
Share on other sites

  • 0

Ok What I have is this

BEGIN MAINPROGRAM

Character_count = Null (Real)

Field_count = Null (Real)

Record_count = Null (Real)

File_status = Null (Boolean)

Open file

REPEAT

Record each character into a field

Check field if it contains these

8]CASEWHERE Character encounters

tab : Field_count + 1

return : Record_count +1

# : File_status = EoF

OTHERWISE

Character_count = Character_count + 1

ENDCASE

IF tab is encountered THEN

Move onto next field

ENDIF

UNTIL File_status = EoF

END MAINPROGRAM

I'm not sure if thats all the question is asking since It seems a bit small and I'm not sure if I can use "Check field if it contains these" and if I need it there or not

Ermm for some reason the post formatting looks weird when I used tabs to seperate out and format the pseudocode correctly sorry about it :s

Link to comment
Share on other sites

  • 0

Record separation problem

Let us assume that a particular database program manages a simple mailing list which consists of one record for each person on the list, and a number of fields containing information about each person (their name, address, etc). The program can read in data produced by a word processor provided that data is structured in the following way

Each record to be read must be a single paragraph terminated by a return character, and each field within a record is separated by a tab character. For Example:

Colin Jameson|tab|33Falcon Street|tab|Waverly|tab|NSW|tab|2114|return|

Would be read as one record containing five fields. The end of the data is marked with the # (Hash) character which immediately follows the return ending the last paragraph.

Assuming that there is at least one line of valid data at the start of the input file, describe an algorithm that the program might use to read such data one character at a time and place the information into separate fields and records. The algorithm reports the number of records read when all records have been processed.

The question as said above I'm trying to understand it as to what it's asking from me is it asking for me to create a pseudocode which sorts random details into the form as shown above or to create like a database with everything sorted out? I was given a hint to use a array but I have no idea how.


get(data)
do(
recordcount++
separate out fields based on tab delimiter
do what ever you need with data
)while (get(data) != "#")

print (number of records is) recordcount
[/CODE]

Link to comment
Share on other sites

  • 0

I'd think you still need to be a little more specific than:

Begin at the beginning, increase record count along the way when there's a return, till you come to a hash: then stop and return the number.

:laugh:

...but yes, that's the general idea.

@OP: use [ code ] codegoeshere [ /code ] tags (without spaces) for code.

Link to comment
Share on other sites

  • 0


BEGIN MAINPROGRAM
					    Character_count = Null (Real)
					    Field_count = Null (Real)
Record_count = Null (Real)
File_status = Null (Boolean)
Open file			
REPEAT
[indent=1]Record each character into a field[/indent]
[indent=1]Check field if it contains these[/indent]
[indent=1.8]CASEWHERE Character encounters[/indent]
											    tab				 :					   Field_count + 1
											    return		 :					   Record_count +1
											    #					 :					   File_status = EoF								
					    OTHERWISE
											    Character_count = Character_count + 1
					    ENDCASE
					    IF tab is encountered THEN
											    Move onto next field
					    ENDIF
UNTIL File_status = EoF
END MAINPROGRAM

Ok I tried putting it like that but I have a count for fields, records and characters in the pseudocode as you can see from the x_count + 1

Link to comment
Share on other sites

  • 0

1. Strong typing isn't particularily helpful in pseudocode. Consider leaving out variable types. In fact, no strong typing language would allow initializing Real, much less Boolean, with Null, even though both do have 0 value (if I remember single-precision IEEE standard). And while we know what EoF means, it also isn't a Boolean value. Types are quite pointless, if you don't use them as such.

2. Don't do unnecessary things:

* counting characters (in languages with no character string type this would be crucial, but not here)

* counting fields (which are, by definition, record count * 5, twist or turn).

3. If you open file, be sure to close it when done with it.

4. I think it would benefit to elaborate more on what "record each character into a field" is. You don't want delimiters to be actually stored in the field. You need to read a character, check it and add to the field only if it isn't any of delimiters.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.