Wednesday, September 27, 2017

Analytical Questions Qbasic Programs [SEE Qbasic Practice PART III]

1.      Declare Function St$(s$)
Let P$=”SCHOOL”
Z$=St$(P$)
Print z$
End

Function St$(S$)
Q=1
DO
Y$=Y$+ mid$(S$, Q, 1)
Q=Q+2
Loop While Q < = Len(s$)
St$=Y$
End function

i.List all strings variable used in above program.
ii.How many times ‘Do……Loop’ execute in above program?

2.      DECLARE FUNCTION TEST$(S$)
CLS
INPUT”ENTER A STRING”;S$
PRINT TEST$(S$)
END

FUNCTION TEST$(S$)
FOR I=LEN(S$) TO 1 STEP-1
M$=MID$(S$,I,1)
V$=V$+M$
NEXT I
TEST$=V$
END FUNCTION

a) List the string and numeric variables used in above program.
b) What will be the output if S$=”EDUCATION”

3.      DECLARE FUNCITON ALTER$(M$)
A$ = “NATIONAL”
PRINT ALTER$(A$)
PRINT ALTER$(“NEPAL”)
END

FUNCITON ALTER$(A$)
B = LEN(A$)
FOR K = 1 TO B STEP 3
C$ = LEFT$(A$,K)
NEXT K
ALTER$ = C$
END FUNCITION

i.List the numeric variable used in the USB MODULE.
ii.How many times the same function activated here?
iii.Are the values returned by the function same each time?
iv. Write the output of this program.

4.      DECLARE FUNCTION B(N)
CLS
LET N = 12345
PRINT "Sum of Digits :"; B(N)
END

FUNCTION B(N)
WHILE N <> 0
R = N MOD 10
C = C+R
N = INT(N/10)
WEND
B = C
END FNCITON

i.Write the variables used in the program with their type.
ii.List out the different types of operators with their type used in the program.

5.      DECLARE SUB WORD(N$)
CLS
N$=”SCIENCE”
CALL WORD(N$)
END

SUB WORD(N$)
B=LEN(N$)
C=1
WHILE C<=B
M$=MID$(N$, C,1)
PRINT M$;
C=C+2
WEND
END SUB

i.For how many times will the loop execute?
ii.List out the numeric and string variables used in the above program.

6.      DECLARE SUB WORD (N$)
CLS
N$="PABSON”
CALL WORD (N$)
END

SUB WORD (N$)
B=LEN (N$)
C=1
WHILE C < B
M$=MID$(N$, C, 1)
PRINT M$
C=C+2
WEND
END SUB

i) List the string and numeric variables used in the program.
ii) What is the value of B in the above program?



7.      DECLARE SUB check (N$)
n$ = “MNMB FIRST TERM EXAMINATION 2072”
CALL check (n$)
END

SUB check (n$)
b = LEN (n$)
count = 0
WHILE count <= b
X$ = X$ + MID$(n$, count, 1)
count = count + 2
WEND

PRINT X$
END SUB

i.What will be the value of ‘b’ in above program?
ii.List the numeric and string variables used in above program.
8.      DECLARE SUB RE(A$)
CLS
INPUT “ENTER A STRING”;A$
CALL RE(A$)
END

SUB RE(A$)
FOR I=LEN(A$) TO 1 STEP -1
C$ = C$ + MID$(A$, I, 1)
NEXT I
PRINT C$
END SUB

i.Write the variables used in the program with their type.
ii.List out the different types of operators with their type used in the program.

9.      DECLARE SUB TEST(A$)
COMMON SHARED X
CLS
INPUT "ENTER A STRING";B$
CALL TEST(B$)
PRINT X
END

SUB TEST(C$)
X=0
FOR I=1 TO LEN(C$)
D$=MID$(C$,I,1)
E=ASC(D$)
IF E MOD 2=0 THEN X=X+1
NEXT I
END SUB

i.Write different variable used in the program with their types.
ii.How many parameters are used in above SUB procedure?
iii.List out the operators used in the program with their types.
iv.What will be the output if user supplies "ABCD"?

10.   DECLARE SUB Strin(X$)
X$= “Computer”
END

SUB Strin(X$)
L=LEN(X$)
FOR I = L to 1 step-2
PRINT MID$(X$,I,1);
NEXT I
END SUB

i)What statement should be added in main module to execute program?
ii) What will be the output of the program?
iii) What will be the value of L if X$=”Nepal”
iv) List out numeric and string variables used in the program.


11.   DECLARE SUB Exam()
CLS
CALL Exam
END

SUB Exam
LET X=567
LET Y= X MOD 10
LET X1= INT(X/10)
LET Y1=X1 MOD 10
LET X2 = INT(X/10)
LET A =X2+Y1+Y
PRINT “The result is:”;A
END SUB

i.List the mathematical operators used in the above program.
ii.Write the value of variable A.

12.   DECLARE FUNCTION CUBE(T,R)
CLS
N=15
S=CUBE (2,4)
PRINT “CUBE=”; S
END

FUNCTION CUBE(P, M)
CUBE = P^3
N = 5 * 2
END FUNCTION

i.How many parameters are used in above program?
ii.List two mathematical operators used in the above program.

13.   DECLARE FUNCTION AB(n)
CLS
INPUT “Enter any number”;x
PRINT  “Result =”;AB(x)               
END


FUNCTION AB (n)
WHILE n<>0
r = n mod 10
s=s*10 + r
n = n\ 10
WEND
AB = s
END FUNCTION

i.What output displayed by computer if you enter 54.
ii.List the arithmetic operators used in above program.

14.   DECLARE FUNCTION XYZ$ (N$)           
X$=XYZ$(“SENDUP”)
PRINT X$
END

FUNCTION XYZ$(M$)
FOR K=LEN(M$) TO 1 STEP -1
C$ =MID$(M$, K, 1)
T$ = T$ + C$
NEXT I
XYZ$ = T$
END FUNCTION

i.Write the function of “XYZ$ = T$” in the above program.
ii.List the operators with their types used in the above program.

15.   DECLARE SUB TEST(A$)
CLS
INPUT “Enter a String”; B$
CALL TEST(B$)
END

SUB TEST(C$)
FOR I=1 TO LEN(C$)
D$ = MID$(C$,I,1)
E = ASC(D$)
IF E MOD 2 = 0 THEN
W$ = W$ + UCASE$(D$)
ELSE
W$ = W$ + LCASE$(D$)
ENDIF
NEXT I
PRINT W$
END SUB

i.List out the different parameters used in the program and mention its types.
ii.Write the different operators used in the program and mention its types.
iii.What is the function of CALL TEST(B$) statements?
iv.What will be the output if users entered NEPAL?
16.   DECALRE FUNTION MIN(X, Y)
CLS
A= 4: B=20
PRINT “Minimum Value is”; MIN (A, B)
PRINT MIN (100,200)
PRINT MIN (100, 200)
END

FUNTION MIN(X, Y)
IF X<Y THEN
MIN = X
ELSE
MIN = Y
END IF
END FUNCTION

i.How many time the function MIN () will be executed while running the above program?
ii.What will be the output of the program?

17.   DECLARE FUNCTION CHECK$(n)
CLS
INPUT”Any number”;num
C$=check$(num)
Print c$
End

FUNCTION cnt=0 then
F=f+1
End if
Next cnt
If f=2 then
Check$=”prime”
ELSE
Check$=”composite”
END IF
END FUNCTION

a. Can you write CLS statement before declare statement? If no why?
b. What is the return value by the function name check$?
c. If the value of num is 5,now mention the initial value of num, f, n and check$ when function body is called.
d. What will be the final output?

18.   DECLARE FUNCTION A(X)
X=5
Z=A(X)
PRINT Z
END

FUNCTION A(X)
FOR I = 1 TO X
S=S+I
NEXT I
A=S
END FUNCTION

a) How many parameters are used in the program?
b) How many times execute the expression S=S+I in the above program?
c) If the line S = S + I is changed to S = S + I ^ 2 then find the output.

19.   DECALRE FUNCTION COUNT$(A$)
CLS
PRINT COUNT$(“SCIENCE LEARNING CENTER”)
END

FUNCITON COUNT$(B$)
SHORT$ = LEFT$(B$,1)+”.”
I = L
WHILE C<=LEN(B$)
C$ = MID$(B$,I,L)
IF C$ = “ “ THEN
SHORT$ = SHORT$ + LEFT$(B$,I+L)+”.”
I = I +L
WEND
COUNT$ = SHORT$
END FUNCTION

i.Write the output of the above program.
ii.What will be the output if “computer science” is passed to function as argument?

20.   DECLARE FUNCTION Highest (M, N)
CLS
M=5 : N=10
PRINT Highest (M, N)
END

FUNCTION Highest(T,P)
While P<>0
R=T MOD P
T=P
P=R
Wend
Highest=T
End Function

i.What is the value the function returns in this program?
ii.What will happen if R=T Mod P is replaced by R=P MOD T?


21.   DECLARE FUNCTION B (N)
INPUT “ENTER A NUMBER”; N
PRINT “THE EQUIVALENT NUMBER IS = “; B(N)
END

FUNCTION B (N)
WHILE N<>0
r = N MOD 2
j$ = STR$(r)
SUM$ = j$ + SUM$
N = N\2
WEND
B = VAL(SUM$)
END FUNCTION

i. What will be the output of the program, if the value is 9?
ii. What is the use of VAL function in the above program?

22.   DECLARE FUNCTION RESULT(N)
PRINT RESULT(16)
END

FUNCTION RESULT(N)
WHILE N<>0
A=N MOD 2
N=N\2
E$=STR$(A)
F$=E$+F$
WEND
RT= VAL(F$)
RESULT=RT
END FUNCTION

i.Write the output of the above program.
ii.What happens if we write the statement F$=E$+F$ as F$=F$+E$

23.   DECLARE FUNCTION SUM(N)
CLS
FOR I=1 TO 3
READ N
DATA 15,25,67
PRINT SUM (N)
NEXT
END

FUNCTION SUM(N)
S=0
WHILE N<>0
R=N MOD 10
S=S+R
N=INT(N/10)
WEND
SUM=S
END FUNCTION

i.What will be the output of the program?
ii.How many times the main function will be called in this program?

24.   DECLARE FUNCTION HIGHEST (M, N)
CLS
M=5
N=10
PRINT HIGHEST(M,N)
END

FUNCTION HIGHEST(T,P)
WHILE P<>0
R=T MOD P
T=P
P=R
WEND
HIGHEST =35
END FUNCITON

a)      Write down the use of MOD in the above program.
b)     What is the value the function returns in this program?



25.   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?

No comments:

Post a Comment