FILE STRUCTURE AND OPERATIONS


Exercise 5.1
REM A program written in Visual BASIC to read data from a data file "file1.txt" and display the student ID and marks on the screen.

Private Sub Form_Activate()
Dim Name As String
Dim m1, m2, m3, m4, m5, m6 As Integer
Open "c:\WINDOWS\Desktop\file1.txt" For Input As #1
Do While Not EOF(1)
Input #1, Name, m1, m2, m3, m4, m5, m6
Print Name; m1; m2; m3; m4; m5; m6
Loop
Close #1
End Sub



Exercise 5.2
Modify the program in Exercise 5.1 to calculate the average mark for each student.


Exercise 5.3
Modify the program in Exercise 5.2 to include a subroutine to calculate the average.
Private Sub CalculateAverage(avrg, mk1, mk2, mk3, mk4, mk5, mk6)
Sum = mk1 + mk2 + mk3 + mk4 + mk5 + mk6
avrg = Sum / 6
End Sub



Sample data:
"Peter Parker",90,90,92,94,96,96
"Clark Kent",82,86,86,89,83,84
"Xena",80,91,93,94,96,96
"Steve Martin",42,60,53,54,53,65
"Jessica Simpson",76,75,72,78,78,77
"Lois Lane",88,87,96,54,90,100
"Sam Smith",50,91,83,94,96,96
"Alex Cornel",72,70,53,84,53,65
"Jimmy Nail",86,75,52,78,79,77
"Mandy Olsen",98,37,96,54,90,80
"Christopher Pan",68,77,90,84,98,90



Hosted by www.Geocities.ws

1