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

In Exercises 23-27, give the contents of the file named update after each progra

ID: 3569684 • Letter: I

Question

In Exercises 23-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 A ,25 C ,20 E ,15 and that the following statements precede each program segment: Open original For Input As GivenFi1e Open update For Output As TempFi1 e End While Close GivenFile, TempFile 27. Set InputItem = C Set InputNumber = 75 While NOT EOF(GivenFile) Read GivenFile, Item, Number If InputItem == Item Then Write TempFile, InputItem, InputNumber Else Write TempFile, Item, Number End If End While Close GivenFile, TempFile In the program segment of Exercise 23: a. Give two possible data types for the variable Item,

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 the entries of inputfile to tempfile whose character field is not C, and when it reads {C,20} from inputfile, it will see that it matches inputitem 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>