Friday, August 9, 2024

(3.2) File processing (file handling)

 

(3.2) File processing (file handling)

File

The collection of different data or information or instructions, which is stored in secondary storage devices under a unique file name, is known as file

 

File handling

File handling is a process to create a data file, write data to the data file and read data from the specified data file.

 

Data file

Data file is a collection of data such as name, address, class, etc. required for data processing.

The different types of data file are:

a)     Sequential Access files - Sequential Access to a data files means that the computer system reads or writes information to the file sequentially, starting from the beginning of the file and proceeding step by step.

b)     Random access files - Random Access to a file means that the computer system can read or write information anywhere in the data file.

 

Program File

The set of instruction written in a computer language for data processing under unique file name is known as program file.

 

Mode of data file

Mode of data file means opening a sequential file for one of the three modes of operation like output mode, input mode and append mode.

 

Modes of operation for opening a sequential file

a)     Output Mode: It is used to create a new sequential data file and write data in it. If the file already exists its current contents will be destroyed. It starts writing data always from the beginning of the file (BOF).

b)     Input Mode: It is used to read / display data or information from the existing sequential data file.

c)     Append Mode: It is used to add more records in the existing sequential file.. If the specified file does not exist APPEND mode creates it. It starts adding of data always from the end of the file (EOF).

 

File number

The number assigned to a file in order to identify it during processing is called file number.

 

Write down the functions of:

 

OPEN statement: It opens a sequential file for one of the three possible operations (reading, writing, appending).

 

WRITE statement: It writes data to a sequential file. It inserts commas between the data items. It encloses strings in double quotation marks.

 

PRINT#: It writes data to a sequential file It adds spaces between data items while storing data. It does not enclose strings in double quotation marks.

 

CLOSE statement : It closes one or all open files.

 

INPUT# statement: It reads data items from a sequential file and assigns them to variables.

 

EOF( ) function: It is used to check whether the record pointer reaches at end of file or not.

LINE INPUT statement: It reads an entire line without delimiters from a sequential file to a string variable.

 

INPUT$ function: It returns a string of characters read from the specified file.

 

NAME statement : The NAME statement changes the name of a disk file or directory

 

KILL statement : The KILL statement  deletes a file.

 

MKDIR statement : It creates a new directory..

 

CHDIR statement: It changes the current default directory for the specified drive.

 

RMDIR statement : It remove an existing empty directory.

 

FILES statement: The FILES statement displays the list of files residing on the specified disk.

 

SHELL: The SHELL statement executes a DOS command.

 

SYSTEM : This command is used to close QBASIC program window

 

INT ( ) : It rounds and returns the largest integer less than or equal to a numeric expression.

PRINT  : Display result on screen.

MID$ ( ) : t is a string function that returns the specified number of characters from the specified location of string.

LEN ( ): Returns the number of characters in a string or the number of bytes required to store a variable.

SQR ( ) : Returns the square root of a numeric expression.

Qbasic Operators

Operators are special symbols that are meant for specific tasks or operators.

i) Arithmetic operators

ii) Relational operators

iii) Logical Operators

iv) String operator

Static variable

The variable which is declared by using the “STATIC” keyword is called static variable.

Comparing C and QBASIC language

 

QBASIC

C

It is a high level language without feature of low level language.

It is a high level language with some features of low level language.

It is mostly used to design application software.

It is mostly used to prepare system software.

It supports structure programming with sub and function procedure.

It is a structured programming language with function procedure.

It is not case sensitive

It is case sensitive

IBM PC version of BASIC has around 159 keywords.

It has only 32 keywords.

What is the function of MOD in Qbasic?

The function of MOD in Qbasic is to find remainder.

What is the function of SQR in Q-Basic?

The function of SQR in Q-Basic us to calculate the square root of a given number.

No comments:

Post a Comment