(X) Analytical QBASIC Program

1. Study the following program and answer the given questions:

Declare sub table(N) Input "Enter any number" , N Call table (N) END Sub table(N) For I = 1 to 10 Ans=N*I Print Ans Next I End Sub
(a) Write the name of procedure name used in above program.
Answer: table ( )
(b) Write the name of local variable used in above program.
Answer: Ans , I
(c) Name the loop used in above program.
Answer: For Next Loop
(d) Will the program run if the first line(i.e. Declare ...) is deleted ?
Answer: Yes, the program will run.
(e) List the operator used in above program with its type.
Answer: Arithmetic Operator : Multiplication (*)
Relational Operator : Equal to (=)

2. Study the following program and answer the given questions:

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 function used in the above program?
Answer:xyz ()
(b) How many times will the function be called?
Answer: Five times

3. Study the following program and answer the given questions:

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
(a) List any two library functions used in above program.
Answer: LEN, MID$, UCASE$ (Write any two)
(b) Write the use of variable "C" in line 3[i.e. C=count(R$)] given in the above program.
Answer: C is a variable used to store the value return by function module.

4. Study the following program and answer the given questions:

Declare sub SUM(N) Input "Enter 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
(a) In which condition will the statements within WHILE ... END looping statement not be executed?
Answer: When the value of N is equal to zero.
(b) Will the output be same if the place “ \ ” instead of “ / ” in the above program
Answer: No,the output won’t be same because backslash(\) is integer division and slash(/) is division.

5. Study the following program and answer the given questions:

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
(a) Write the name of the function used in above program.
Answer: Num()
(b) List out the mathematic function (Library) used in above program
Answer: int

6. Study the following program and answer the given questions:

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 a$= "Composite" ELSE a$= "Prime" END IF chk$=a$ End Function
Will the above program execute if "Declare function ..." is deleted ?
Answer: Yes, the program will run.
Why $ sign is used in the name of the above function ?
Answer: $ sign is used in function name because the value return by this function is of string type.

7. Study the following program and answer the given questions:

Declare sub check() CLS CALL check END Sub check C$= "APPLE" C=1 DO B$=MID$(C$,C,1) D$=d$+b$ C=C+1 LOOP WHILE C<=5 PRINT d$ End Sub
(a) What will be the output of the above program?
(i) ELPPA
(ii) Blank Screen
(iii) O
(iv) None of above
Answer: None of above
(b) What will be the output of the above program if the line LOOP WHILE C<=5 is replace with LOOP WHILE C>=5?
Answer: A

8. Study the following program and answer the given questions:

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.
Answer: It is used to retrieve data from data file.
(b) What happens if you remove “UCASE$” from the above program.
Answer: The address(Kathmandu) in lowercase will not display.

9. Study the following program and answer the given questions:

Open "data.txt" for output As #1 input "Enter name , class and Attendance" , n$,cl,A Write #1,n$,cl,A input "more records";y$ if y$="y" then goto top close #1 End

(a) Why the file is opened in output mode? Answer: To store data in file (b) What will happen if the label top is placed above the OPEN statement? Answer: Program will open new file with error message every time after one data is inserted , which will cause the loss of old records.

10. Study the following program and answer the given questions:

Open “Detail.dat” for input as #1 Open “Temp.dat” for output as #2 Input “Enter name of the student”; SN$ For I = 1 to 10 Input #1, Nm$, Cl, A If SN$<>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? Answer: Main objective of the above program is to delete the records of student as entered by the user. (b) Do you get any problem in the above program if “Kill” statement is removed ? Give reason. Answer: Yes, we get problem. “Detail.dat” file will not be deleted and we cannot rename the “Temp.dat”.