Monday, January 15, 2024

3.2.3. QBASIC Modular Programming Debugging Solutions - SEE COMPUTER SCIENCE 2080

3.2.3. QBASIC Modular Programming  Debugging Solutions - SEE COMPUTER SCIENCE 2080




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

 

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

 

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

 

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

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

 

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

 

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

 

Debugged program.

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

CLS

OPEN "store.dat" FOR OUTPUT AS #1

DO

INPUT "Enter name"; name$

INPUT "Enter address"; address$

WRITE #1, name$, address$

INPUT "do you want to continue"; ans$

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

CLOSE #1

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

 

Debugged Program

CLS

OPEN "employee.dat" FOR OUTPUT  AS #1

DO

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

WRITE #1, NS, A$, G$

INPUT "Do you want to continue "; Y$

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

CLOSE #1

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

 

Debugged Program

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

OPEN “STD.DOC” FOR OUTPUT 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

 

Debugged program

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

CLS

OPEN "record.dat" FOR OUTPUT AS #1

UP:

INPUT "ENTER NAME";N$

INPUT "ENTER ADDRESS";A$

INPUT "ENTER PHONE NUMBER";PH

WRITE #1, 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

 

 

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

 

 

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

 

Debugged Program

 

REM PROGRAM DISPLAY RECORDS

OPEN “INFO.DAT” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, NAME$,AGE,SALARY

PRINT NAME$, AGE, SALARY

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

 

Debugged Program

REM to display records from existing file.

OPEN "emp.txt" FOR INPUT AS #1

WHILE NOT EOF (1)

INPUT # 1, eN$, posts, salary$

PRINT eN$, post$, salary

WEND

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

 

Debugged Program

REM to store Name, post and salary

OPEN "EMP.DOC" FOR OUTPUT AS #1

INPUT "Enter name"; N$

INPUT "Enter post "; P$

INPUT "Enter salary"; S

WRITE #1, N$, P$, S

CLOSE #1

END

 

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

 

 Debugged Program

 

Rem to add 5 records in data file HOSPITAL.TXT

OPEN "HOSPITAL.TXT" FOR APPEND 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$

WRITE #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

 

Debugged Program

 

REM to count total no. of passed student

OPEN "pab.txt" FOR INPUT AS #1

WHILE NOT EOF ( 1 )

INPUT #1, ID, M1, M2, M3

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

X=X+1

END IF

WEND

PRINT "TOTAL passed RECORD";X

CLOSE #1

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

 

Debugged Program

REM display records of students from Data file

OPEN "Stdinfo.dat" FOR INPUT AS #1

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

DO WHILE NOT EOF (1)

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

PRINT RN, NS, ADS, CL, S$

WEND

CLOSE #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

 

Debugged Program:

OPEN "student.rec" FOR INPUT AS #1

FOR I = 1 TO 5

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

WRITE #1, N$, C, R, A

NEXT I

CLOSE #1

END

 

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

 

Debugged Program

DECLARE SUB VOLUME (l,b,h)

CLS

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

CALL VOLUME (l, b, h)

END

 

SUB VOLUME(l,b,h)

V=l*b*h

PRINT "The volume is";V

END SUB

 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

 

Debugged Program

 

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

DECLARE SUB FIBO ( )

CLS
CALL  FIBO

END

 

SUB FIBO

A = 2

B = 2

FOR ctr = 5 to 1 STEP -1

PRINT A; B;

A = A + B

B = A + B

NEXT ctr

END SUB

 

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

Debugged Program

 

DECLARE FUNCTION SUM(N)

CLS

            INPUT “ENTER A NUMBER”; N

            SU= SUM(N)

            PRINT “SUM =”; SU

             END

           

            FUNCTION SUM(N)

               WHILE N< > 0

                R = N MOD 10

                S= S + R

                 N = N \  10

              WEND

            SUM=S

            END FUNCTION

  

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

 

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

 

 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)

 

Debugged Program

 

DECLARE FUNCTION SQUARE(N)

CLS

REM TO PRINT SQUARE OF A NUMBER

INPUT “ENTER ANY NUMBER”;  N

PRINT SQUARE(N)

END

 

FUNCTION SQUARE(N)

ANS=N^2

SQUARE = ANS

END FUNCTION 

 

 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

 

Debugged Program

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

DECLARE FUNCTION SUM (N)

CLS

INPUT “ENTER MULTI-DIGITS NUMBER  ”NUM

PRINT “SUM  = ” ; SUM(NUM)

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 =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

 

CORRECTED PROGRAM

DECLARE FUNCTION REV (A)

CLS

INPUT "ENTER A NUMBER"; A

RE=REV(A)

PRINT "REVERSE ="; RE

END

FUNCTION REV (A)

               WHILE A<> 0

                              R= A MOD 10

                              S = S * 10 + R

                              A = A 10

               WEND

               REV = S

END FUNCTION

 

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

 

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

 

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

 

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

  

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

 

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

 

 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

 

Debugged Program

DECLARE SUB SUM (P, Q, R)

CLS

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

CALL SUM (P,Q,R)

END

 

SUB SUM(P,Q,R)

S = P + Q + R

PRINT “Sum of three numbers is”; S

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

 

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

 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

 

Debugged Program

DECLARE SUB rev (s$)

CLS

INPUT n$

CALL rev (n$)

END

 

SUB rev (n$)

FOR k= LEN(n$) TO 1 STEP-1

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

p$ = p$ + a$

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

 

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

 

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

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

 

  

No comments:

Post a Comment