Friday, August 9, 2024

QBASIC Debugging

 

Debugging

1.     Re-write the given program after correcting the bugs:                             [2]

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 GOTO aa

CLOSE “Record.dat”

END

 

 

2.  Re-write the given program after correcting the bugs.  [2]

               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

 

3.     Re-write the given program after correcting the bugs.                              [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

  

4. Debug the following program.

 

REM to store name, address in the file "store.dat"

CLS

OPEN "store.dat" FOR INPUT AS #1

DO

INPUT "Enter name"; name$

INPUT "Enter address"; address

WRITE name$, address$

INPUT "do you want to continue"; ans$

LOOP WHILE UCASE$(ans$)="Y"

CLOSE #2

END

 5. Re-write the given program after correcting the bugs: [2]

REM to store record in data file

 CLS

OPEN "employee.dat" FOR INPUT AS #1

DO

INPUT "Enter Name, address and gender": NS, A. G

INPUT #1, NS, A. G

INPUT "Do you want to continue "; Y$

WHILE UCASE$(Y$) = "Y"

CLOSE "employee.dat"

END

 

6.      Re-write the given program after correcting the bug.                                                         [2]

REM    To store name and age in a sequential data file STD.DOC

OPEN STD.DOC FOR OUT AS#1

CLS

INPUT "Enter name";N

INPUT "Enter age";A

WRITE 1,N$,A

CLOSE #1

END

7. Rewrite the given program after correcting the bugs.

 REM to create sequential data file "record.dat" to enter some records.

CLS OPEN "record.dat" FOR INPUT AS #1

UP:

INPUT "ENTER NAME";N$

INPUT "ENTER ADDRESS";A$

INPUT "ENTER PHONE NUMBER";PH

WRITE #2, N$,A$,PH

INPUT "Do you want to continue(y/n)?";an

IF LCASE(an$)="y" THEN GOTO UP

CLOSE #1

END

  8. Re-write the given program after correcting the bugs:         2

       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

 9. Rewrite the given program after correcting bugs,

REM PROGRAM DISPLAY RECORDS

OPEN INFO.DAT FOR INPUT AS #1

CLS

WHILE NOTEOF(2)

INPUT #1, NAME$,AGE,SALARY

DISPLAY NAME$, AGE, SALARY

LOOP WEND

CLOSE #1

END

 10. Rewrite the given program after correcting the bugs:

REM to display records from existing file.

OPEN "emp.text" FOR APPEND AS #1

WHILE NOT EOF (#1)

WRITE # 1, eN$, posts, salaryS

PRINT eN$, post$, salary

NEXT

CLOSE #1

END

 

 11. Re-write the given program after correcting the bugs: (2)

 REM to store Name, post and salary

OPEN EMP.DOC FOR OUT AS #1

INPUT "Enter name"; N

INPUT "Enter post"; PS

INPUT "Enter salary"; S

INPUT #2, NS, P$, S

CLOSE #1

STOP

  12.Rem to add 5 records in data file HOSPITAL.TXT

OPEN "HOSPITAL.TXT" FOR INPUT AS #5

FOR REP = 1 TO 5

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

 13. Re-write the given program after correcting the bugs: (2)

 REM to count total no. of passed student

WHILE NOT EOF()

OPEN "pab.txt" FOR OUTPUT AS#1

INPU T#2,ID,M1,M2,M3

IF M1>=32, M2>=32, M3>=32 THEN

X=X+1

END IF

WEND

PRINT "TOTAL RECORD";X

END

  14. Re-Write the given program after correcting the bug: 2

 REM display records of students from Data file

OPEN "Stdinfo.dat" FOR OUTPUT AS #1

PRINT "ROLL",  NAME", "ADDRESS", "CLASS" , "SECTION"

DO WHILE NOT EOF

INPUT #1, RN. N$, AD$, CL, S$

PRINT RN, NS, ADS, CL, S$

NEXT

STOP #1

END

 15. Re-write the given program after correcting the bugs.

 

OPEN "student.rec" FOR OUTPUT AS #1

FOR I = 1 TO 5

 INPUT "Enter Name, Class, Roll No. and Age"; N$, C, R, A

WRITE N$, C, R, A

CLOSE #1

 

 16. Re-write the given program after correcting the bugs:                        2

DECLARE SUB VOLUME (l,b,h)

CLS

INPUT "ENTER length, breadth & height";l, b, h

EXECUTE VOLUME

SUB VOLUME(l,b,h)

V=lxbxh

PRINT "The volumeis";V

END FUNCTION

 

17. Re-write the given program after correcting the bugs.

 

REM Program to generate 2, 2, 4, 6, 10 up to 10th term

DECLARE SUB FIBO ( )

CLS
EXECUTE FIBO

END

 

SUB FIBO

A = 2

B = 2

FOR ctr = 5 to 1

DISPLAY A; B;

A = A + B

B = A + B

NEXT ctr

END FUNCTION

 

 18.  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 = R MOD 10

                S= S + R

                 N = N \  10

              WEND

            S= SUM

            END SUB

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

 

20. Re-write the given program after correcting the bugs:

 CREATE FUNCTION SQUARE(N)

CLS

REM TO PRINT SQUARE OF A NUMBER

GET “ENTER ANY NUMBER”;  N

CALL SQUARE(N)

END

 

FUNCTION SQUARE(N)

ANS=A^2

SQUARE = ANS

END SQUARE(N)

 

21.    Re-write the given program after correcting the bugs:                               2

 REM To find the sum of even digits of multi digits number

DECLARE FUNCTION SUM (N)

CLS

ACCEPT “ENTER MULTI-DIGITS NUMBER  ”NUM

PRINT “SUM  = ” ; SUM(N)

END

 FUNCTION SUM(N)

WHILE N=0

R= N MOD 10

IF R MOD 2 = 0 THEN S=S+R

N = N \ 10

WEND

SUM (N) =S

END FUNCTION

 

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

 

23. Re-write the given program after correcting the bugs: [2]

            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

 

 

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

 

25. 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 ( )

 

26. Debug the following program:

DECLARE SUB SUM (P, Q, R)

CLS

INPUT “Enter the numbers”: P,Q,R

CALL SUM

END SUB

 

SUB Check(P,Q,R)

S = P + Q + R

PRINT “Sum of three numbers is”; SUM

END SUB

 

 

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

 

END FUNCTION

 28. Re-Write the given program after correcting the bugs:                                    [2]

 

REM to display the reverse of the supplied string

DECLARE SUB rev (s$)

CLS

INPUT n$

CALL rev$(n$)

END

 

SUB rev (n$)

FOR k=1 TO LEN(n$).

a$ = MID$(n$, 1, k)

p$ = p$ + n$

NEXT k

PRINT p$

END SUB

 

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

 

 

30. Re-Write the given program after correcting the bugs:

REM program to make a word reverse

DECLARE FUNCTION Rev$(N$)

CLS

LNPUT “Enter a word”; N$

DISPLAY “Reversed is”; Rev$(N$)

END

EUNCTION Rev$(N$)

FOR K=LEN$(N$) To 1 STEP-1

B$=B$+MID$(N$,1,K)

NEXT K

B$=Rev$

END FUNCTION

 

 

 

 


No comments:

Post a Comment