A Corner for Computer Learners

Common file system operations supported by QBASIC are:

	CHDIR, MKDIR, RMDIR, FILES, NAMES…AS and KILL.
CHDIR: to change the default directory
		e.g. CHDIR "D:\Home" 
MKDIR: to create a new directory
		e.g. MKDIR "D:\MyFolder"
RMDIR: to remove the existing directory
		e.g. RMDIR "D:\MyFolder"
FILES: to display file name in current directory
		e.g. FILES "*.BAS"  [lists all the file with extension 'BAS']
NAME…AS: to rename the file
		e.g. NAME "Home" AS "School" [changes the file 'Home' to 'School']
KILL: to delete files
		e.g. KILL "info.dat"
 
Modes to open file
Files are opened to enter data, to add more data and retrieve data from the file 
Syntax to open file
OPEN [file_name] FOR [mode] AS [file_number]
Here,
	Mode: INPUT, OUTPUT, APPEND
	File number=#1 to #255
. 
There are 3 different modes to open the file in Qbasic: 
1.	Output Mode: Files are opened in output mode to create a file and enter data in the file
OPEN [file_name] FOR OUTPUT AS [file_number]
2.	Append Mode: Files are opened in output mode to add more records in an existing file 
OPEN [file_name] FOR APPEND AS [file_number]
3.	Input Mode: Files are opened in  input  mode view data from tabl 
OPEN [file_name] FOR APPEND AS [file_number]

Some Programs in File Handling

1.  create a file 'school.txt' and enter 5 records 
2.  create a file 'school.txt' and store records till user wants
3. A data file "school.txt" contains some records with students' name and marks in math, science and english. Write program to 
   a. add 3 more records in the file  
   b.  add more records in the file on user's choice
   c.  display all records
   d. to display the records of student whose name is supplied by the user
   e. display all records with total and percentage
   f. to display the records of passed students with total and percentage if the pass mark in 
   each subject is 40
   g. to copy all the records of 'school.txt' file to new file 'marks.txt' with total 
   and percentage
4. A data file 'rate.txt' has some records of items with item name, qty and rate. 
Write a program to increase the rate of all items by 10% 

Practice Yourself

 
1.	WAP to create a file "patient.dat" to store name, address, gender, age and date of admission of patients.
2.	WAP to add more records in the file
3.	WAP to display all the records.
4.	WAP to search the records of patients whose name is supplied by user and display the record. 
5.	WAP to display records of all patients whose name starts with 'R'.
6.	WAP to count and display records of all female patients.
7.	WAP to display records of all patients admitted on 'April'.
8.	WAP to modify the records of all patients with new field 'illness'.
9.	WAP to display the records of all patients suffered from TB and display the total number.
10.	WAP to copy all the records to new file 'hospital.dat'
11.	WAP to change the illness of 'mental' to 'psycho'.
	hints:
	Input #1, n$, …… i$
	If ucase$(i$)="MENTAL" i$="Psycho"
	Write #2, n$, ………. I$
12.	WAP to delete the records of 'psycho' patients.



© All rights reserved to Niraj Balami