6.
Re-write the given program after correcting the bugs: [2]
REM to add record in an existing file
CLS
OPEN “[Link]” FOR OUTPUT AS #1
AA:
INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn
INPUT #2, Nm$, Cl, Rn
INPUT “More records”; Y$
IF UCASE$(Y$)=”Y” THEN GOTO aa
CLOSE “[Link]”
END
Debugged program:
REM to add record in an existing file
CLS
OPEN “[Link]” FOR APPEND AS #1
AA:
INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn
WRITE #1, Nm$, Cl, Rn
INPUT “More records”; Y$
IF UCASE$(Y$)=”Y” THEN GOTO AA
CLOSE #1
END
6. Re-write the given program after correcting the bugs: 2
DECLARE SUB Series ( )
CLS
EXECUTE Series
END
SUB Series( )
REM Program to generate 1 1 2 3 5 .....upto the 20th terms
A=1
B=1
FOR ctr=10 to 1
DISPLAY A:B:
A=A+B
B=A+B
NEXT ctr
END Series ( )
Debugged Program
DECLARE SUB Series ( )
CLS
CALL Series
END
SUB Series( )
REM Program to generate 1 1 2 3 5 .....upto the 20th terms
A=1
B=1
FOR ctr=1 TO 10
PRINT A; B;
A=A+B
B=A+B
NEXT ctr
END SUB
6. Re-write the given program after correcting the bugs: 2
REM to display records from existing file.
CLS
OPEN “[Link]” FOR APPEND AS #1
WHILE NOT EOF(#1)
WRITE #1, eN$, post$, salary
PRINT eN$, post$, salary
CLOSE#1
END
Debugged Program
REM to display records from existing file.
CLS
OPEN “[Link]” FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, eN$, post$, salary
PRINT eN$, post$, salary
WEND
CLOSE #1
END
6. Re-Write the given program after correcting the bugs: REM program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
INPUT “Enter a word”; N$ DISPLAY “Reversed is”; Rev$(N$)
END
FUNCTION Rev$(N$)
FOR K=LEN$(N$) To 1 STEP-1 B$=B$+MID$(N$,1,K)
NEXT K B$=Rev$
END FUNCTION
Debugged Program
REM program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
INPUT “Enter a word”; N$
PRINT “Reversed is”; Rev$(N$)
END
FUNCTION Rev$(N$)
FOR K=LEN (N$) To 1 STEP-1
B$=B$+MID$(N$, K,1)
NEXT K
Rev$=B$
END FUNCTION
Rewrite the given program after correcting the bugs:
REM to display records from existing file.
OPEN "[Link]" FOR APPEND AS #1
WHILE NOT EOF (#1)
WRITE # 1, eN$, posts, salaryS
PRINT eN$, post$, salary
NEXT
CLOSE #1
END
Debugged Program
OPEN "[Link]" FOR INPUT AS #1
WHILE NOT EOF (1)
INPUT # 1, eN$, posts, salary$
PRINT eN$, post$, salary
WEND
CLOSE #1
END
Debug the following program.
DECLARE FUNCTION PAL$ (W$)
CLS
INPUT "Enter a word"; W$
SHOW PAL$ (W$)
END
FUNCTION PAL$ (W$)
FOR I= LEN (W$) TO 1 STEP1
R$=R$+MID$ (W$, I, 1)
NECT I
IF R$-W$ THEM
P$="Palindrome"
ELSE
P$="Not palindrome"
ENDIF
P$=PAL$
END FUNCTION
Debugged Program
DECLARE FUNCTION PAL$ (W$)
CLS
INPUT "Enter a word"; W$
PRINT PAL$ (W$)
END
FUNCTION PAL$ (W$)
FOR I= LEN (W$) TO 1 STEP-1
R$=R$+MID$ (W$, I, 1)
NEXT I
IF R$=W$ THEM
P$="Palindrome"
ELSE
P$="Not palindrome"
ENDIF
PAL$ =P$
END FUNCTION
6. Re-write the program after correcting the bug.
DECLARE SUB sbn()
CLS
CALL SUB sbn (14)
END SUB
SUB sbn()
INPUT "enter the variable value”; var
PRINT "Square of given number"; var^2
END
Debugged Program
DECLARE SUB sbn( )
CLS
CALL sbn
END
SUB sbn( )
INPUT "enter the variable value”; var
PRINT "Square of given number"; var^2
END SUB
6. Re-write the given program after correcting the bugs.
REM Program to add records to an existing file "[Link]"
OPEN "[Link]" FOR APPEND AS #1
DO
CLS
INPUT "Enter name: "; N$
INPUT "Enter Address: "; Ad$
INPUT "Enter Total Marks: "; TM$
COPY #1, N$, Ad$, TM
INPUT "Do you want to add more records? Press Y or N: "; CH$
LOOP WHILE UCASE$(CH$) < > “Y”
CLOSE "[Link]"
END
Debugged Program
REM Program to add records to an existing file "[Link]"
OPEN "[Link]" FOR APPEND AS #1
DO
CLS
INPUT "Enter name: "; N$
INPUT "Enter Address: "; Ad$
INPUT "Enter Total Marks: "; TM
WRITE #1, N$, Ad$, TM
INPUT "Do you want to add more records? Press Y or N: "; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
6. Re-write the given program after correcting the bug. [2]
FUNCTION SUM(M, N)
REM to print sum of two numbers
A=6
B=7
DISPLAY sum(M,N)
END
FUNCTION SUM(M,N)
S=M+N
S=SUM
END FUNCTION
Debugged Program
DECLARE FUNCTION SUM(M, N)
REM to print sum of two numbers
A=6
B=7
PRINT sum(A,B)
END
FUNCTION SUM(M,N)
S=M+N
SUM=S
END FUNCTION
6. Rewrite the given program after correcting the bugs.
Rem to convert the given number in reverse order
DECLARE FUNCTION REV (A)
CLS
INPUT "ENTER A NUMBER"; A
CALL REV (A)
PRINT "REVERSE ="; RE
END
FUNCTION REV$ (A)
WHILE A<> 0
R= A MOD2
S=S*10+R
A=A-10
WEND
REV=S
END SUB
CORRECT PROGRAM
DECLARE FUNCTION REV (A)
CLS
INPUT “ ENTER A NUMBER”; A
RE=REV(A)
PRINT “RECERSE=”;RE
END
FUNCTION REV (A)
WHILE A<> 0
R= A MOD 10
S=S*10+R
A=A/10
WEND
REV=S
S=S*10+R
END FUNCTION
Debug
DECLARE FUNCTION vowel(S$)
w$=we love our country
v=vowel(w$)
PRINT "The total no. of vowel::"; v
END
FUNCTION vowel$(S$)
c=0
FOR K=1 TO length(S$)
B$=MID$(S$, K, 1)
B$=LCASE$(B$)
SELECT CASE B$
CASE "a", "e", "i", "o", "u"
c=c+1
END SELECT
NEXT K
C=vowel
END FUNCTION
Debugged Program
DECLARE FUNCTION vowel(S$)
w$="we love our country"
v=vowel(w$)
PRINT "The total no. of vowel::"; v
END
FUNCTION vowel(S$)
c=0
FOR K=1 TO LEN(S$)
B$=MID$(S$, K, 1)
B$=LCASE$(B$)
SELECT CASE B$
CASE "a", "e", "i", "o", "u"
c=c+1
END SELECT
NEXT K
vowel = c
END FUNCTION
6) Rewrite the given program after correcting bugs,
REM PROGRAM DISPLAY
RECORDS OPEN [Link]
FOR INPUT AS #1 CLS
WHILE NOTEOF(2)
INPUT #1,
NAME$,AGE,SALARY
DISPLAY NAME$, AGE,
SALARY LOOP WEND
CLOSE #1
END
Debugged Program
REM PROGRAM DISPLAY RECORDS
OPEN “[Link]” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, NAME$,AGE,SALARY
PRINT NAME$, AGE, SALARY
WEND
CLOSE #1
END
Re-write the given program after correcting the bugs: (2)
REM to store Name, post and salary
OPEN [Link] FOR OUT AS #1
INPUT "Enter name"; N
INPUT "Enter post"; PS
INPUT "Enter salary"; S
INPUT #2, NS, P$, S
CLOSE #1
STOP
Debugged Program
REM to store Name, post and salary
OPEN "[Link]" FOR OUTPUT AS #1
INPUT "Enter name"; N$
INPUT "Enter post "; P$
INPUT "Enter salary"; S
WRITE #1, N$, P$, S
CLOSE #1
END
Debug the following program
Rem to add 5 records in data file [Link]
OPEN "[Link]" FOR INPUT AS #5
FORREP=1TO5
INPUT "ENTER PATIENT NAME":PN$
INPUT "ENTER PATIENT ADDRESS":AD$
INPUT "ENTER PATIENT AGE": A%
INPUT "ENTER PATIENT GENDER":G$
STORE #5, PN$,AD$,A, G$
NEXT REP
CLOSE #1
END
Debugged Program
Rem to add 5 records in data file [Link]
OPEN "[Link]" FOR APPEND AS #5
FORREP=1TO5
INPUT "ENTER PATIENT NAME":PN$
INPUT "ENTER PATIENT ADDRESS":AD$
INPUT "ENTER PATIENT AGE": A%
INPUT "ENTER PATIENT GENDER":G$
WRITE #5, PN$,AD$,A%, G$
NEXT REP
CLOSE #1
END
6. Rewrite the following program after correcting the bugs. [2]
DECLARE FUNCTION SUM(N)
CLS
INPUT “ENTER A NUMBER”; N
SU= SUM(N)
PRINT “SUM =”; SUM(N)
END
FUNCTION SUM(N)
WHILE N< > 0
R=RMOD10
S=S+R
N=N\ 10
WEND
S= SUM
END SUB
DECLARE FUNCTION SUM(N)
CLS
INPUT “ENTER A NUMBER”; N
SU= SUM(N)
PRINT “SUM =”; SU
END
FUNCTION SUM(N)
WHILE N< > 0
R=NMOD10
S=S+R
N=N/10
WEND
SUM=S
END FUNCTION
6. Re-Write the given program after correcting the bugs:
DECLARE FUNCTION RESULT$(X,Y)
CLS
INPUT “Enter marks in math:”, M
R$=RESULT$(X,N)
PRINT M$
END FUNCTION
FUNCTION RESULT$(X,Y)
IF X>=40 AND Y>=40 THEN
RESULT$ = "Pass"
ELSE
RESULT$ = "Fail"
END IF
END SUB
Debugged Program
DECLARE FUNCTION RESULT$(X,Y)
CLS
INPUT “Enter marks in math and science:”, M, N
R$=RESULT$(M,N)
PRINT R$
END
FUNCTION RESULT$(X,Y)
IF X>=40 AND Y>=40 THEN
RESULT$ = "Pass"
ELSE
RESULT$ = "Fail"
END IF
END FUNCTION