SET 15 - Qbasic Debugging Program ----SEE Computer Science 2076 --- Practice Day 15 --- 25 Questions
Debugging
[25]
1.
[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
|
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
|
|||||
2.
[SLC
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(x,y) SUM=a+b END |
[SLC
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(x, y) END FUNCTION SUM(a, b) SUM=a+b END FUNCTION |
|||||
3. [SLC
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
|
[SLC
2072]
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
|
|||||
4.
[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) |
[SLC 2068]
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 |
|||||
5.
[SLC 2064]
[SLC 2067 S] [SLC 2071 S]
DECLARE SUB
Series( )
CLS
EXECUTE Series
END
SUB Series( )
REM program to
generate 3 3 4 9 15 upto 20th
terms.
A=3
B=3
FOR ctr= 10 to
1
DISPLAY A;B;
A=A+B
B=A+B
NEXT ctr
END Series( )
|
DECLARE
SUB Series( )
CLS
CALL Series
END
SUB Series()
REM program to generate 3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1 STEP-1
PRINT A;B;
A=A+B
B=A+B
NEXT ctr
END SUB
|
|||||
6. [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
|
DECLARE SUB Fibonic ()
REM
*Fibonic series*
CALL Fibonic
END
SUB
Fibonic
A=1
B=1
FOR
x=1 to 10
PRINT a; b;
a=a+b
b=a+b
NEXT x
END
SUB
|
|||||
7. [SEE 2065
S]
DECLARE SUB Series()
CLS
EXECUTE 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()
|
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
|
|||||
8.
[SEE 2073 U]
|
|
|||||
DECLARE SUB Series (
)
CLS
EXECUTE Series
END
SUB Series
REM Program to print
4 4 8 12 20 ....... 20th terms
X = 4
Y = 4
FOR ctr = 10 To 1
DISPLAY X; Y;
X = X+Y
Y = X+ Y
Next ctr
End Series
|
DECLARE SUB Series (
)
CLS
CALL Series
END
SUB Series ( )
REM program to
generate 4 4 8 12 20 …20th term
X=4
Y=4
For ctr = 10 TO
1 STEP -1
PRINT C ; Y;
X = X + Y
X = X + Y
NEXT ctr
END SUB
|
|||||
9.
[SLC 2070]
DECLARE
SUB Series( )
CLS
EXECUTE Series
END
SUB Series
REM 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()
|
[SLC
2070]
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 ctr
END
SUB
|
|||||
10.
[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
|
[SEE 2073]
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
|
|||||
11.
[MM 2076]
REM To check the
input no. is perfect square or not
DECLARE FUNCTION
chk$ (a)
CLS
INPUT “Enter the
number :”; a
CALL chk$ (a)
END
FUNCTION chk$(a)
m=SQUARE (a)
n=INT (m)
IF
m=a THEN
c$=”Perfect Square”
ELSE
c$=”Not Perfect
Square”
END IF
C$=chk$
END FUNCTION
|
REM To check the
input no. is perfect square or not
DECLARE FUNCTION
chk$ (a)
CLS
INPUT “Enter the
number :”; a
PRINT chk$ (a)
END
FUNCTION chk$(a)
m=SQR (a)
n=INT (m)
IF m=n THEN
c$=”Perfect Square”
ELSE
c$=”Not Perfect
Square”
END IF
chk$ = c$
END FUNCTION
|
|||||
12.
[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
|
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
|
|||||
13. [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,1)
B$ = B$+A$
NEXT X
B$ = reverse$ (N$)
END FUNCTION
|
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
|
|||||
14. [SLC 2069]
Rem program to reverse the
string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END
SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=LEFT$(W$,I,1)
S$=D$+1
LOOP
PRINT “Reverse string is:”; D$
CLOSE SUB
|
[SLC 2069]
Rem program to reverse the
string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END
SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=MID$(W$,I,1)
S$=S$+C$
NEXT I
PRINT “Reverse string is:”; S$
END SUB
|
|||||
15. [MFT 2076]
|
|
|||||
REM program to display reverse of supplied string
DECLARE SUB REVE (C$)
CLS
INPUT “Enter the value”; C$
FOLLOW REVE (C$)
END
SUB REVE(C$)
FOR J = 1 to LEN(C$)
B$ = MID$(C$, 1, J)
A$=A$+B$
LOOP J
PRINT A$
END SUB
|
REM program to display reverse of supplied string
DECLARE SUB REVE (C$)
CLS
INPUT “Enter the value”; C$
CALL
REVE (C$)
END
SUB REVE(C$)
FOR J = LEN(C$)
TO 1 STEP -1
B$ = MID$(C$, J,
1)
A$=A$+B$
NEXT
J
PRINT A$
END SUB
|
|||||
16. [PMT
2075]
|
|
|||||
DECLARE FUNCTION
REV$ (ST$)
CLS
INPUT “Enter
string”, S$
LET R$= REV$(st$)
PRINT "The
reverse string is :"; R$
END
FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO
1
RV$= RV$+ MID$(ST$,
1, I)
NEXT I
RV$=REV$
END FUNCTION
|
DECLARE FUNCTION
REV$ (ST$)
CLS
INPUT “Enter
string”, S$
LET R$= REV$(S$)
PRINT "The
reverse string is :"; R$
END
FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1 STEP - 1
RV$= RV$+ MID$(ST$, I, 1)
NEXT I
REV$=RV$
END FUNCTION
|
|||||
17.
[SLC
2067]
REM to display all the records from
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 |
[SLC
2067]
REM to display all the records from
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 |
|
|
|
|
18.
[SLC
2068 S]
Rem to
display the contents of a 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 |
[SLC 2068 S]
Rem to
display the contents of a 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 |
19.
[SLC
2069]
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
CLOSE
#1
END
|
[SLC
2069]
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
|
20.
[SLC 2066 S]
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 #2, N$,P$, S
CLOSE #1
END
|
[SLC
2066 S]
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
|
21.
[SLC
2070 S]
OPEN "STUDENT.DAT" FOR
APPEND AS 1#
INPUT "NAME"; N$ INPUT "ADDRESS"; ADD$ INPUT "AGE"; AGE$ WRITE #1, N$, ADD$, AGE END# 1 STOP |
OPEN
"STUDENT.DAT" FOR APPEND AS #1
INPUT "NAME"; N$ INPUT "ADDRESS"; ADD$ INPUT "AGE"; AGE WRITE #1, N$, ADD$, AGE CLOSE # 1 END |
22. [SEE
2075 U]
|
|
REM program to read
data from the data file.
OPEN “STD.DAT” FOR
OUTPUT AS #1
CLS
WHILE NOT EOF(#1)
WRITE#1, N$, R, C, P
PRINT N$, R, C, P
WEND
CLOSE “STD.DAT”
END
|
REM program to read
data from the data file.
OPEN “STD.DAT”
FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, R, C, P
PRINT N$, R, C, P
WEND
CLOSE #1
END
|
23. [SEE 2074 U]
|
|
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
|
Rem To
print only class 10 record from “student.dat” CLS
OPEN “I” , #2 , “Student.Dat”
WHILE
NOT EOF (2)
INPUT #2, N$, C, R
IF
C=10 THEN
PRINT N$, C, R
END IF
WEND
CLOSE #2 END
|
24.
[SQE 2075K]
|
|
REM to copy from old file to new file
OPEN "info.dat" for INPUT AS #1 OPEN "temp.dat" for OUTPUT AS #2 DO UNTIL EOF(1) INPUT #2, n$, p$, d$, s WRITE #1, n$, p$, d$, s WEND CLOSE #2, #2 END |
REM to copy from old file to new file
OPEN "info.dat" for INPUT AS #1 OPEN "temp.dat" for OUTPUT AS #2 DO UNTIL EOF(1) INPUT #1, n$, p$, d$, s WRITE #2, n$, p$, d$, s LOOP CLOSE #1, #2 END |
25.
[SQE
2074K]
|
|
REM to print only male record on the printer from the data file.
OPEN "EMP.DAT" FOR OUTPUT AS #1
DO
INPUT #4, N$, A%, S$
SELECT CASE S
CASE MALE
PRINT N$, A%, S$
END SELECT
LOOP UNTIL EOF(1)
STOP #1
END
|
REM to print only male record on the printer from the data file.
OPEN "EMP.DAT" FOR INPUT AS
#1
DO
INPUT #1, N$, A%, S$
SELECT CASE S$
CASE "MALE"
PRINT N$, A%, S$
END SELECT
LOOP UNTIL EOF(1)
CLOSE #1
|
No comments:
Post a Comment