50 QBASIC ANALYTICAL PROGRAMMING QUESTIONS COLLECTIONS 2081 - SEE COMPUTER SCIENCE
1. [SLC 2064]
DECLARE FUNCTION
CELLS$(W$)
W$=”CYBER”
PRINT CELL$(W$)
END
FUNCTION CELL$
K=LEN(W$)
FOR I = K TO 1
STEP -2
M$=M$+MID$(W$,I,1)
NEXT I
CELLS$=M$
END FUNCTION
a)
Why
is $(dollar) sign followed in the function name?
b)
What
will be the output of the program when it is executed?
c)
What
will be the output of the program when FOR loop is changed as FOR I= 1 TO K
STEP 2?
d)
What
is the name of sign “+” used in the program and what operation does it perform?
2. [SEE 2080 L]
DECLARE SUB AA (N$)
W$=CYBERCRIME"
CALL AA(W$)
END
SUB AA (N$)
R=LEN(N$) \ 2
E$=RIGHT$(N$,R) +
LEFT$(N$,R)
PRINT E$
END SUB
Questions:
a) List the
parameter(s) and argument(s) of the program.
b) List all the
string library functions from the program.
3. [SEE 2080 P]
DECLARE FUNCTION
OUTPUTS(W$)
CLS
W$="CYBER
CRIME"
PRINT OUTPUT$ (W$)
END
FUNCTION OUTPUT$
(W$)
FOR M= LEN(W$) TO
1 STEP-2
M$=M$+MID$(W$, M,
1)
NEXT M
OUTPUT$=M$
END FUNCTION
a Why is $ sign is
followed by function name?
Ans: The $ sign is
followed by function name because the function returns string value.
b. List the
library function used in the above program.
Ans: The library
function used in the above program are LEN( ) and MID$( ).
4. [SLC 2065]
DECLARE FUNCTION
xyz(N)
FOR I = 1 TO 5
READ N
Z=xyz(N)
S=S+Z
NEXT I
PRINT S
DATA 10,13,15,4,6
END
FUNCTION xyz(N)
IF N MOD 2=0 THEN xyz=N
END FUNCTION
a) What is the name of the function used in the above program?
b) How many times the function will be called in the above program?
3. [SLC 2072]
DECLARE FUNCTION
Prod(N)
INPUT “Any number”;N
X=Prod(N)
PRINT X
END
FUNCTION Prod(N)
F=1
FOR K=1 TO N
F=F*K
NEXT K
Prod=F
END FUNCTION
a) Write the name of the user defined
function used in the above program.
b) Name the loop in the above
program.
5. [SLC 2071 S]
DECLARE FUNCTION JPT
(N)
FOR ctr = 1 TO 6
READ N
J = JPT (N)
Sum = Sum + J
NEXT ctr
PRINT Sum
DATA 10, 20,
30, 40, 50, 60
END
FUNCTION
JPT (N)
IF
N MOD 2 = 0 THEN JPT = N
END
FUNCTION
a) What is name to the function used in the
above program?
b) How many times the function will be
executed in the above program?
6. [SEE
2078 NP]
DECLARE SUB PC$ (N)
CLS
INPUT
"Enter a number"; N
CALL PC$ (N)
END
SUB PC$ (N)
FOR I=2 TO N-1
R=N MOD I
IF C=0 THEN
PRINT "Prime
number"
ELSE
PRINT
"Composite number"
ENDIF
END SUB
a. What
is the name of sub procedure?
b. List
the local variable.
7. [SEE
2080 P]
DECLARE FUNCTION
prod(a,b)
CLS
INPUT "Enter
first number" ;a
INPUT "Enter
second number" ;b
PRINT "The
product of two number is" ;prod(a,b)
END
FUNCTION prod(a,b)
P=a*b
Prod=p
END FUNCTION
i) List the
numerical variables used in above program.
ii) List the
local variables used in above program.
8. [SLC
2067]
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”;S
END
SUB
i) In which condition the statements within
the WHILE….WEND looping statement will not be executed?
ii) Will
the output be the same if we place “/” instead of”\” in the above program.
9. [SLC
2070]
DECLARE
FUNCTION Sum(A,B)
INPUT
“Enter first number:”; A
INPUT
“Enter second number:”; B
PRINT
“The sum of the two number=”;Sum(A,B)
END
FUNCTION
SUM(A,B)
S=A+B
Sum=S
END FUNCTION
a) List the
numerical variables used in the above program.
b) Will the
program run if the first line (i.e. DECLARE….) is deleted?
10. [SEE 2073]
DECLARE FUNCTION Diff(A, B)
CLS
INPUT “Enter first number”; A
INPUT “Enter second number”; B
PRINT “The difference”; Diff(A, B)
END
FUNCTION Diff(A, B)
Difference= A – B
Diff = difference
END FUNCTION
List all the numeric variables used in th
above program
List the local variables used in the above program.
11. [SLC 2067 S] [SEE
2078 GP] [SEE 2079 GP]
DECLARE FUNCTION
Prod(A,B)
CLS
INPUT “Enter first
number:”;A
INPUT “Enter
second number:”;B
PRINT “the product
of two number=”;Prod(A,B)
END
FUNCTION Prod(A,B)
P=A*B
Prod=P
END FUNCTION
a) List all the
numerical variables used in the program.
b) List all the
local variables used in the program.
12. [SEE 2074]
DECLARE
FUNCTION SUM (N)
CLS
INPUT "Enter any number"; N
S = SUM (N)
PRINT "The Sum of individual digit is"; S
END
FUNCTION SUM (N)
WHILE N > 0
R = N MOD 10
T = T + R
N = N \ 10
WEND
SUM = T
END FUNCTION
a) State the purpose of suing variable S in line 4 in above program.
b) Write the use of MOD in the above program.
13. [SEE 2080 P]
DECLARE SUB
FACTORS(N)
N=10
CALL FACTORS(N)
END
SUB FACTORS(N)
FOR J=1 TO N
R=N MOD J
IF R=0 THEN PRINT
J;
NEXT J
END SUB
Questions:
a) Write down the
use of MOD in the program.
b) How many time
the loop executes in the above program?
14. [SEE 2075 S2]
DECLARE SUB TRIM(W$)
CLS
INPUT "Enter
word"; WO$
CALL TRIM(WO$)
END
SUB TRIM (W$)
FOR I = 1 TO LEN(W$)
PRINT
LEFT$(W$, I)
NEXT I
END SUB
a) What will be the maximum value of I if input
string is “SEE” in the above program?
b) List the real parameter used in the above
program.
15. [SEE 2079 B]
DECLARE FUNCTION ABC$(N$)
CLS
INPUT “ENTER ANY WORD”; W$
PRINT “THE RESULT STRING IS”; ABC(W$)
END
FUNCTION ABC$ (N$)
FOR I=1 TO LEN (N$)
P$=MID$ (N$,I,1)
R$=P$+R$
NEXT I
SHARED R$
ABC$=R$
END FUNCTION
a) List the arguments and parameters used in above
program
b) What is the use of SHARED in above program?
16. [SEE 2080 PB]
DECLARE SUB question
(a, b, c)
CLS
x=10: y=20 : z=15
CALL question(x,y,z)
END
SUB question(a,b,c)
a = a +10
b = b + a
c = a + b
PRINT a,b,c
END SUB
a) What would be its output if
x=1,y=2, z=3?
b) Write actual and formal parameters used
in the program.
17. [SEE 2078 P]
DECLARE FUNCTION test$ (A$)
CLS
INPUT “ENTER ANY WORD”; T$
PRINT test$(t$)
END
FUNCTION test$ (A$)
FOR M = LEN(A$) TO 1 STEP -1
C$= C$+ MID$(A$, M,1)
NEXT M
Test$ = C$
END FUNCTION
a) List the formal and actual
parameters used in the program given above.
b) List the library function used in
the above program.
18. [SEE 2080 NP]
DECLARE FUNCTION
Calculate (X,Y)
CLS
INPUT "Enter
a multi-digit number"; N
LET S = Calculate
(N,T)
PRINT "The
sum =”; S
END
FUNCTION Calculate
(X,Y)
WHILE X < >
0
R=X MOD 10
Y = Y + R
X=X\10
WEND
Calculate = Y
END FUNCTION
a) List formal
parameters and real parameters of procedure Calculate'.
b) What is the
purpose of the above program?
19. [SEE 2078] [SEE 2074 U]
DECLARE FUNCTION
TEST(X)
X=100
Z=TEST(X)
PRINT Z
END
FUNCTION TEST(X)
FOR R=1 TO X
S=S+I
NEXT R
TEST=S
END FUNCTION
a) How many
parameters are used in the above program?
b) How many times
does the statement S=S+I execute in the above program?
20. [SEE PABSON 2080
PD]
DECLARE FUNCTION
text$(N$)
CLS
INPUT "Enter
any string":X$
PRINT text$(X$)
END
FUNCTION text$(N$)
FOR i=len (N$) TO 1
STEP-1
W$=W$+MID$(N$,i,1)
NEXT i
text$ = WS
NEXT Q
END FUNCTION
Questions:
a) What is the main
objective of above program?
b) List all the
parameters used in above program.
21. [SEE 2079] [SEE
2078 GP]
DECLARE FUNCTION
SUM(N)
CLS
INPUT “Enter any number”; N
X=SUM(N)
PRINT “The sum of individual
digit is “; X
END
FUNCTION SUM(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=INT(N/10)
WEND
SUM=S
END FUNCTION
a) Write the
function of INT.
b) How many times
does the WHILE ….WEND loop repeat if the value of N is 123?
22. [SEE 2080 P]
DECLARE SUB
string(x$)
CLS
X$=“COMPUTER"
CALL string(X$)
END
SUB string(x$)
L=LEN(X$)
FOR A = L to 1
step -2
PRINT
MID$(x$.A,1);
NEXT A
END SUB
Questions:
a) What is the
value of L in the above program?
b) List the
numeric and string variable in the above program.
23. [SLC 2065 S]
DECLARE FUNCTION
Diff(A,B)
CLS
INPUT “Enter first
number”;A
INPUT “Enter
second number”;B
PRINT “The
difference of the two number=”;Diff(A,B)
END
FUNCTION Diff(A,B)
D=A-B
Diff=D
END FUNCTION
a) What will be
the output of the program if the user enters 200 as the first number and 100 as
the second number.
b) Will the
program run if the first line (i.e. DECLARE…..) is deleted?
24. [SEE 2080 P
DECLARE SUB TEST(A$)
CLS
A$= “COMPUTER”
END
SUB TEST (A$)
L= LEN(A$)
FOR I = L TO 1 STEP -2
PRINT MID$(A$, I, 1)
NEXT I
END SUB
a) What
statement should be added in the main module to execute the program?
b) List
out the variables used in the above program with types.
25. [SLC
2068 S]
DECLARE SUB
ABC(X,Y,Z)
FOR P=1 TO 3
READ A,B,C
CALL ABC(A,B,C)
NEXT P
DATA
5,4,3,2,1,6,7,8,4
END
SUB ABC(X,Y,Z)
T=X+Y+Z
IF T MOD 2 = 0 THEN
PRINT T
END IF
END SUB
a) List any two
variables used in the above program.
b) How many times
SUB-procedure will be called when program is executed?
26. [SLC 2069 S]
DECLARE FUNCTION
CHK$(N)
CLS
N=57
PRINT “The number is”; CHK$(N)
END
FUNCTION CHK$(N)
FOR I = 1 TO N
IF N MOD I = 0
THEN C=C+1
NEXT I
IF C>2 THEN
CHK$=”Composite”
ELSE
CHK$=”Prime”
END IF
END FUNCTION
a) Will the above
program execute if “DECLARE FUNCTION….” Is deleted
b) Why $ sign is used in the name of the above function
27. [SEE 2073 U]
DECLARE FUNCTION SUM
(A, B)
INPUT A
INPUT B
X = SUM (A, B)
PRINT X
END
FUNCTION SUM (A, B)
S = A+B
SUM = S
END FUNCTION.
a) Write the name of local variable
used in the above FUNCTION procedure.
b) Write the Mathematical operator and
Relation operator used in above program.
28. [SLC 2070 S]
DECLARE
FUNCTION rev$ (N$)
INPUT "Any string"; N$
PRINT rev$ (N$)
END
FUNCTION
rev$ (N$)
FOR X = LEN (N$) to 1 STEP -1
A$=MID$ (N$, X, 1)
B$ = B$ + A$
NEXT X
rev$ = B$
END
FUNCTION
List
the library function used in the above program.
What
will be the maximum value of X if the N$ is equal to "Computer".
29.
[SEE 2080 P
DECLARE FUNCTION num (N)
FOR 1=1 to 5
READ N
Z=num(N)
S=S+Z
NEXT 1
PRINT S
DATA 11, 14, 16,5, 7
END
FUNCTION num (N)
IF N MOD 2=0 THEN num =N
END FUNCTION
Questions:
a) List the library functions used in the above program.
b ) Write the name of the function used in the above
program.
30. [SLC 2066 S]
DECLARE FUNCTION COUNT(A$)
Input “Enter a word”; W$
END
Function Count(A$)
B=LEN(A$)
C$=UCASE$(A$)
FOR I=1 TO B
E$=MID$(C$,I,1)
IF E$=”A” OR E$=”E” OR E$=”I” OR E$=”O”
OR E$=”U” THEN C=C+1
END IF
NEXT I
COUNT=C
END FUNCTION
a) List the string Library functions used in the above program.
b) Write down the missing statements in the main module to execute the program.
31. [SEE 2080]
DECLARE FUNCTION
Count (W$)
INPUT "Enter a
word"; R$
C = Count (R$)
PRINT C
END
FUNCTION Count (W$)
FOR L = 1 TO LEN
(W$)
Ch$MID$ (W$, L, 1)
IF UCASES
(Ch$) = "K" THEN
N=N+1
END IF
NEXT L
Count = N
END FUNCTION
List any two library
functions used in the above program.
Write the use of
variable 'C' in line 3 [i.e. C = Count (R$)] given in the above program.
32. [SLC 2068]
Declare function
count(N$)
Input “Enter a word”; R$
C= Count(R$)
Print C
END
Function count(N$)
For k=1 to LEN(n$)
X$=MID$(N$,K,1)
IF UCASE$(X$)=”A” then
X=X+1
End if
Next K
Count = X
End function
i) List any two library functions used in the above program.
ii) Write the use of variable ‘C’ inline 3 [i.e. C=Count(R$)] given in the
above program.
33. [SEE 2080 P]
DECLARE FUNCTION COUNT(z$)
CLS
INPUT"ENTER A WORDS="; z$
END
FUNCTION COUNT(z$)
m=LEN(z$)
v$=UCASE$(z$)
FOR I = 1 TO m
v$=MID$(z$,I,1)
IF v$=
"A","E","I","O","U" THEN
g=g+1
END IF
NEXT I v
owel =g
END FUNCTION
What is the name of the functions used in
the above program.
Write down the missing statement in the
main module to execute the program.
34. [SEE 2080 P
DECLARE FUNCTION prod(x,y)
CLS
INPUT "Enter first number" ;x
INPUT "Enter second number" ;y
PRINT "The product of two number is"
;prod(x,y)
END
FUNCTION prod(x,y)
P=x*y
Prod=p
END FUNCTION
List the numerical variables used in above program.
List the local variables used in above program.
35. [SEE 2080 P]
DECLARE FUNCTION
COUNT (NS)
INPUT "Enter a
word"; RS
C=COUNT(RS)
PRINT C
END
FUNCTION COUNT(NS)
FOR K=1 TO LEN(NS)
XS=MIDS(NS,K,1)
IF
UCASES(XS)="A" THEN
X=X+1
END IF
NEXT K
COUNT=X
END FUNCTION
Questions:
a) List any two
library functions used in above program.
b) Write the use of
variable "C" in line 3 [i.e. C=COUNT(RS)] given in the above program.
36. [SEE 2080 P]
DECLARE
FUNCTION NUM(N)
INPUT N
S = NUM(N)
PRINT S
END
FUNCTION NUM(N)
X = INT(17/N)
Y =15 MOD N
NUM = X + Y
END FUNCTON
i. What is the name
of function used in above program?
ii. List the
mathematical function used in above program.
37. [SLC 2071]
DECLARE
SUB Stde(N$U)
FOR
Loop = 1 TO 5
READ
NM$(Loop)
NEXT
Loop
DATA
RAMA, PRATIMA, PRASANT
DATA
NISHA, RUDHRA
CALL
Stde(NM$U)
END
SUB
Stde(N$U)
PRINT
“Name starting from P”
FOR
J = 1 TO 5
C$=MID$(N$,(J),1,1)
IF
C$=”P” THEN
PRINT
N$(J)
END
IF
NEXT
J
END
SUB
a.
List
the library function used in the above program.
b.
List
the conditional statement used in the above program.
38. [SLC 2069]
DECLARE SUB
EXAM(N$)
CLS
INPUT “Enter
word”;WO$
CALL EXAM(WO$)
END
SUB EXAM (N$)
FOR I = 1 TO LEN
(N$)
PRINT RIGHT$(N$,I)
NEXT I
END SUB
a) Write the names
of two built-in functions used in the above program.
b) List the real
parameter in the program.
39. [SLC 2066]
DECLARE FUNCTION
Num(N)
INPUT N
S=Num(N)
PRINT S
END
FUNCTION Num(N)
X=Int(17/N)
Y=15 MOD N
Num=X +Y
END FUNCTION
i) Write the name of the function used in the above program.
ii) List out the mathematical function (Library function) used in the above
program.
40. [SEE 2080 P]
DECLARE FUNCTION
ODDEVEN$(N)
CLS
INPUT ”Enter a
number”; N
PRINT “Number is”;
ODDEVEN$(N)
END
FUNCTION ODDEVEN$(N)
IF N MOD 2=0 THEN
MS$=”even”
ELSE
MS$=”odd”
END IF
ODDEVEN$=MS$
END FUNCTION
a) What is the main objective of above
program?
b) What is the use of MOD in above
program?.
41. [SEE 2080 R]
DECLARE SUB TEST (A, B)
CLS
X= 7
Y = 5
CALL TEST (X, Y)
END
SUB TEST (A, B)
FOR I = A to B STEP -1
A = A+ B
B = B + A
NEXT I
END SUB
a. List the formal parameter and argument.
b. Which loop is used in the above program?
42. [SEE 2080 PC]
DECLARE FUNCTION
text$(N$)
CLS
INPUT "Enter
any string":X$
PRINT text$(X$)
END
FUNCTION text$(N$)
FOR i=len (N$) TO 1
STEP-1
W$=W$+MID$(N$,i,1)
NEXT i
text$ = WS
NEXT Q
END FUNCTION
Questions:
a) What is the main
objective of above program?
b) List all the
parameters used in above program.
43. [SEE 2075]
DECLARE SUB SUM(N)
N = 5
CALL SUM (N)
END
SUB SUM(N)
FOR X = 1 TO N
S =S + X
NEXT X
PRINT S
END SUB
a) In the above program how many times does the
FOR ………..NEXT loop executes?
b) Write the name of the procedure used in the
above program.
44. [SEE 2075 U]
DECLARE SUB TEST (N$
)
INPUT N$
CALL TEST ( N$ )
END
SUB TEST (N$ )
FOR P = 1 TO LEN (
N$ )
B$ = MID$ (N$, P, 1)
IF LCASE$ (B$) = “a”
THEN
C = C + 1
END IF
NEXT P
PRINT C
END SUB
a) Write the name of the sub procedure used
in the above program.
b) Write any two library functions used in
the above program.
45. [SEE 2080 K]
DECLARE FUNCTION
MATH$(R)
CLS
DIM SHARED P
INPUT "Enter
first number:"; P
INPUT "Enter
second number:"; C
Y$ = MATH$(C)
PRINT Y$
END
FUNCTION MATH$(R)
F=100 MOD R
IF 20 MOD P > 3
AND F < P THEN
MATH$=”True”
ELSE
MATH$=”False”
END IF
END FUNCTION
a) Variable P
remained uncalled in the main module. Why?
b) Find the output
if the user supplies P=9 and c=4 running the program.
46. [SEE MODEL 2067]
OPEN “Detail.dat”
FOR INPUT AS #1
OPEN “Temp.dat” FOR
OUTPUT AS #2
INPUT “Enter name of
the students”; S$
FOR I=1 TO 10
INPUT #1, Nm$, Cl, A
IF S$< >Nm$
THEN
WRITE #2, Nm$, Cl, A
END IF
NEXT I
CLOSE #1, #2
KILL “Detail.dat”
NAME “Temp.dat” AS
“Detail.dat”
END
a. What
is the main objective of the program given above?
b. Do
you get any problem in the above program if “Kill” statement is removed? Give
reason.
47. [SEE 2079 NP]
OPEN
"student.txt" FOR OUTPUT AS #1
OPEN
"Tem.txt" FOR INPUT AS #2
WHILE NOT EOF (2)
INPUT #2, reg,
Name$, Add$
IF reg>10 AND reg
<20 then
WRITE #1, reg,
Name$, Add$
END IF
WEND
CLOSE #1, #2
END
( a) Write down the
mode used in above program
(b) Write the name
of String variable used in file based on above program.
48. [SEE 2080 P]
CLS
OPEN
"INFO.DAT" FOR INPUT AS #5
TOP:
INPUT "ENTER
NAME"; N$
INPUT "ENTER
ADDRESS";A$
INPUT "ENTER
PHONE NUMBER";P
WRITE #5, N$, A$, P
INPUT "DO YOU
WANT TO CONTINUE (Y/N)?"; AN$
IF UCASE$ (AN$) =
"Y" THEN GOTO TOP
CLOSE #5
END
Questions:
a) List the variables used in above
program.
b) What is the name of data file used
in above program?
49. [SEE 2079 S]
OPEN “MARKINFO.TXT” FOR INPUT AS #1
OPEN “TEMP.TXT” FOR OUTPUT AS #2
CLS
DO UNTIL EOF(1)
INPUT #1, REGISTRATIONNUMBER,
STUDENTNAME$, ENGLISH, NEPALI,
MATHEMATICS
IF MATHEMATICS<20 THEN
MATHEMATICS=MATHEMATICS+10
END IF
WRITE #2, REGISTRATIONNUMBER,
STUDENTNAME$, ENGLISH, NEPALI,
MATHEMATICS
LOOP
CLOSE#1
CLOSE #2
KILL “MARKINFO.TXT”
NAME “TEMP.TXT” AS “MARKINFO.TXT”
END
a) What is the main objective of the program
given above?
b) Do you get any problem in above program
if “Kill” statement is removed? Give reason.
50. [SEE 2080 S]
OPEN "BUSRIDER.TXT" FOR
INPUT AS #1
OPEN "TEMP.TXT" FOR OUTPUT
AS #2
CLS
WHILE NOT EOF (1)
INPUT #1, STUDENTNAME$, CLASS, BUSCODE,
BUSSTOP$
IF UCASE$(BUSSTOP$) < >
UCASE$("KATHMANDU") THEN
WRITE #2, STUDENTNAME$, CLASS,
BUSCODE, BUSSTOP$
PRINT STUDENTNAME$, CLASS, BUSCODE,
BUSSTOP$

END IF
WEND
CLOSE #1 #2
KILL BUSRIDER.TXT"
NAME "TEMP.TXT" AS
"BUSRIDER TXT”
END
a) What is the main objective of the
program given above?
b) Do you get any problem in above
program if "Kill" statement is removed? Give reason.
51. [SEE 2080]
OPEN “EMP.DAT” FOR
INPUT AS #1
DO
INPUT #1, N$, A$,
S
IF
UCASE$(A$)=”KATHMANDU” THEN
PRINT
N$, A$, S
END IF
LOOP WHILE NOT
EOF(1)
CLOSE #1
END
a. Write
the use of statement “INPUT #1, N$, A$, S” in the above program.
b. What
happens if you remove “UCASE$” from the above program?