An algorithm will output the last three lines from a text file Result.txt
The lines need to be output in the same order as they appear in the file.
Assume:
Three variables
LineX, LineYandLineZwill store the three lines. These are of type string and all three variables have been initialised to an empty string.The file exists and contains at least three lines.
The algorithm to output the lines is expressed in eight steps.
Complete the steps.
Open the file ...........................................................................
Loop until ...........................................................................
........................................................................... and store in
ThisLineAssign
LineYtoLineXAssign
LineZtoLineYAssign
ThisLinetoLineZAfter the loop, ...........................................................................
Output
LineX, LineY, LineZ
The requirement changes, and the algorithm will now output three lines from the file, starting from a given line number.
The modified algorithm will be implemented as a function which will:
be called with an integer parameter representing the given line number
output three lines, starting at the given line
return
TRUEif the 3 lines are output, orFALSEif it was not possible to output the 3 lines.
Describe the changes that need to be made to steps 2 to 8 of the algorithm given in part (a).
Did this page help you?