![]() I tell them that they are reading from a text file named 'data.txt' and that the format of the data is John#Smith#50 which needs to be read into three parallel arrays declared as with arrName and arrSurname being string and arrMark being an integer. As soon as a learner gets full marks they do not need to write again but those that did not will continue to do so everyday until they also get full marks. It does not take long to mark as you can stop the moment you find a mistake. Before they switch their computers on I give them a piece of paper and they have to write the code from testing if the file exists up to the CloseFile(tFile) until they get full marks. Their homework is to study this code and then write a written test every day until they get full marks. Using the pos, copy, delete method to read from the text file works in all scenarios. First step is to write a Procedure to ReadFromFile.I use one very large program to code many examples together.Remember that iCount will be global and may not be re-declared as a local variable or you will lose its contents.If you use the method of setting iCount to 1 before the loop your counter will be one higher than the number of items in your array which will be needed in another event. It is best to start with your iCount as 0 and inc(iCount) before you add a value to the array.For example: while not eof(tFile) and (iCount < 30) do If an array is declared as your while loop needs to test, using the counter, that it does not exceed this number.It was mentioned that learners have to test if the file exists even if the paper does not ask you to do so.I find that I save some time teaching arrays and text file together from the start. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |