Back to: COMPUTER SCIENCE SS2
Welcome to Class !!
We are eager to have you join us !!
In today’s Computer Science class, We will continue from where we stopped last as we learn more about Handling Computer Files. We hope you enjoy the class!
STEPS IN CREATING SEQUENTIAL FILE:
The OPEN statement is used in writing information to a file. In general, the open statement follows this pattern;
OPEN file FOR OUTPUT AS 1
The ‘file’ determines the filename to use
The FOR portion indicates how the file will be accessed or operated; it may be APPEND, BINARY, INPUT, OUTPUT, and RANDOM
The AS is the identifier used for the filehandle in question.
The following opens a file, using mode OUTPUT and number 1, and then saves the text.
10 CLS
20 OPEN “textfile.dat” FOR OUTPUT AS 1
30 PRINT 1, “Hello World”
40 CLOSE 1
50 END
CODE
The combination of all these records forms a file. Thus, a file is a group of related records.
To facilitate the retrieval of specific records from a file, at least one field in each record is chosen as the record key. Usually, the key is unique to every record to avoid duplication of records in a file.
BASIC File Processing statement to read and display files
The table below would be used in a BASIC program. The table would be stored in a file named “EXAMFILE.TXT” the content would be retrieved from the file and output to the screen
|
MATHEMATICS |
ENGLISH |
TOTAL SCORE |
01234 | 50 | 90 | 140 |
01235 | 70 | 40 | 110 |
01236 | 80 | 70 | 150 |
Example
10 CLS
20 OPEN “EXAMFILE.TXT” FOR INPUT AS 1
30 PRINT 1 “MATRIC NO. MATHS ENG. LANG TOTAL SCORE”
40 PRINT 1 “ 0001 50 90 140”
50 PRINT 1 “ 0002 70 40 110”
60 PRINT 1 “ 0003 80 70 150”
70 CLOSE 1
80 OPEN “EXAMFILE.TXT” FOR OUTPUT AS 1
90 DO WHILE NOT EOF(1)
100 INPUT 1, test
110 PRINT test
120 LOOP
130 CLOSE 1
140 END
Note that Free-File function is used to determine the next available filehandle to be used in the OPEN statement. However, in a bigger project that uses many files, Free-file ensures that there are no conflicting File Handles used. It‘s a good practice to use it whenever you‘re not sure of the number of files your program might need to open.
- OPEN “Examfile.txt” for output AS #File Number
This is the line that does the physical opening of file and assigns it #FileNumber as its filehandle. The ‘FOR INPUT’ part tells QuickBasic that you want to open the file in Read mode as you‘ll be reading the contents of the file later in the example.
Next is the loop indicated by the DO WHILE NOT EOF (FileNumber) line. In QuickBASIC EOF () means End Of File. There is also BOF () for Beginning of File and LOF () for Length of File
Since you can’t go backwards on a sequential file, you won’t need BOF () at all.
- The first line Gets a line of data
DESCRIBE FILE INSECURITY
Computer file insecurity refers to the concept that a computer system is vulnerable to attacks and that this fact creates a constant battle between those looking to improve security, and those looking to circumvent security.
EFFECT OF INSECURITY OF FILE
Data loss refers to the unforeseen loss of data or information. An occurrence of data loss can be called Data Loss Event and there are several possible root causes. Backup and recovery schemes are developed to restore lost data.
Overwriting is a process of writing a binary set of data on memory. Overwriting generally occurs when unused file system clusters are written upon with new data. In simple terms, it writes over the previous data.
METHODS FOR FILES SECURITY
Backup
Backup or the process of backing up a file refers to making copies of files so that these additional copies may be used to restore the original after the data loss event.
Backup has two distinct purposes. The primary purpose is to recover data as a reaction to data loss, be it by data deletion or corrupted data. The secondary purpose of backups is to recover data from a historical period of time within the constraints of a user-defined data retention policy.
Antivirus
An anti-virus program protects a computer file from malicious virus attack, detects and heals files that have been attacked. Usually, it consists of a firewall, a virus scanner and remover and sometimes other tools as well.
Password
It is a chosen secret string of characters that allows access to a computer, interface, files etc. The use of a password is at the user’s discretion and caution must be exercised by the user to remember the password always.
Differences between computer files and manual files
Manual is using the old method without the help of the technology or maybe less to perform a certain task or work while; computerized file system is using the latest technology of ICT to carry out various tasks that is more effective when compared with a manual system in terms of the productivity and time usage.
We have come to the end of this class. We do hope you enjoyed the class?
Should you have any further question, feel free to ask in the comment section below and trust us to respond as soon as possible.
In our next class, we will continue learning about File Security. We are very much eager to meet you there.
Ready to make school management and growth easy? Book your free onboarding session now
Get more class notes, videos, homework help, exam practice on Android [DOWNLOAD]
Get more class notes, videos, homework help, exam practice on iPhone [DOWNLOAD]