QBASIC FILE HANDLING SOLUTIONS[DIFFICULT ONE - PART B]



1. A sequential data file called salary.dat contains s.no, name, post and salary fields. WAP to update the salary of all the employees if post is manager and salary is more than 25000 by 15% otherwise by 10%.

OPEN "D:\SALARY.DAT" FOR INPUT AS #1
OPEN "D:\TEMP.DAT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S > 25000 AND UCASE$(P$) = "MANAGER" THEN
WRITE #2, N$, P$, S + (15 / 100) * S
ELSE
WRITE #2, N$, P$, S + (10 / 100) * S
END IF

WEND
CLOSE
KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"


 END

1.    2.   A sequential data file “RECORD.DAT” contains different records under fields: name rollno., name, address and percentage. Write a program to edit a record and display both edited and unedited records on the screen to compare them side by side.
OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2
CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$, P
ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT FOUND"
ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= "; R
PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= "; P
PRINT "---------------"
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: "; ER
PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF

CLOSE

KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"
END

Comments

Unknown said…
I understand that after adding new required data in a new file then kill the new file and rename the
old file as the new file but the file's sequence number still wouldn't match so how would file 2 replace file 1?

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

PALINDROME AND ARMSTRONG PROGRAMS