Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Post Top Ad

Your Ad Spot

Friday, February 18, 2022

Debugged program using QBASIC

Debugged program using QBASIC

Debugged program using QBASIC


"Short question on QBASIC debug program for SEE and grade 10 students"


Re-write the following program with correcting bugs. (It carries 2 Marks)

1) Specification Grid 2065

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

OPEN STD.DOC FOR OUT AS #1

INPUT "Enter name";n

INPUT "Enter age";a

WRITE 1, n$,a

CLOSE #1

END

Answer:

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

OPEN "STD.DOC" FOR OUTPUT AS #1

INPUT "Enter name";n$

INPUT "Enter age";a

WRITE #1, n$,a

CLOSE #1

END

 

2) SEE 2078

DECLARE SUB series()

CLS

EXECUTE series

END

 

SUB series

REM program to generate 1  1   2   3  5  ….up to the 20th term.       

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  ….up to the 20th term.       

A=1

B=1

FOR ctr 10 TO 1 STEP -1

PRINT A;B;

A=A+B

B=A+B

NEXT ctr

END SUB

 

3) SEE Grade Promotion Exam 2078

REM to display records from an existing file.

CLS

OPEN "empt.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 an existing file.

CLS

OPEN "empt.txt" FOR INPUT AS #1

WHILE NOT EOF(1)

INPUT #1, en$, post$, salary

PRINT en$, post$, salary

WEND

CLOSE #1

END

 

4)

REM to create a new data file

CLS

OPEN "ABC.DAT" FOR INPUT AS #1

DO

INPUT "Enter Name, Roll No and Total. "; N$,R,T

INPUT #1, N$, R,T

INPUT "Supply more records Y/N"; CS

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

CLOSE #1

END

 

Debugged program

REM to create a new data file

CLS

OPEN "ABC.DAT" FOR OUTPUT AS #1

DO

INPUT "Enter Name, Roll No and Total. "; N$,R,T

WRITE #1, N$, R,T

INPUT "Supply more records Y/N"; C$

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

CLOSE #1

END

 

5)

REM to store record in data file

CLS

OPEN "info.dat" FOR INPUT AS #1

DO

INPUT “Enter Name, Address and Class ”;N$,A,C

INPUT #1,N$,A,C

INPUT "Do you want to continue " ; Y$

WHILE UCASE$(Y$)= "Y"

CLOSE "info.dat"

END

 

Debugged program:

REM to store record in data file

CLS OPEN "info.dat" FOR OUTPUT AS #1

DO

INPUT “Enter Name, Address and Class ”;N$,A$,C

WRITE #1,N$,A$,C

INPUT "Do you want to continue " ; Y$

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

CLOSE #1

END

 

6) Pabson Pre-board exam 2078

REM to add more data in sequential data 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 sequential data 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”

END

 

7)

DECLARE FUNCTION FACTO (N$)

REM to find factorial of a input number

CLS

INPUT "Enter a number" ; X

PRINT “The factorial is “; FACTO(N)

END

FUNCTION FACTO(N)

F=1

WHILE N=0

F=F*N

N=N-1

WEND

F=FACTO

END FUNCTION

 

Debugged program

DECLARE FUNCTION FACTO (N)

REM to find factorial of a input number

CLS

INPUT "Enter a number" ; X

PRINT “The factorial is “; FACTO(x)

END

FUNCTION FACTO(N)

F=1

WHILE N <>0

F=F*N

N=N-1

WEND

FACTO=f

END FUNCTION

 

8)

REM program to store name, post and salary in data file for few employees.

OPEN “emp.dat” FOR APPEND As #1

top:

INPUT “Enter name”;name

INPUT “Enter post”;post$

INPUT “Enter salary”;sal

WRITE #2, name$,post$,sal

INPUT “Do you want to more records”;ch$

IF UCASE$(ch$)=”Y” THEN GOTO top

ENDIF

CLOSE #1

END

Debugged program

REM program to store name, post and salary in data file for few employees.

OPEN “emp.dat” FOR OUTPUT As #1

top:

INPUT “Enter name”;name$

INPUT “Enter post”;post$

INPUT “Enter salary”;sal

WRITE #1, name$,post$,sal

INPUT “Do you want to more records”;ch$

IF UCASE$(ch$)=”Y” THEN GOTO top

CLOSE #1

END

 

9) Specification Grid 2065

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

OPEN STD.DOC FOR OUT AS #1

INPUT "Enter name";n

INPUT "Enter age";a

WRITE 1, n$,a

CLOSE #1

 END

Answer:

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

OPEN "STD.DOC" FOR OUTPUT AS #1

INPUT "Enter name";n$

INPUT "Enter age";a

WRITE #1, n$,a

CLOSE #1

END

 

10) SLC 2065

 DECLARE SUB series()

CLS

 EXECUTIVE series

 END

SUB series

 a=2

 b=2

 FOR ctr = 1 TO 5

DISPLAY a;b;

a=a+b

b=a+b

LOOP ctr

END series()

 

Answer:

            DECLARE SUB series()

            CLS

            CALL series

            END

            SUB series

            a=2

            b=2

            FOR ctr = 1 TO 5

            PRINT a;b;

            a=a+b

            b=a+b

            NEXT ctr

            END SUB

 

11) SLC supplementary 2065

DECLARE FUNCTION sum(a,b)

REM program to sum given two numbers

INPUT "enter first number;x

INPUT "Enter second number";y

 PRINT sum(a,b)

END

 FUNCTION sum(a,b)

sum=a+b

END

 

Answer:

DECLARE FUNCTION sum(a,b)

REM program to sum given two numbers

INPUT "enter first number";x

INPUT "Enter second number";y

PRINT sum(x,y)

END

FUNCTION sum(a,b)

sum=a+b

END FUNCTION

 12)    SLC 2066

 DECLARE SUB fibonic( )

 REM *fibonic series*

 CALL SUB fibonic

END

SUB fibonic

a=1

b=1

FOR x= 1 TO 10

DISPLAY a;

 a=a+b

b=a+b

END fibonic

 

 Answer:

            DECLARE SUB fibonic( )

            REM *fibonic series*

            CALL fibonic

            END

            SUB fibonic

            a=1

            b=1

            FOR x= 1 TO 10

            PRINT a;

            a=a+b

            b=a+b

            NEXT x

            END SUB

 

13)    SLC supplementary 2066

REM to store name, post and salary

OPEN EMP.DOC FOR OUT AS #1

INPUT "Enter name";n

INPUT "Enter post";p$

 INPUT "Enter salary";s

WRITE 1, n$,p$,s

CLOSE #1

 END

 

Answer:

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

 

14)    SLC 2067

REM to display all the records from the sequential data file ABC.DAT

OPEN "ABC.DAT" FOR OUTPUT AS #1 DO WHILE NOT EOF ("ABC.DAT"

INPUT #1, n$,a

PRINT n$,a

CLOSE 1

END

 

Answer:

REM to display all the records from the sequential data file ABC.DAT

            OPEN "ABC.DAT" FOR INPUT AS #1

            DO WHILE NOT EOF (1)

            INPUT #1, n$,a

            PRINT n$,a

            LOOP

            CLOSE #1

            END

 

15)

DECLARE FUNCTION vowel(a$)

CLEAR

INPUT "Enter String:";a$

vo=vowel(a$)

PRINT "Total numbers of "A" characters=";vo

END

FUNCTION vowel(a$)

FOR x= 1 to LEN(a$)

m$=MID(a$,x,1)

m$=UPPERCASE$(m$)

SELECT CASE m$

CASE "A"

v=v+1

END SELECT

NEXT x

v=vowel

END FUNCTION

 

Answer:

DECLARE FUNCTION vowel(a$)

CLS

INPUT "Enter String:";a$

vo=vowel(a$)

PRINT "Total numbers of "A" characters=";vo

END

FUNCTION vowel(a$)

FOR x= 1 to LEN(a$)

m$=MID$(a$,x,1)

m$=UCASE$(m$)

SELECT CASE m$

CASE "A"

v=v+1

END SELECT

NEXT x

Vowel=v

END FUNCTION

 

16)    SLC 2064

DECLARE SUB series( )

CLS

EXECUTE series

END

SUB series ()

REM program to generate 3 3 6 9 15 ….up to 20th terms

A=3

B=3

FOR CTR = 10 TO 1

DISPLAY A; B;

A=A+B

B=A+B

NEXT ctr

END series( )

 

 

Answer:    

DECLARE SUB series( )

CLS

CALL series

END

SUB series ()

REM program to generate 3 3 6 9 15 ….up to 20th terms

A=3

B=3

FOR CTR = 10 TO 1 STEP -1 OR FOR CTR=1 TO 10

PRINT A; B;

A=A+B

B=A+B

NEXT ctr

END SUB

17)    SLC 2063

REM program to find the square root of given program.

DECLARE SUB square(N)

ENTER n

DISPLAY square (N)

END

SUB square(N)

S=m ^ 0.5

PRINT s

FINISH

Answer:

DECLARE SUB square(N)

INPUT n

CALL square (N)

END

SUB square(N)

S=n^ 0.5

PRINT s

END SUB

 

18)

REM program to display all the pass students records on the screen from the sequential data file "test.txt"

OPEN "test.txt" FOR OUTPUT as #5

PRINT "Name","Class","Result"

DO WHILE EOF(5)

INPUT n$, c, r$

IF r$="pass" THEN PRINT n$,c,r$

WEND

CLOSE #5

END

 

Answer:

CLS

REM program to display all the pass students records on the screen from the sequential data file "test.txt"

OPEN "test.txt" FOR INPUT AS #5

PRINT "Name","Class","Result"

DO WHILE EOF(5)

INPUT #5, n$, c, r$

IF r$="pass" THEN PRINT #5,n$,c,r$

LOOP

CLOSE #5

END

19)

CLS

DECLARE FUNCTION sum(n)

INPUT "Enter how many numbers:-";n

s=sum(n)

PRINT "Sum=";sum

END

FUNCTION sum(n)

FOR x= 1 to n

su=su+sum

NEXT x

su=sum

END FUNCTION

Answer:

DECLARE FUNCTION sum(n)

INPUT "Enter how many numbers:-";n

s=sum(n)

PRINT "Sum=";s

END

FUNCTION sum(n)

FOR x= 1 to n

su=su+x

NEXT x

Sum=su

END FUNCTION

 

 

20)    SLC 2068

CREATE FUNCTION square(a)

REM to print square of a number

CLS

GET “a number”;a

CALL square (a)

END

FUNCTION square (a)

Ans=a^2

Square =Ans

END square(a)

 

Answer:

DECLARE FUNCTION square (a)

REM to print square of a number

CLS

INPUT “A number”;a

PRINT square(a)

END

FUNCTION square (a)

ANS =a^2

Square = Ans

END FUNCTION

 

21)    SLC 2069

Re-write the given program after correcting the bugs:

REM display records of students from data file

OPEN “STDREC.DAT” FOR INP AS #1

PRINT “ROLL”, “NAME”, “ADDRESS”, “CLASS”, “SECTION”

DO WHILE NOT EOF

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

PRINT RN, N$, AD$, CL, S$

NEXT

CLONE#1

END

 

Answer:

REM display records of students from data file

OPEN “STDREC.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, N$, AD$, CL, S$

LOOP

CLOSE #1

END

 

 

22)    SLC 2070

DECLARE SUB series()

CLC

EXECUTE series

 END

SUB series

 RE to generate 2 2 4 6 10 ……upto 10th term

 P=2

Q=2

FOR ctr=1 TO 5

DISPLAY p,q,

P=p+q

Q=p+q

WEND

END series()

 

Answer:

DECLARE SUB series()

CLS

CALL series

END

SUB series

REM to generate 2 2 4 6 10 ……upto 10th term

P=2

Q=2

FOR ctr=1 TO 5

PRINT p,q,

P=p+q

Q=p+q

NEXT

END SUB

 

23)    SLC 2068 Supp.

REM to display the contents of data file

OPEN “marks.dat” FOR OUTPUT AS #1

CLS

WHILE EOF(1)

INPUT #1 name$,age,add$

DISPLAY name$,age,add$

WEND

CLOSE 1

END

 

Ans:

REM to display the contents of data file

OPEN “marks.dat” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1 name$,age,add$

PRINT name$,age,add$

WEND

CLOSE #1

END

 

24)    SLC 2067 Supp.

DECLARE SUB series()

CLS

EXECUTE series

END

SUB series

REM program to generate 11235…upto the 20th term.

A=1

B=1

FOR ctr= 10 to 1

DISPLAY a;b;

A=a+b

B=a+b

NEXT ctr

END series()

 

Ans:

DECLARE SUB series()

CLS

CALL series

END

SUB series

REM program to generate 11235…upto the 20th term.

A=1

B=1

FOR ctr= 1 to 10

PRINT a;b;

A=a+b

B=a+b

NEXT ctr

END SUB

 

25)    SLC 2070 (Supplementary)

OPEN “student.dat” FOR APPEND AS 1#

INPUT “Name”;n$

INPUT “Address”’add$

INPUT “Age”;age$

WRITE #1,n$,add$,age

END #1

STOP

 

Ans: 

OPEN “student.dat” FOR APPEND AS #1

INPUT “Name”;n$

INPUT “Address”’add$

INPUT “Age”;age

WRITE #1,n$,add$,age

CLOSE #1

END

 

26)    SLC 2071

DECLARE SUB cube (n)

CLS

FOR I = 1 TO 5

READ

CALL cube (no)

NEXT x

DATA 3,5,2,6,4

END

SUB cube ( )

DISPLAY n^3

END SUB 

 

Ans

DECLARE SUB cube (n)

CLS

FOR I = 1 TO 5

READ (no)

CALL cube (no)

NEXT I

DATA 3,5,2,6,4

END

SUB cube (n )

PRINT n^3

END SUB

 

27)   

REM to add more records in the existing data file

OPEN “INFO.DAT” FOR OUTPUT AS #2

DO

INPUT “REG”; REG$

INPUT “NAME”; NAME$

INPUT “TEL”; TEL$

WRITE REG$,N$,TEL$

INPUT “WANT TO ADD MORE(Y/N)”; YN$

LOOP WHILE UCASE$(YN$)=Y

CLOSE #2

END

 

Ans: 

REM to add more records in the existing data file

OPEN “INFO.DAT” FORAPPENDAS #2

DO

INPUT “REG”; REG$

INPUT “NAME”; NAME$

INPUT “TEL”;TEL

WRITE#2REG$,N$,TEL

INPUT “WANT TO ADD MORE(Y/N)”; YN$

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

CLOSE #2

END

 

28)   

REM to display records from 2nd position to 6th position

OPEN record.txt FOR INPUT AS #2

DO WHILE EOF(2)

INPUT #1, N, Add$, DOB$

C=C+1

IF C<=2 AND C>=6 THEN

PRINT N$, Add$, DOB$

END IF

LOOP

CLOSE #2

END

 

Ans:

REM to display records from 2ndposition to 6thposition

OPEN“record.txt”FOR INPUT AS #2

DO WHILENOTEOF(2)

INPUT#2,N$, Add$, DOB$

C=C+1

IF C>=2 AND C<=6THEN

PRINT N$, Add$, DOB$

END IF

LOOP

CLOSE #2

END

 

29)    SEE 2072

FUNCTION SUM(m,n)

Rem to print sum of two numbers

a=6

b=7

DISPLAY SUM(a,b)

END

FUNCTION SUM(m,n)

S=m+n

S=SUM

END SUM

 

Ans:

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 SUB

 

30)    SEE 2073

DECLARE SUB SUM(N)

INPUT “Any Number”; N

PRINT SUM(N)

END

SUB SUM (N)

S=0

WHILE N=0

R= R MOD 10

S=S+R

N=N/10

WEND

PRINT “Sum of digits”;S

END

 

Ans:

DECLARE SUB SUM(N)

INPUT “Any Number”; N

CALL SUM(N)

END

SUB SUM (N)

S=0

WHILE N<>0

R= N MOD 10

S=S + R

N=N 10

WEND

PRINT “Sum of digits”;S

END SUB

 

31)    SEE 2073 Supp.

DECLARE SUB serries()

CLS

EXECUTE series

END

SUB series

REM program to print 4 4 8 12 20 .....20th term

x=4

y=4

FOR ctr 10 TO 1

DISPLAY x;y;

x=x+y

y=x+y

NEXT ctr

END series

 

 

Ans:

DECLARE SUB serries()

CLS

CALL series

END

SUB series

REM program to print 4 4 8 12 20 .....20th term

x=4

y=4

FOR ctr 10 TO 1 STEP -1

PRINT x;y;

x=x+y

y=x+y

NEXT ctr

END SUB

 

32)    SEE 2074

REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N$)
CLS
INPUT "Enter a number"; X
PRINT "The Factorial is: ", FACTO (N)
END

FUNCTION FACTO (N)
F = 1
WHILE N = 0
F = F * N
N = N - 1
WEND
F = FACTO
END FUNCTION

 

Debugged:

REM To find the factorial of a given number
DECLARE FUNCTION FACTO (N)
CLS
INPUT "Enter a number", X
PRINT "The Factorial is :", FACTO (X)
END


FUNCTION FACTO (N)
F = 1
WHILE N > 0
F = F * N
N = N – 1
WEND
FACTO = F
END FUNCTION

 

33)    SEE 2074 Upgrade

Rem To print only class 10 record from "student.dat"

CLS

OPEN "I",#2, "Student.Dat"

WHILE NOT EOF (#2)

WRITE#2, N$,C,R

IF C=10 THEN

DISPLAY N$,C,R

END IF

NEXT

CLOSE #2

END

 

Debugged program

Rem To print only class 10 record from “student.dat”

CLS

OPEN I” , #, “Student.Dat

WHILE NOT EOF (2)

INPUT #2N$CR

IF C=10 THEN

PRINT N$CR

END IF

WEND

CLOSE #2

END

 

34)    SEE 2075

DECLARE FUNCTION reverse$(N$)

INPUT “Any String”; N$

X$ = reverse$(N$)

PRINT N$

END

FUNCTION reverse(N$)

L = LEN$(N$)

FOR X = L to 1 STEP – 1

A$ = MID$(N$, X, I)

B$ = B$ + A$

NEXT X

B$ = reverse$(N$)

END FUNCTION

 

Debugged Program

DECLARE FUNCTION reverse$(N$)

INPUT “Any String”; N$

X$ = reverse$(N$)

PRINT X$

END

FUNCTION reverse$(N$)

L = LEN(N$)

FOR X = L to 1 STEP – 1

A$ = MID$(N$, X, 1)

B$ = B$ + A$

NEXT X
reverse$ = B$

END FUNCTION

 

 

35)      

REM to print odd numbers from 32 to 12

DECLARE SUB SHOW ( )

CLS

CALL SHOW ( )

END

 

SUB SHOW ( )

N = 12

WHILE N <= 32

IF N MOD 2 = 0 THEN PRINT N;

N = N-1

NEXT N

END SUB

 

 

Debugged program

REM to print odd numbers from 32 to 12

DECLARE SUB SHOW ( )

CLS

CALL SHOW

END

 

SUB SHOW ( )

N = 32

WHILE N >= 12

IF N MOD 2 = 0 THEN PRINT N;

N = N-1

WEND

END SUB

 

36. 

REM program t make a word reverse.

DECLARE FUNCTION rev$(n$)

CLS

LNPUT "Enter a word";n$

DISPLAY "Reserved 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

 


REM program t make a word reverse.

DECLARE FUNCTION rev$(n$)

CLS

INPUT "Enter a word";n$

PRINT "Reserved 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

Post Top Ad

Your Ad Spot

Pages