QBASIC, a fundamental programming language taught in many Class 10 computer science curriculums, offers powerful capabilities for file handling. Understanding how to manipulate files is essential for any programmer, and QBASIC provides an excellent platform to learn these concepts. In this article, we'll delve into important questions with their codes of QBASIC file handling, its importance, and how Class 10 students can master this aspect of programming.
QBASIC file handling is a fundamental aspect of programming that Class 10 students should master. By understanding how to create, read, write, and manage files in QBASIC, students develop essential skills that are applicable across various programming languages and real-world scenarios. Through practice and experimentation, students can gain confidence in their ability to manipulate data effectively using QBASIC file handling techniques.
Very Important Function....End Function QBASIC Programming(Turn on Desktop Mode for Better View)
1. Write a program to create a sequential data file named "record.txt" and store Roll number, Name, Address, and Class of a student.
OPEN "record.txt" FOR OUTPUT AS #1 CLS INPUT "Enter roll, name, address, and class of a student: "; r, n$, a$, c WRITE #1, r, n$, a$, c CLOSE #1 END
2. Write a program to create a sequential data file named "record.txt" and store Roll number, Name, Address, and Class of few students.
OPEN "record.txt" FOR OUTPUT AS #1 CLS DO INPUT "Enter roll, name, address, and class of a student: "; r, n$, a$, c WRITE #1, r, n$, a$, c INPUT "Do you want to continue? "; x$ LOOP WHILE UCASE$(x$) = "Y" CLOSE #1 END
3. Write a program to add few more records in a data file named "record.txt" which contains Roll number, Name, Address, and Class of students.
OPEN "record.txt" FOR APPEND AS #1 CLS DO INPUT "Enter roll, name, address, and class of a student: "; r, n$, a$, c WRITE #1, r, n$, a$, c INPUT "Do you want to continue? "; x$ LOOP WHILE UCASE$(x$) = "Y" CLOSE #1 END
4. Write a program to display all the records from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c PRINT r, n$, a$, c LOOP CLOSE #1 END
5. Write a program to display only those records whose name starts with "K" from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF LEFT$(UCASE$(n$), 1) = "K" THEN PRINT r, n$, a$, c END IF LOOP CLOSE #1 END
Write a program to display only those records who live in "POKHARA" from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF UCASE$(a$) = "POKHARA" THEN PRINT r, n$, a$, c END IF LOOP CLOSE #1 END
7. Write a program to count and display only those records who study in class 10 from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF VAL(c) = 10 THEN PRINT r, n$, a$, c END IF LOOP CLOSE #1 END
8. Write a program to display only those records whose roll number is in the range from 20 to 30 from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF r >= 20 AND r <= 30 THEN PRINT r, n$, a$, c END IF LOOP CLOSE #1 END
9. Write a program to count only those records who don't live in "POKHARA" from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 CLS COUNT = 0 DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF UCASE$(a$) <> "POKHARA" THEN COUNT = COUNT + 1 END IF LOOP CLOSE #1 PRINT "Number of students not living in POKHARA: "; COUNT END
10. Write a program to delete all those records whose address is "KATHMANDU" from the data file named "record.txt" which contains Roll number, Name, Address, and Class of several students.
OPEN "record.txt" FOR INPUT AS #1 OPEN "temp.txt" FOR OUTPUT AS #2 CLS DO WHILE NOT EOF(1) INPUT #1, r, n$, a$, c IF UCASE$(a$) <> "KATHMANDU" THEN PRINT #2, r, n$, a$, c END IF LOOP CLOSE #1 CLOSE #2 KILL "record.txt" NAME "temp.txt" AS "record.txt" END
Q) A sequential data file named "result.doc" contains Roll number, Name, Class and Marks obtained in 5 different subject i.e Maths, Science, English, Nepali, Computer. Let us consider Pass mark to be 40 and Full mark to be 100 then answer all the following questions.
1. Display all the names of students who failed in any one or more of the subjects:
OPEN "result.doc" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, roll, name$, class$, maths, science, english, nepali, computer IF maths < 40 OR science < 40 OR english < 40 OR nepali < 40 OR computer < 40 THEN PRINT name$ END IF LOOP CLOSE #1 END
2. Count total number of students who passed in all the subjects:
OPEN "result.doc" FOR INPUT AS #1 CLS pass_count = 0 DO WHILE NOT EOF(1) INPUT #1, roll, name$, class$, maths, science, english, nepali, computer IF maths >= 40 AND science >= 40 AND english >= 40 AND nepali >= 40 AND computer >= 40 THEN pass_count = pass_count + 1 END IF LOOP CLOSE #1 PRINT "Total number of students passed in all subjects: "; pass_count END
3. Calculate and display percentage of all the students along with the roll number and name:
OPEN "result.doc" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, roll, name$, class$, maths, science, english, nepali, computer total_marks = maths + science + english + nepali + computer percentage = (total_marks / 500) * 100 PRINT "Roll No: "; roll; ", Name: "; name$; ", Percentage: "; percentage; "%" LOOP CLOSE #1 END
4. Display name of the students who failed only in English and Nepali:
OPEN "result.doc" FOR INPUT AS #1 CLS DO WHILE NOT EOF(1) INPUT #1, roll, name$, class$, maths, science, english, nepali, computer IF english < 40 AND nepali < 40 AND maths >= 40 AND science >= 40 AND computer >= 40 THEN PRINT name$ END IF LOOP CLOSE #1 END
5. Delete all the records of students who failed in any one or more of the subjects:
OPEN "result.doc" FOR INPUT AS #1 OPEN "temp.doc" FOR OUTPUT AS #2 CLS DO WHILE NOT EOF(1) INPUT #1, roll, name$, class$, maths, science, english, nepali, computer IF maths >= 40 AND science >= 40 AND english >= 40 AND nepali >= 40 AND computer >= 40 THEN PRINT #2, roll, name$, class$, maths, science, english, nepali, computer END IF LOOP CLOSE #1 CLOSE #2 KILL "result.doc" NAME "temp.doc" AS "result.doc" END
to create menu driven program for handling the following cases. case1:to store name ,age and address in to "Menu.dat" file. case2:to read and display all the data from "menu.dat" file. case3:to add five more persons data in the "menu.dat" file. case4:to quit the program
ReplyDeleteIf you have any doubts, Please let me know