Friday, August 9, 2024

QBASIC PROGRAM Analytical Questions

 

QBASIC Analytical Questions

1.     Study the following program and answer the given questions.                   [2×1=2]

OPEN “hospital.txt” 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, B

IF S$< >Nm$ THEN

WRITE #2, Nm$, Cl$, A, B

END IF

NEXT I

CLOSE #1, #2

KILL “hospital.txt”

NAME “Temp.dat” AS “hospital.txt”

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.

2.     Study the following program and answer the given questions.                   [2×1=2]

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?

3. Study the given program and answer the given questions. [2]

               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.

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

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?

 

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

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.

6. Study the following program and answer the given questions.          2x1=2

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?

7. Read the following program and answer the given questions.

DECLARE FUNCTION FACT( N )

CLS
INPUT “Enter no”; N

PRINT “Factorial is”; FACT (N)

END
FUNCTION FACT (N)

F = 1

FOR X = 1 TO N

F = F * X

Next X

FACT = F

END FUNCTION

Questions:

a)     What is the name of function procedure used in the above program?

b)    What is the main objective of the above program?

8. Study the following program and answer the given questions.          2x1=2

DECLARE FUNCTION Prod(A,B)

CLS

INPUT “Enter first number”; A

INPUT “Enter second number”; B

PRINT “The product of the 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 the local variable/s used in the above program.

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

 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 the WHILE…..WEND LOOP repeats if the value of N is 123?

10. Study the following program and answer the given questions:                          [2x1=2]

 

DECLARE FUNCTION count(bs)

INPUT a$

num=count (a$)

PRINT num

END

 

FUNCTION count (b$)

FOR K=1 to LEN (bs)

aS=MIDS(b$, K, 1)

IF UCASES(a$)="D" THEN

c=c+1

END IF

NEXT K

count = c

 

END FUNCTION

 

a) What is the name of FUNCTION procedure used in above program?

 b) List out the formal and actual arguments from the

 

 11. Read the following program and answer the given questions: [2]

 

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.

12. Study the following program and answer the given questions.

 

 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?

 

13. Study the following program and answer the given questions: [2]

 

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.

 

14.       Study the following programs and answer the given questions.      [2x1=2]

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.

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

DECLARE FUNCTION TEST (A)

X = 10

Z = TEST (X)

PRINT Z

END

 FUNCTION TEST (B)

 FOR I = 1 TO B

 S = S + I * I

NEXT I

TEST= S

END FUNCTION.

 Questions:

a)    How many parameters are used in the above program?

b)   How many times does the statement S=S + I * I will be executed in the above program?

 16. Study the following program and answer the given questions: [2x1  =  2]

            DECLARE FUNCTION A (X)

            CLS

            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.                If the line S=S+I is changed to S=S+I^2, find the output of it.

b.                How many times does the statement S=S+I execute in the above program?

17. Analytical Questions

 

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.

 

18. Study the following program and answer the given questions: (2×1=2)

 

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.

19. Study  the following program  and  answer  the following questions: (2x 1=2)

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.

 

20. Read the following program and answer the given questions.

 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.

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

 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?

22. Study the following program and answer the given questions. [2×1=2]

 

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?

 

23. Study the following program and answer the given questions.            [2]

            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.

 

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

 

DECLARE SUB TEST (B$)

CLS

INPUT W$

CALL TEST(W$)

END

 

SUB TEST (B$)

FOR I=1 To LEN (B$)

PRINT RIGHT$(B$, i)

NEXT I

END SUB

 a. Write the names of two built in functions used in the above program

 b. List the real parameters of the above program

 

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

 

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.

 

26. Study the following program and answer the given questions: [2]

 

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?

b. List the library function used in the above program.

 

 

27.    Study the following program and answer the given questions:           2×1=2

DECLARE  SUB EXAMSEE (A$)

INPUT "Enter any string", B$

CALL EXAMSEE (B$)

END

 

SUB EXAMSEE(A$)

FOR I= LEN (A$) TO 1 STEP-1

PRINT LEFT$(A$,1)

NEXT I

END SUB

 

a) Write the names of two built in functions used in the program.

 

No comments:

Post a Comment