Monday, January 15, 2024

3.2.4. QBASIC Modular Programming Analytical Questions Solutions - SEE COMPUTER SCIENCE 2080

3.2.4. QBASIC Modular Programming  Analytical Questions Solutions - SEE COMPUTER SCIENCE 2080




 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?

The main objective of the program given above is to delete the record according to the entered name.

b.     Do you get any problem in the above program if “Kill” statement is removed? Give reason.

Yes, the program will display the error message and it won’t delete the record.

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.

The use of statement “INPUT #1, N$, A$, S” in the above program to read data from the data file EMP.DAT.

b.     What happens if you remove “UCASE$” from the above program?

If UCASE$ is removed then if Kathmandu is in small letters then it won’t be displayed on the screen.

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.

Formal parameter= A$                 Actual parameter = T$

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

The library function used in the above program is LEN( ) and MID$( ).

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.

Ans: variables used in above programs are: A$, P, N$, AN$.

b)      What is the name of data file used in above program?

Ans: INFO.DAT 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?

The name of the sub procedure is PC$( )

b.     List the local variable.

The local variable are N, I, R, C

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?

Ans: The parameters used in the above program is one.

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

The statement S=S+I will execute 100 times 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?

The name of function procedure used in the above program is FACT ( ).

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

The main objective of the above program is to display the factorial of a given number.

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.

Ans: The numerical variables used in the program are A, B and P

b) List the local variable/s used in the above program.

The local variable/s used in the program are A, B and P.

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.

The int() function returns the numeric integer equivalent from a given expression.

b)     How many times the WHILE…..WEND LOOP repeats if the value of N is 123?

The WHILE…..WEND LOOP repeats 3 times 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?

The name of FUNCTION procedure used in above program is count( ).

 

b) List out the formal and actual arguments from the

Formal parameter – b$, Actual parameter – a$

 

 

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?

Ans: The value of L in the above program is 8.

 

b) List the numeric and string variable in the above program.

Ans: Numeric variable = L, A

String Variable = X$,

 

 

 

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

Ans: The argument used in the above program is W$ and parameter is N$.

 

b) What is the use of SHARED in above program?

Ans: The SHARED keyword in QBASIC is used to declare global variables in sub module

 

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?

Ans: The main objective of above program is to reverse the string.

 

b) List all the parameters used in above program.

Ans: The parameters used in above program are X$ and N$

 

 

 

 

 

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?

Ans: The output would be 11  13   24.

b)      Write actual and formal parameters used in the program.

Ans: Actual parameters- x,y,z

        Formal parameters-a,b,c

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?

Ans. 1 parameter is used in the above program.

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

Ans. The statement S= S + I * I will be executed 10 times.

 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.

Ans:The output will be 55.

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

Ans: The statement S=S+I executes 5 times.

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?

The main objective of the program given above is to increase marks of math by 10 whose marks in math is less than 20.

b)     Do you get any problem in above program if “Kill” statement is removed? Give reason.

Yes, there will be a problem in the above program if the "KILL" statement is removed. If the "KILL" statement is removed, the program will not be able to delete the existing "MARKINFO.TXT" file.

 

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.

Ans: Two library functions used in above program are UCASE$( ) and MID$( )

 

b) Write the use of variable "C" in line 3 [i.e. C=COUNT(RS)] given in the above program.

Ans: The use of variable "C" in line 3 [i.e. C=COUNT(RS)] is to store the value returned by

COUNT(RS) function.

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?

Ans: The name of function used in above program is NUM ( ).

 

ii. List the mathematical function used in above program.

Ans: The mathematical function used in above program is INT ( ).

 

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.

Ans: The parameter used in above program is N$ and argument used in above program is W$.

b) List all the string library functions from the program.

Ans: The string library functions used from the program are LEN ( ), RIGHT$( ), LEFT$( ).

 

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.

Ans: The use of MOD in the program  is to determine the remainder of a division operation.

 

b) How many time the loop executes in the above program?

Ans: The loop executes 10 times 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.

Ans: Formal parameters are  A and B

            Arguments are X and Y

 

b. Which loop is used in the above program?

Ans: FOR……NEXT 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?

Ans: CALL TEST(A$) statement should be added in the main module to execute the program.

 

b)     List out the variables used in the above program with types.

Ans: the variables used in the above program are:

A$ - String Variable

L, I – Numeric Variable

 

 

 

 

 

 

 

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

Ans: The names of two built in functions used in the above program are LEN ( ) and RIGHT$ ( )

 

b. List the real parameters of the above program

Ans: The real parameters of the above program is W$

 

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?

Ans: Variable P remained uncalled in the main module because P is declared as global variable and its value can be accessed by MATHS$ ( ) function without passing the value.

 

b) Find the output if the user supplies P=9 and c=4 running the program.

Ans: The output of the program if the user supplies P=9 and c=4 running the program is:

False

 

 

 

 

 

 

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?

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$( ).

 

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.

Ans: The two built in functions used in the program are: LEN( ) and LEFT$( )

b) List the real parameter and formal parameter in the program.

Ans: The real parameter is B$ and formal parameter is A$

 

1 comment: