David W. answered 08/15/17
Tutor
4.7
(90)
Experienced Prof
Declare an array: R$(5)
Initialize array R$(x) elements to ""
Open data file for input [note: use record mode]
On ENDFILE GOTO Finish
Loop forever:
READ Record A$
REM keep most recent five records
R$(5)=R$(4)
R$(4)=R$(3)
R$(3)=R$(2)
R$(2)=R$(1)
R(1) = A$
NEXT for continuous loop
Finish:
Close File R$
FOR I = 1 TO 5 // you may want to make this 5 TO 1 STEP -1
PRINT ( R$(I) )
NEXT I
Soumya S.
can you plz code it for me ?? my file "student.bas" contains name, class and roll no. of students.
Report
08/15/17
David W.
This is pseudocode.
Many of the statements are actually valid BASIC.
The best plan is to start small -- with a working program -- then add small increments (it's called the Spiral Process). For example:
Write a program that:
1. opens your file and prints the first line.; close file
2. opens your file and stores each line in a 1-element array; check for EOF and print the one line; close file
3. do the same for a 2-element array
4. do the same for a 5-element array
5. determine the order of the "last file" that you want; consider a file size of less than 5 records
Report
08/15/17
Soumya S.
08/15/17