Connect Me

twitterfacebookgoogle plus email

  Instagram View Biwas Bhattarai's profile on LinkedIn
Showing posts with label File handling in qbasic. Show all posts
Showing posts with label File handling in qbasic. Show all posts

WAP to create a data file "Book.txt"

1)WAP to create a data file "Book.txt" and enter book name, author name, price, published year, and language used. Ask user to continue for next record.
2) WAP to display records from "Book.txt", where language used is "Nepali"
3) WAP to display records from "Book.txt", where price of a book is between 500 to 1000.
4) WAP to display records from "Book.txt", where published year is 2015 and author name starts with letter "N"
5) WAP to copy records from "Book.txt" to "Eng.txt" file where language used is "English"

1)
OPEN "BOOK.TXT" FOR OUTPUT AS #1
CLS
DO WHILE UCASE$(CH$)="Y" 
INPUT "ENTER BOOK NAME";BN$INPUT "ENTER AUTHOR NAME";AN$
INPUT "ENTER PRICE"; P
INPUT "ENTER PUBLISHED YEAR"; PY
INPUT "ENTER LANGUAGE OF THE BOOK";L$
WRITE #1, BN$, AN$, P, PY, L$
INPUT "DO YOU WANT TO ADD MORE (Y/N)"; CH$
LOOP
CLOSE #1
END

2)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF UCASE$(L$)="NEPALI" THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

3)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF P>=500 AND P<=1000 THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

4)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
N$=LEFT$(AN$,1)
IF PY=2015 AND UCASE$(N$)="N" THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

5)
OPEN "BOOK.TXT" FOR INPUT AS #1
OPEN "ENG.TXT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF UCASE$(L$)="ENGLISH" THEN
WRITE #2, BN$, AN$, P, PY, L$ 
END IF
WEND
CLOSE #1
CLOSE #2
END

Original file is BOOK.TXT. All records with language as ENGLISH will be copied to new file ENG.TXT.
WRITE #2, BN$, AN$, P, PY, L$ will copy into #2, which mean ENG.TXT file.

WAP to create a data file “info.dat” and enter the following details for 5 students.

WAP to create a data file “info.dat” and enter the following details for 5 students.
a. Name
b. Address
c. Class
d. Roll number
e. Section
f. House


OPEN "info.dat" FOR OUTPUT AS #1
FOR I=1 TO 5
INPUT "Enter your name "; n$
INPUT "Enter your address "; ad$
INPUT "Enter your class "; cl
INPUT "Enter your roll number "; rn
INPUT "Enter your Section "; s$
INPUT "Enter your House "; h$
WRITE #1, n$, ad$, cl, rn s$, h$
NEXT I
CLOSE #1
END

Create a data file to copy the records of all employee.

Solution:

CLS

OPEN "EMPLOYEE.DAT" FOR INPUT AS #1

OPEN "COPY.DAT" FOR OUTPUT AS #2


Create a data file to display the records with the students name starting with "B"

Solution:

REM PROGRAM DISPLAYING THE NAMES OF STUDENTS STARTING WITH LETTER "B"

CLS

OPEN "MARKS.DAT" FOR INPUT AS #1

DO WHILE NOT EOF(1)

File Handling in Qbasic

QBasic Program display only the list of pass student

CLS
OPEN "RESLUT.TXT" FOR INPUT AS #1
PRINT "RN", "NAME", "ENGLISH","NEPALI", "MATHS"
WHILE NOT EOF (1)
INPUT#1, RN,N$,ENG,NEP,MAT
IF ENG>=40 AND NEP>=40 AND MAT>=40 THEN
PRINT RN, N$, ENG, NEP, MAT
END IF
WEND
CLOSE #1
END

Ą
https://www.flickr.com/photos/spklg/15211044551/