Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

TYPE TstudentRecord

DECLARE name : STRING


DECLARE address : STRING
DECLARE className : STRING
ENDTYPE

DECLARE students : ARRAY OF TstudentRecord

Append a record:
PROCEDURE AppendRecord(student : TstudentRecord)
DECLARE myFile : FILE
myFile = OPEN("student.txt", "APPEND")
ADD student TO students
WRITE myFile, students
CLOSE myFile
ENDPROCEDURE

Find and delete a record:


PROCEDURE DeleteRecord(name : STRING)
DECLARE myFile : FILE
myFile = OPEN("student.txt", "READ")
FOR i FROM 0 TO LENGTH(students) - 1
IF students[i].name == name THEN
REMOVE students[i]
BREAK
ENDIF
ENDFOR
CLOSE myFile
ENDPROCEDURE

Output all the records:


PROCEDURE OutputRecords()
DECLARE myFile : FILE
myFile = OPEN("student.txt", "READ")
FOR i FROM 0 TO LENGTH(students) - 1
PRINT students[i].name, students[i].address, students[i].className
ENDFOR
CLOSE myFile
ENDPROCEDURE

You might also like