Wednesday, September 27, 2017

Analytical Questions Qbasic Programs [SEE Qbasic Practice PART II]

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

2.      DECLARE FUNCTION PALIN(NUM)
CLS
INPUT "ENTER ANY NUMBER";NUM
P=PALIN((NUM))
IF P=NUM THEN
PRINT NUM;"IS PALINDROME"
ELSE
PRINT NUM;"IS NOT PALINDROME"
END IF
END

FUNCTION PALIN(NUM)
S=0
WHILE N>0
R=N MOD 10
S=S*10+R
N=INT(N/10)
WEND
PALIN=S
END FUNCTION

a. What is the name of the function used in the above program?
b. List out the mathematical function used in the above program.
c. How the argument is passed either by reference or by value?
d. List out the numeric variables used in program.
e. Write the output of the program if the value of NUM is 543.

3.      DECLARE FUNCTION TEST(A)
FOR I=1 TO 10
READ X
TE=TEST(X)
SUM=SUM+TE
NEXT
DATA 10,20,5,40,3
DATA 20,11,9,8,16
END

FUNCTION TEST(A)
R=A MOD2
IF R =1 THEN
TEST = R^2
END IF
END FUNCTION

i. What is the name of the function used in the above program?
ii.What is the purpose of the above program?

4.      DECLARE FUNCTION count (S$)
CLS
INPUT"ENTER ANY STRING:";S$
PRINT "Number of words="; count (S$)
END

FUNCTION count (S$)
C=1
FOR I=1 TO LEN (S$)
A$= MID$(S$, I, 1)
IF A$="  " THEN C=C+1
NEXT I
count = C
END FUNCTION

a)      What is the name and type of function in above program?
b)     What will be the output if value of S$="I am a robot"?
c)      How many time loops will execute if value of s$="Sunder Nepal".

5.      DECLEAR 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

i.What is the name of the function used in the program?
ii.How many times will the function be called?

6.      DECLARE SUB CHECK(N$)
N$=”MID-NORTH MUTUAL BOARD
CALL CHECK(N$)
END

SUB CHECK (N$)
B=LEN (N$)
COUNT=2
WHILE COUNT<=B
X$= X$+MID$(N$, COUNT, 1)
COUNT=COUNT+2
WEND
PRINT X$
END FUNCTION

i.What is the name of sub procedure in above program?
ii.List out the numeric and string variables used in the above program.

7.      DECLARE FUNCTION REV(A$,B$)
A$=”NEPAL”
B$=”HONGKONG”
PRINT REV(A$,B$)
END

FUNCTION REV(A$,B$)
A=LEN(A$)
B=LEN(B$)
IF A>B THEN REV=25 ELSE REV=25
END FUNCTION

a) List the string constants used in the program.
b) What will be the value of A here?
c) Write the output of this program.
d) How is parameter passed here: by reference or by value?

8.      DECLARE  SUB Palindrome (B)
CLS
A=3352
B=323
Call Palindrome(A): Call Palindrome (B)
END

Sub Palindrome (B)
While b>0
C=c*10+b mod 10
B=b\10
Wend
If C=B then
Print"the number ",B,;"is not palindrome"
End if
END SUB

i.Write the output of the above program.
ii.List out the numeric variables used in the program.
iii.List out the numerical and logical expression used in the program.
iv.Why do we use call palindrome (B) statement?
v.How the argument is passed either by reference or value?

9.      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

i.What will be the output of the program if the user enters 200 as the first number and 100 as the second number.
ii.Will the program run if the first line (i.e. DECLARE…..) is deleted?

10.   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.

a)      List all the numeric variables used in the above program.
b)     List the local variables used in the above program.

11.   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 above program:
b)     Name the loop in above program?

12.   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

i.Will the above program execute if “DECLARE FUNCTION….” Is deleted
ii.Why $ sign is used in the name of the above function.

13.   DECLARE SUB exam(a$)
CLS
a$="EDUCATION"
CALL exam(a$)
END

SUB exam(a$)
FOR i = 1 to LEN(A$)
b$= MID$(a$,i,1)
IF INSTR("AEIOU",b$) then
c$=UCASE$(b$)+c$
ELSE
c$=LCASE$(b$)+c$
END IF
END SUB

i. List out the different built - in function used in the program.
ii. Will the output be same if first line of the program is deleted?

14.   DECLARE SUB exam(a$)
CLS
a$ = "EDUCATION"
CALL exam(a$)
END

SUB exam(a$)
FOR i=1 to len(a$)
b$ = MID$(a$,i,1)
IF INSTR("AEIOU",b$) then
c$ = UCASE$(b$) + c$
ELSE
c$ = LCASE$(b$) + c$
ENDIF
NEXT i
END SUB

i.List out the different built-in function used in the program.
ii.Will the output be same if first line of the program is deleted?

15.   DECLARE FUNCTION NUM (N)
INPUT”ENTER A NUMBER”; N
S= NUM (N)
PRINT S
END

SUB NUM (N)
X=INT(17/N)
Y= 15 MOD N
NUM= X+Y
END FUNCTION

i.Write down the output of the above program if n=50.
ii.List out the mathematical function (library) used in the above program also mention their task.




16.   DECLARE FUNCTION SHAPE$(TXT$)
CLS
INPUT ”Enter a string”; T$
RV$=SHAPE$(T$)
PRINT “The text in reverse order is”; RV$
END

FUNCTION SHAPE$(TXT$)
FOR I = LEN(TXT$) TO 1 STEP -1
CH$=MID$(TXT$,I,1)
R$=R$+CH$
NEXT I
SHAPE$=R$
END FUNCTION

i.Write the library functions used in the above program.
ii.Write the use of expression SHAPE$=R$ written at the end of the function procedure.

17.   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.

18.   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

i.List the string Library functions used in the above program.
ii.Write down the missing statements in the main module to execute the program.

19.   REM “to count vowels”
DECLARE FUNCTION count(A$)
INPUT “ Enter a word”; A$
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

i.List the string  library function used in  above program.
ii.Write down the missing statement.

20.   DECLARE FUNCTION SHAPE$ (TXT$)
INPUT “Enter a Word”; USRSTR$
RVS$ = SHAPE$ (USRSTR$)
PRINT “The text in reverse order is”; RVS$
END

FUNCTION SHAPE$ (TXT$)
FOR I = LEN (TXT$) TO 1 STEP -1
CH$ = MID$ (TEXT$, I, 1)
RVS$ = RVS$ + CH$
NEXT   I
SHAPE$ = RVS$
END FUNCTION

i.Write the library functions used in the above program.
  ii.Write the use of expression SHAPE$ = RVS$ written at the end of function procedure.

21.   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
i.List the library function used in the above program.
ii.List the conditional statement used in the above program.

22.   DECLARE SUB GAUROS (S$)
CALL GAUROS$ (“NEPAL YELLOWPAGES”)
END
SUB GAUROS(S$)
L = LEN(S$)
FOR I = 1 TO L
C$ = UCASE$ (MID$ (S$, I, 1))
IF C$ = “E” THEN R = R + 1
NEXT I
PRINT “Total no is”; R
END SUB
i.If the lines if C$ = “E” is relaced by IF C$ = “C” , what will be the output?
ii.List out the numeric and string variables in above program?
23.   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
i.List any two variables used in the above program.
ii.How many times SUB-procedure will be called when program is executed?
24.   DECLARE SUB ARM( M)
CLS
INPUT "Enter a number";N
CALL ARM(N)
END
SUB ARM(R)
LET S = R
WHILE R<>0
X=R MOD 10
Y=Y+X^3
R=INT(R/10)
WEND
IF Y=S THEN
PRINT "ARMSTRONG"
ELSE
PRINT "NOT"
ENDIF
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 happen if first line will be deleted from the program?

25.   DECLARE FUNCTION ALTRE$(M$)
A$=”NATIONAL”
PRINT ALTRE$(A$)
PRINT ALTRE$9(“NEPAL”)
END

FUNCTION ALTRE$(A$)
B=LEN (A$)
FOR K = 1 TO B STEP 3
C$= LEFT$(A$, K)
NEXT K
ALTRE$=C$
END FUNCTION

i.List the numeric variables used in SUB MODULE.
ii.Are the values returned by the function same each time?

No comments:

Post a Comment