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.
The example is about inserting records into a sequential file. My textbook says:
"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."
Then, it express the pseudo-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 < 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
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.
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 < Student) telling me if there is a new student to then write the TempFile, Student, and Score?
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.
At the end, why do we have to copy scratch onto grades?
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.
Note: This have nothing to do with an assignment, just trying to understand better the logic of programming.