Write Algorithm To Update Score In Flat File.

Problem Statement:

A file exists on the disk named students.dat. The file contains several records, and each record contains two fields: (1) the student’s name, and (2) the student’s score for the final exam. Design an algorithm that changes Julie Milan’s score to 100.

Solution:

Start
Declare InFile As File
Declare OutFile As File
Declare Name As String
Declare Score As Integer
Set InFile = "students.dat"
Set OutFile = "students.tmp"
For Each Line From InFile
	Read Next Line
	Split Line by <Tab>
	Set Name = Line[0]
	Set Score = Line[1]
	If "Julie Milan" = Name Then
		Set Score = 100
	End If
	Set Line = Name + "<Tab>" + Score
	Write Line Into OutFile
End For
Close InFile
Close OutFile
Delete InFile
Rename OutFile to InFile
Exit

Comments

Popular posts from this blog