Note that there are some explanatory texts on larger screens.

plurals
  1. POSequential Files
    primarykey
    data
    text
    <p>Okay, so I'm still learning the basics of programming. Still learning to use pseudocode. I have read, and practised to write pseudocode operations. I still get so confused, and when I ask questions to my instructor I feel like I bother her. Maybe this is not the case, but this is how I always feel whenever I have questions, but I'm trying to break that barrier. So I'm going to give an example from my book, and I'll make some questions see if someone can help me understand.</p> <p>The example is about inserting records into a sequential file. My textbook says:</p> <p>"Let’s assume that the contents of the grades file lists records alphabetically according to student name. Suppose a new student joins the class. Now we need to insert a new record. We must place data in each field of that record. In this example, grades has two fields—one for the student’s name and one for the student’s score. So we want to insert values that are stored in the variables called NewName and NewScore. These values will be entered by the user and will be inserted into this file at the appropriate place, retaining alphabetical order."</p> <p>Then, it express the pseudo-code:</p> <pre><code>1 Declare NewName As String 2 Declare NewScore As Integer 3 Open “grades” For Input As GivenFile 4 Open “scratch” For Output As TempFile 5 Write “Enter name and score for the new student:” 6 Input NewName, NewScore 7 Set Inserted == 0 8 While (NOT EOF(GivenFile)) AND (Inserted == 0) 9 Read GivenFile, Student, Score 10 If NewName &lt; Student Then 11 Write TempFile, NewName, NewScore 12 Set Inserted = 1 13 End If 14 Write TempFile, Student, Score 15 End While 16 If Inserted == 0 Then 17 Write TempFile, NewName, NewScore 18 End If 19 While NOT EOF(GivenFile) 20 Read GivenFile, Student, Score 21 Write TempFile, Student, Score 22 End While 23 Close GivenFile, TempFile 24 Copy scratch onto grades </code></pre> <p>I don't understand line 3 and 4, why one is Input and the other is Output? I thought Input is what is going to be inserted in the program, and output is the results of what it was inserted in the program.</p> <p>Also, I have used the relational operators just with numbers, so I'm getting confused now that I see them as it is on line 10. What is it trying to tell me? Is (NewName &lt; Student) telling me if there is a new student to then write the TempFile, Student, and Score?</p> <p>In the first While loop is giving a Inserted = 1, then it ends the loop. Then repeats the Inserted == 0 (line 16), does this means in case there is another new student to repeat the while loop? I really got lost on this one.</p> <p>At the end, why do we have to copy scratch onto grades?</p> <p>I'm sorry for all the questions, I'm so confused, and I'm taking the classes online, which I have to teach myself, and I have nobody to discuss this with. </p> <p>Note: This have nothing to do with an assignment, just trying to understand better the logic of programming.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload