Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Thursday, February 17, 2022

INPUT mode in File Handling

 Solved examples of INPUT mode 

in File Handling


1. Write a program in QBASIC to open a sequential data file “WMP.DAT” which contains the name, address and phone number of employee and display all the records as well as total number of records stored in the file. (SLC 2064)

OPEN “EMP.DAT” FOR INPUT AS # 1

CLS

P=0

PRINT "Name", "Address", "Phone"

WHILE NOT EOF(1)

INPUT #1, n$, a$, p$

PRINT n$, a$, p$

P=p+1

WEND

PRINT “Total number of records=”;p

CLOSE #1

END

 

2. A  data file "MARKS.DAT" contains fields of Roll.no, Name, English, Nepali and Maths. WAP to print all the contents of the data file. (SLC supplementary 2065)

OPEN "MARKS.DAT" FOR INPUT AS #1

CLS

PRINT "Roll no", "Name", "English", "Nepali", "Maths"

DO WHILE NOT EOF(1)

INPUT #1, r, n$, e, n, m

PRINT r, n$, e,n,m

LOOP

CLOSE #1

END

 

 3. A data file "LIB.TXT" consists of Book's name, Author's name and price of books. Write a program to count and print the total number of records present in the file. (SLC supplementary 2066)

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

c=0

PRINT "Books name", "Authors name", "Price"

DO WHILE NOT EOF(1)

INPUT #1, b$,a$,p

c=c+1

LOOP

PRINT "Total number of records=";c

CLOSE #1

END

 

4. A sequential data file "EMP.DAT" contains name, post and salary fields of information about employees. WAP to display all the information of employees along with tax amount. (Tax is 15% of salary) (SLC 2067)

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1, n$, po$, sal

ta = (sal * 15) / 100

PRINT n$, po$, sal, ta

LOOP

CLOSE #1

END

 

 5. A data data file "information. dat" have contains name, address and phone no. WAP to display all the information whose address is Hasanpur or Taranagar.

CLS

OPEN "information.dat" FOR INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1,n$,a$,p

IF a$="Hasanpur" or a$="Taranagar" THEN

PRINT "Name=";n$

PRINT "Address=";a$

PRINT "Phone no=";p

ENDIF

LOOP

CLOSE #1

END

 

6. A data file named "salary.dat" contains name, designation and salary of employees. WAP to display all the employees record whose salary is between 10000 to 15000.

CLS

OPEN "salary.dat" FOR INPUT as #3

DO WHILE NOT EOF(3)

INPUT #3, n$,d$,s

IF s>=10000 and s<=15000 THEN

PRINT "Name="n$

PRINT "Designation=";d$

PRINT "Salary=";s

ENDIF

LOOP

CLOSE #3

END

 

7. A sequential data file "result.dat" contains name and marks secured by students in 3 subjects. Assuming that pass marks of each subjects is 40, write a program to count the number of passed students.

OPEN "result.dat" FOR INPUT AS #2

DO WHILE NOT EOF(2)

INPUT #2, n$,e,m,c

IF e>=40 and m>=40 and c>=40 THEN

p=p+1

ENDIF

LOOP

CLOSE #2

PRINT "Total number of passed students=";p

END

 

8. A sequential data file “information.dat” contains name, address and phone number of the students. WAP to enter a telephone number from the keyboard, match the telephone number with the telephone number stored in the file. If the telephone number matched then display “Record found” otherwise display “Record not found”

OPEN “information.dat” FOR INPUT AS#1

CLS

INPUT “Enter telephone number=”;tel$

WHILE NOT EOF(1)

INPUT #1, n$, a$, ph$

IF(ph$=tel$) THEN

PRINT “Record found”

ELSE

PRINT “Record not found”

ENDIF

PRINT “Name=”;n$

PRINT “Address=”;a$

PRINT “Telephone number”;ph$

WEND

CLOSE #!

END

 

 9. A sequential data file called “marks.dat” contains fields name, English, Neplai, Maths and Science fields. Write a program to print all the contents of that data file.  (SLC 2070)

OPEN “marks.dat” FOR INPUT AS #1

CLS

PRINT “Name”, “English”, “Maths”, “Science”, “Nepali”

WHILE NOT EOF(1)

INPUT #1, n$, eng, math, sci, nep

PRINT n$, eng, math, sci, nep

WEND

CLOSE #1

END

 

10. A sequential data file called “Marks.dat” contains Roll no, Name, English, Nepali, and Maths fields. Write a program to print all the contents of the data file.  (SLC 2067 Supp.)

OPEN “marks.dat” FOR INPUT AS #1

CLS

PRINT “Roll no”,“Name”, “English”, “Maths”, “Science”, “Nepali”

DO WHILE NOT EOF(1)

INPUT #1, r, n$, eng, math, sci, nep

PRINT r, n$, eng, math, sci, nep

LOOP

CLOSE #1

END

 

11. WAP to view those records from “employee.dat” sequential data file having employee’s name, department, appointment data and salary whose salary is more than Rs 5000. (SLC 2068 Supp.)

OPEN “employee.dat” FOR INPUT AS #2

CLS

WHILE NOT EOF(2)

INPUT #2, n$,d$,a$,s

IF s>=5000 THEN PRINT n$,d$,a$,s

WEND

CLOSE #2

END

 

 12. A sequential data file “staff.dat” contains the name, address, post and salary of employees. Write a program to read and display all the records in the above data file. (SLC 2069 Supp.)

OPEN “staff.dat” FOR INPUT AS #1

CLS

PRINT “Name”, “Address”, “Post”, “Salary”

DO WHILE NOT EOF(1)

INPUT #1, n$,a$,p$,s

PRINT n$,a$,p$,s

LOOP

CLOSE #1

END

 

13. 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 25000 and less than 40000 (SLC 2071)

OPEN “salary.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1 n$,p$,sa

IF sa>25000 AND sa<40000 THEN

PRINT “Name”;n$

PRINT “Post”;p$

PRINT “Salary”;sa

ENDIF

LOOP

CLOSE #1

END

 

14. A sequential data file “record.dat” has records with field name, address, age and salary. Write a program to display only those records whose age is greater than 26.  (SLC 2070 Supp.)

OPEN "record.dat" FOR INPUT AS #1

PRINT "Name", "Address", "Age", "Salary"

DO WHILE NOT EOF(1)

INPUT #1, n$, a$,age, sal

IF age>26 THEN PRINT n$,a$,age,sal

LOOP

CLOSE #1

END

 

15. A sequential data file “Employee.rec” consists of numerous records of employees of a company on the following fields: employee’s name, post, salary and status (i.e. permanent or temporary) Write a program to read records of the “Employee.rec” file and display the records of permanent employees whose post is manager.

OPEN “Employee.rec” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, P$, S, S$

IF UCASE$(P$)= “MANAGER” AND UCASE$(S$)= “PERMANENT” THEN PRINT N$, P$, S, S$

WEND

CLOSE #1

END

 

16. Data file named “RECORD.DAT” contains name, age and salary for ‘n’ number of persons. Write a program to input a name to search data from data file. If the data is not found, then display the message “Data not found in the list.”

OPEN “RECORD.DAT” FOR INPUT AS #1

CLS

INPUT “Enter name to search data”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, A, S

IF UCASE$(S$)=UCASE$(N$) THEN

PRINT N$, A, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “DATA NOT FOUND”

CLOSE #1

END

                                                                                                                                             

17. A sequential data file called “Marks.dat” contains NAME, AGE, CITY, and TELEPHONE fields. Write a program to display all the contents of the data file. (SEE 2072)

OPEN “Marks.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1, N$, A, C$, T#

PRINT N$, A, C$, T#

LOOP

CLOSE #1

END

 

18. A sequential data file called "ADDRESS.DAT" contains NAME, AGE, CITY and TELEPHONE fields. Write a program to display all the contents of the data file. (SEE 2073 Supp.)

OPEN "ADDRESS.DAT" FOR INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1, na$,ag,c$,tel$

PRINT na$,ag,c$,tel$

LOOP

CLOSE #1

END

 

19. A data file “STAFF.dat” has stored records of few employees with ID, First name, sur name, post and salary. WAP to display all the records of the employees whose salary is greater than 40,000.  (SEE 2075)

OPEN “SALARY.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1, ID, Ba$, Ca$, Da$, E

IF E > 40000 THEN PRINT ID, Ba$, Ca$, Da$, E

LOOP

CLOSE #1

END

 

20. A sequential data file “Employee.rec” consists of numerous records of employees of a company on the following fields: employee’s name, post, salary and status (i.e. permanent or temporary) Write a program to read records of the “Employee.rec” file and display the records of permanent employees whose post is manager.

OPEN “Employee.rec” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, P$, S, S$

IF UCASE$(P$)= “MANAGER” AND UCASE$(S$)= “PERMANENT” THEN PRINT N$, P$, S, S$

WEND

CLOSE #1

END

 

 21. A hospital keeps name, age and gender of his patients in a sequential data file “paitent.txt”. WAP to display all the records whose gender is male.

OPEN “paitent.txt” FOR INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1, n$,a,g$

IF UCASE$(g$)=”MALE” THEN PRINT n$,a,g$

LOOP

CLOSE #1

END

 

22. A data file “result.txt” has the field’s students name and marks of three subjects. WAP to display all the records along with percentage whose percentage is greater than 80 and less than 100.

CLS

OPEN “result.dat” FOR INPUT AS #1

WHILE NOT EOF(1)

INPUT #1, na$,e,m,s

p=(e+m+s)/3

IF p>=80 AND p<100 THEN PRINT na$,e,m,s,p

WEND

CLOSE #1

END

 

 23. A sequential data file “compu.txt” has records of different fields like students name, address and age . WAP to copy all the records from the data file “compu.txt” into “school.txt”.

CLS

OPEN “compu.txt” FOR INPUT AS #1

OPEN “school.txt” FOR OUTPUT AS #2

WHILE NOT EOF(1)

INPUT #1, n$,ad$,a

WRITE #2, n$,ad$,a

WEND

CLOSE #1

PRINT “Data are successfully copied”

END

 

24. WAP to delete the some records from data file "AVN.DAT" which has contents name, class, roll no and address.

CLS

OPEN "avn.dat" FOR INPUT AS #1

OPEN "abc.dat" FOR OUTPUT AS #2

ab:

DO WHILE NOT EOF(1)

INPUT #1, r,n$,c$,a$

PRINT "Name=";n$

PRINT "Class=";c$

PRINT "Roll no=";r

PRINT "Address=";a$

INPUT "Do you want to delete this record (y/n)";y$

IF y$="Y" or y$="y" THEN GOTO ab

ELSE

WRITE #2, r, n$, c$, a$

GOTO ab

ENDIF

LOOP

CLOSE #1, #2

KILL "avn.dat"

NAME "abc.dat" AS "avn.dat"

END

 

 25. A sequential data file “STUDENT.DAT” contains the details of students such as Name, roll no, class, joining date etc. WAP to update the details of the data file “student.dat”.

CLS

OPEN “student.dat” FOR INPUT AS#1

OPEN “temp.dat” FOR OUTPUT AS #2

WHILE NOT EOF(1)

INPUT #1, name$, roll, class, date$

PRINT:PRINT

PRINT “Name of the student=”;name$

PRINT “Roll number”;roll

PRINT “Class=”;class

PRINT “Joining date=”;date$

PRINT:PRINT

PRINT “Do you want to Update this record(Y/N)”

INPUT ch$

IF ch$=”Y” OR ch$=”y” THEN

INPUT “New name=”;name$

INPUT “New roll number=”;roll

INPUT “New class=”;class

INPUT New date=”;date$

ENDIF

WRITE #2, name$, roll, class, date$

WEND

CLOSE #1, #2

KILL “student.dat”

NAME “temp.dat” AS “student.dat”

END

 

26. A sequential data file “information.dat” contains name, address and phone number of the students. WAP to enter a telephone number from the keyboard, match the telephone number with the telephone number stored in the file. If the telephone number matched then display “Record found” otherwise display “Record not found”

OPEN “information.dat” FOR INPUT AS#1

CLS

INPUT “Enter telephone number=”;tel$

WHILE NOT EOF(1)

INPUT #1, n$, a$, ph$

IF(ph$=tel$) THEN

PRINT “Record found”

ELSE

PRINT “Record not found”

ENDIF

PRINT “Name=”;n$

PRINT “Address=”;a$

PRINT “Telephone number”;ph$

WEND

CLOSE #!

END


Also Read: Program Design Tools Algorithm Flowchart and Pseudo code

Program to count vowel letters

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages