Chapter 5 Assignment Page 2

Automatic end of file loop

An automatic end of file loop uses an end of file marker to tell the computer system when it is time to exit the loop.

To create a properly formed automatic end of file loop you must:

    1. Read the first input record.
    2. Check for the end of file marker. This performs error checking and checks for an empty file. If the first record in the file is the end of file marker, then the file is empty and an error message should be printed. If the first record in the file is not the end of file marker, then processing is continued.
    3. Process the record that was read.
    4. Print any necessary output.
    5. Read the next record. (These steps from step 2 are followed until the end of file marker is read.)
NOTE: The problem below walks through an example of an automatic end of file problem that will simply read a record and print the output. This will allow you to focus on the loop and not focus on processing the problem. Walk through the steps the computer will perform using a memory diagram.

Input File (Name and Age)

wpe27.gif (1008 bytes)
 
 

NOTE: Remember the automatic end of file marker is a nonprintable character. To check for the end of file marker, you use the key phrase EOF, which stands for End Of File. Computer languages that support automatic end of file recognize the key phrase EOF.

Pseudocode Example:

wpe26.gif (1008 bytes)
 
 

Flowchart Example:

wpe25.gif (4674 bytes)




Exercises:

Problem 9 – Place the processing for the totals within the nested if statement. Do not place all the processing statements after the if statement.

Problem 11 – This is a good problem to practice totals and averages.

Problem 12 – Although this problem is short, it becomes an involved problem. It includes many totals and averages. It takes the students a long time to solve this problem.

Problem 16 – Although this problem is lengthy, it is easy to solve. This is a good problem to practice nested if statements and totals. You may want to save this problem for a practice problem for the final exam.

Multi-page reports
Pseudocode Example:

wpe28.gif (1008 bytes)

wpe24.gif (7565 bytes)

Exercises: (These problems are not required for the course, but it is an important programming topic)

Problems 9, 10, 11 – The students will take designs they have already solved and add the statements necessary to print multi-page headings. Each problem should take about 15 – 20 to complete.