Presentation is loading. Please wait.

Presentation is loading. Please wait.

Files Using Sequential files (Flowchart example) © Juhani Välimäki 2003.

Similar presentations


Presentation on theme: "Files Using Sequential files (Flowchart example) © Juhani Välimäki 2003."— Presentation transcript:

1 Files Using Sequential files (Flowchart example) © Juhani Välimäki 2003

2 Sequential files (in our flowcharts) Serial access: Can be read only from the beginning towards the end. Not possible to move backwards. File opened either for reading (R) or for writing (W). Reading only one record (=data compound) at a time or writing one data compound into the file. If the file was opened for writing it’s contains are emptied and whatever was inside will be lost. © Juhani Välimäki 2003

3 Example – Problem description We have a file called “grades”. It contains names of locations(like “London”) and the annual average temperature in centigrades Now we would like to convert the temperatures to the Fahrenheit-scale for some other marketing area. Names are good as they are (“London”). © Juhani Välimäki 2003

4 Example – Temperature conversion We read from the file “grades”. That file will be opened for reading (R). We read record by record to the data compound variable grade T_GRADE. We convert the centigrades Fahrenheit-degrees using formula F = centigrades * 1.8 + 32. We create a new variable temp T_TEMPERATURE, which will written to the output file. The result will be written to the file “temperatures”. That file was opened for writing (W). © Juhani Välimäki 2003

5 Example – Converter program DEFINITIONS grades sequential file TYPE T_GRADE location AN 20 celsius N 3 grade T_GRADE temperatures sequential file TYPE T_TEMPERATURE city AN 20 fahrenheit N 3 temp T_TEMPERATURE STAR T END READ grades -> grade temp.fahrenheit = grade.celsius * 1.8 + 32 OPEN grades(R), temperatures(W) NOT grades-EOF FALSE TRUE WRITE temp -> temperatures CLOSE grades, temperatures temp.city = grade.location © Juhani Välimäki 2003

6 Example – What happens in the program? grades ”London” ”Helsinki” 10 519”Agadir” ”New York” ”Bruexelles” 2315 117 ”Caraca s””Mani toba” temperatures ”London”50 ”London” 10 ”London” 50 grade T_GRADEtemp T_TEMPERATURE (assignment) temperatures sequential file TYYPPI T_TEMPERATURE city AN 20 fahrenheit N 3 city AN 20 fahrenheit N 3 grades sequential file TYYPPI T_GRADE location AN 20 celsius N 3 location AN 20 celsius N 3 READ WRITE © Juhani Välimäki 2003 (assigning the result of the conversion 10 x 1.8 + 32 = 50)

7 Example – What happens next? grades ”London” ”Helsinki” 10 5 19”Agadir” ”New York” ”Bruexelles” 2315 117 ”Caraca s””Mani toba” temperatures ”London” ”Helsinki” 50 41 ”Helsinki” 5 41 READ WRITE grade T_GRADEtemp T_TEMPERATURE (assignment) (assigning the result of the conversion 5 x 1.8 + 32 = 41) temperatures sequential file TYPE T_TEMPERATURE city AN 20 fahrenheit N 3 city AN 20 fahrenheit N 3 grades sequential file TYPE T_GRADE location AN 20 celsius N 3 location AN 20 celsius N 3 © Juhani Välimäki 2003

8 Real life: Files Files are simplified to make easier programs Might be possible to read and write to the same file. Might be possible to move backwards inside the file. © Juhani Välimäki 2003


Download ppt "Files Using Sequential files (Flowchart example) © Juhani Välimäki 2003."

Similar presentations


Ads by Google