Wednesday, March 29, 2023

Debug the following program

 SET - 1

Debug the following program and rewrite it.




1. REM to print all the records where address is Kathmandu

OPEN "ADD.DAT" FOR INPUT AS #1

CLS

WHILE EOF (1)

INPUT #1, NA$, AD$, G$

IF UCASE(G$)="KATHMANDU" THEN PRINT NA$, AD$, G$

WEND

CLOSE #10

END

 

Debugged Program:

REM to print all the records where address is Kathmandu

OPEN "ADD.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

INPUT #1, NA$, AD$, G$

IF UCASE$(AD$)="KATHMANDU" THEN PRINT NA$, AD$, G$

WEND

CLOSE #1

END

 

2. REM to create a new file CLS

OPEN “ABC.DAT” FOR INPUT AS #1

DO

INPUT “Enter Name, Roll No & Total. “; N$, R, T

INPUT #1, N$, R, T

INPUT “Supply more records Y/N”; C$

LOOP WHILE UCASE(Y$)=”Y”

CLOSE #1

END

 

DEBUGGED PROGRAM:

REM to create a new file CLS

OPEN “ABC.DAT” FOR OUTPUT AS #1

DO

INPUT “Enter Name, Roll No & Total. “; N$, R, T

WRITE #1, N$, R, T

INPUT “Supply more records Y/N”; C$

LOOP WHILE UCASE$(C$)=”Y”

CLOSE #1

END

 

3. REM to add record in an existing file

CLS

OPEN “Record.Dat” 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 GOT aa

CLOSE “Record.dat”

END

 

DEBUGGED PROGRAM:

REM to add record in an existing file

CLS

OPEN “Record.Dat” 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

 

4. 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 20

PRINT A; B;

A=A+B

B=A+B

NEXT ctr

END SUB

 

5. REM to display records from existing file.

CLS

OPEN “emp.txt” 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 “emp.txt” FOR INPUT AS #1

WHILE NOT EOF(1)

INPUT #1, eN$, post$, salary

PRINT eN$, post$, salary

WEND

CLOSE #1

END

 

6. 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

 

7. REM to add more data in a sequential file.

OPEN “EMP.DAT” FOR INPUT AS #2

DO

INPUT “ENTER NAME”; N$

INPUT “ENTER ADDRESS”; A$

INPUT “ENTER SALARY”; S$

WRITE #1, N$, A$, S

INPUT” Do you want to add more records.”; M$

LOOP WHILE UCASE(M$) = “Y”

END

 

DEBUGGED PROGRAM:

REM to add more data in a sequential file.

OPEN “EMP.DAT” FOR APPEND AS #2

DO

INPUT “ENTER NAME”; N$

INPUT “ENTER ADDRESS”; A$

INPUT “ENTER SALARY”; S

WRITE #2, N$, A$, S

INPUT” Do you want to add more records.”; M$

LOOP WHILE UCASE$(M$) = “Y”

CLOSE #2

END

 

8. 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

 

DEBUGGED PROGRAM:

Rem to convert the given number in reverse order

DECLARE FUNCTION REV (A)

CLS

INPUT "ENTER A NUMBER"; A

PRINT "REVERSE ="; REV (A)

END

FUNCTION REV (A)

WHILE A<> 0

R= A MOD 10

S = S * 10 + R

A = A \ 10

WEND

REV = S

END FUNCTION

 

9. 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 "GIVEN WORD IS "; 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$ THEN

P$="Palindrome"

ELSE

P$="Not palindrome"

END IF

PAL$ = P$

END FUNCTION

 

10.  REM print the input integer in reverse order

DECLARE SUB REV (N)

CLS

INPUT "Enter an integer number"; NO

CALL REV (NO)

END

SUB REV (N)

A = N

WHILE A = 0

R = A MOD 10

S = S + 10 + R

A = A \ 10

NEXT

DISPLAY "Reverse"; S

END SUB

 

DEBUGGED PROGRAM:

REM print the input integer in reverse order

DECLARE SUB REV (N)

CLS

INPUT "Enter an integer number"; NO

CALL REV (NO)

END

SUB REV (N)

A = N

WHILE A <> 0

R = A MOD 10

S = S * 10 + R

A = A \ 10

WEND

PRINT "Reverse"; S

END SUB

No comments:

Post a Comment