Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with #27 End While Close GivenFile, TempFile 27. Set Inputltem = C Set Inpu

ID: 3569691 • Letter: H

Question

Help with #27

End While Close GivenFile, TempFile 27. Set Inputltem = C Set InputNumber = 75 While NOT EOF(GivenFile) Read GivenFile, Item, Number If Inputltem == Item Then Write TempFile, Else Write TempFile, End If End While Close GivenFile, TempFile 28. In the program segment of Exercise 23: a. Give two possible data types for the variable Item, Inputltem, InputNumber Item, Number In Exercises 2 3 - 27, give the contents of the file named update after each program segment is executed. Assume that the content of the file named original at the beginning of each program segment is and that the following statements precede each program segment: Open original For Input As GivenFile Open update For Output As TempFile

Explanation / Answer

The program opens the file and reads {Item,number} pairs.

So, it will first read Item=A and Number=25

Then it reads {C,20} and {E,15} before encountering EOF.

The program opens a temporary output file TempFile where it writes the output using the following code.

If InputItem== Item Then

Write TempFile, InputItem ,InputNumber

Else

Write TempFile, Item ,Number

Note that the value of InputItem is C and InputNumber is 75.

So, it will copy those entries of inputfile whose character field is not C, as they are, to tempfile. But when it reads {C,20} from inputfile, it will see that it matches the InputItem variable and writes {C,75} instead of {C,20}.

So, the contents of the file "update" are:

"A",25<CR>"C",75<CR>"E",15<CR><EOF>