Write a program to store Roll no., Name, Class and Address of any five students.
OPEN "Student.dat" FOR OUTPUT AS #1
FOR I = 1 TO 5
INPUT "Enter Roll No."; r
INPUT "Enter Name"; n$
INPUT "Enter Class"; c
INPUT "Enter Address"; a$
WRITE #1, r, n$, c, a$
NEXT I
CLOSE #1
END
A sequential data file called “student.dat” contains same records under the field’s name, english, nepali and computer. Write a program to add some more records in the same sequential data file. [SLC 2068]
OPEN “student.dat” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS IN ENGLISH”; E
INPUT “ENTER MARKS IN NEPALI”; N
INPUT “ENTER MARKS IN COMPUTER”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
A sequential data file “RECORD.DAT” contains records of Name, Address and Salary of employees. WAP to add some more records in the data file “RECORD.DAT”. Program should terminate with user choice.
OPEN “RECORD.DAT” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS IN ENGLISH”; E
INPUT “ENTER MARKS IN NEPALI”; N
INPUT “ENTER MARKS IN COMPUTER”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields. [SEE 2073]
OPEN “std.rec” FOR OUTPUT AS #1
TOP:
CLS
INPUT “Enter Name”; N$
INPUT “Enter Address”; A$
INPUT “Enter Post”; P$
INPUT “Enter gender”; G$
INPUT “Enter Salary”; S
WRITE #1, N$, A$, P$, G$, S
INPUT “Do you want to continue”; CH$
IF UCASE$(CH$)=”Y” THEN GOTO TOP
CLOSE #1
END
Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total amount(total=Quantity X Rate).Program should terminate according to the user’s choice.
OPEN “price.dat” FOR OUTPUT AS #1
TOP:
CLS
INPUT “Enter Item Name”; N$
INPUT “Enter Quantity”; Q
INPUT “Enter Rate”; R
T = Q * R
WRITE #1, N$, Q, R, T
INPUT “Do you want to continue”; CH$
IF CH$=”Y” OR CH$ = “y” THEN GOTO TOP
CLOSE #1
END
A sequential data file “Address.inf” contains serial no, name, address, telephone and email_id.WAP to record as many records as the user wants. The serial number should be generated automatically like 5001,5003,5005.
OPEN " Address.inf " FOR OUTPUT AS #1
DO
CLS
C = 5001
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER TELEPHONE”; T#
INPUT “ENTER EMAIL”; E$
WRITE #1, C, N$, A$, T$, E$
C = C + 2
INPUT “DO YOU WANT TO CONTINUE (Y / N)”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
A Sequential data file called "SEE.DAT" has stored data under the field heading Symbol No., Name, English, Nepali, and Computer. Write a program to display all the information of those students whose marks in Computer is more than 80.
OPEN "SEE.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A, B$, C, D, E
IF E > 80 THEN PRINT A, B$, C, D, E
WEND
CLOSE #1
END
Write a program to read all the records from the data file “STUDENT.TXT” and display all the records where the fields name are unknown.
OPEN "STUDENT.TXT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
LINE INPUT #1, A$
PRINT A$
WEND
CLOSE #1
END
A data file “INFO.DAT” has numerous records in it with name, address age, and telephone numbers in it. Write a program to read all the records and print those with address “NEPAL” and age >15
OPEN "INFO.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C, D
IF UCASE$(B$) = “NEPAL” AND C >15 THEN PRINT A$, B$, C, D
WEND
CLOSE #1
END
A data file “lib.txt” consists of book’s name, author’s name and price of books. Write a program to count and display the total number of records present in the file.
OPEN "LIB.TXT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C
D = D + 1
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; D
CLOSE #1
END
A sequential data file called 'ADDRESS.DAT' contains NAME, AGE, CITY and TELEPHONE fields. Write a program to display all the contents of that data file.
OPEN "ADDRESS.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B, C$, D
PRINT A$, B, C$, D
WEND
CLOSE #1
END
Write a program in QBASIC to open a sequential data file “EMP.DAT”, which contains employees records: Name, address and phone number and display all the records as well as total number of records stored in the file.
OPEN "LIB.TXT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C
PRINT A$, B$, C
D = D + 1
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; D
CLOSE #1
END
A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write a program to count total number of “Manager” in the data file. (hint: Manager is a post)
OPEN "EMP.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
IF UCASE$(P$) = “MANAGER” THEN PRINT C = C + 1
WEND
PRINT “TOTAL NO.OF MANAGERS ARE”; C
CLOSE #1
END
A data file “Salary.Dat” contains the information of employee regarding their name, post and salary. Write a program to display all the information of employee whose salary is greater than 15000 and less than 40000.
OPEN "EMP.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
IF S >= 15000 AND S <= 40000 THEN PRINT N$, P$, S
WEND
CLOSE #1
END
A sequential data file “emp.dat” contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount (also tax is 15% of salary).
OPEN "EMP.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
T = 15 / 100 * S
PRINT N$, P$, S, T
WEND
CLOSE #1
END
Write a program that reads the ”INFO.DAT” file that has several record such as name, address, gender, post, and salary .The program display those record whose sex is male and salary more than 10,000 and also the program counts the total number of records in that file.
OPEN "INFO.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, A$, G$, P$, S
C = C + 1
IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; C
CLOSE #1
END
A sequential data file’post.dat’ has few records related to name, address, salary.WAP to display the records whose address begins with ‘S’ or ‘D’
OPEN "POST.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
A$ = UCASE$(LEFT$(N$,1))
IF A$ = “S” OR A$ = “D” THEN PRINT N$, P$, S
WEND
CLOSE #1
END
0 Comments