Wednesday, September 27, 2017

Analytical Questions Qbasic Programs [SEE Qbasic Practice PART I]

1.      DECLARE SUB TEST(A, B, C)
LET X=4
LET Y=7
LET Z=12
CALL TEST (X, Y, Z)
PRINT X, Y, Z
END

SUB TEST(A, B, C)
A=A+3
B=B+2
SUM=A+B+C/3
PRINT SUM
END SUB

i)What happens if CALL TEST(X, Y, Z) is replaced by CALL TEST(A, B, C)
ii)List the formal and real parameters used in the above program.

2.      DECLARE SUB word(B$)
CLS
A$ = “Computer science”
B$ = “Computer Programming”
Call word(a$)
Print A$
Call word (B$)
End

SUB WORD (c$)
L = LEN(C$)
POS = (80 – L)/2
Print tab (pos); C$
C$ = “examination”
END SUB
                                                                                                                                                                                                                                                                                                                  
i)Write the output of the above program.
ii)How is the arguments passed?
iii)What will the print A$ statement in module print?
iv)Is C$ actual or formal parameter?

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

i.Write actual and formal parameter used in the program.
ii.What would be its output if x=1, y=2,z=3?


4.      DECLARE SUB SEQUENCE (A,B,C)
CLS
X=10
Y=20
Z=30
CALL SEQUENCE (X,Y,Z)
END

SUB SEQUENCE (C,B,A)
PRINT A,B,C
END SUB

i.List the formal parameters and actual parameters used in the above program.
ii.Will the above program execute if the position of parameter is to be changed? If ‘yes’ then which sequence of number list will it print either 10,20,30 or 30,20,10?

5.      DECLARE SUB ADD(A,B)
CLS
INPUT “ENTER TWO NUMBERS”; X,Y
CALL ADD(X,Y)
END

SUB ADD(A,B)
C = A + B
PRINT “Sum is”; C
END SUB

i.Write the name of procedure in above program.
ii.List arguments and parameters in the above program.

6.      DECLARE SUB TEST (A, B, C)
LET X = 4
LET Y = 7
LET Z = 12
CALL TEST (X, Y, Z)
PRINT X, Y, Z
END

SUB TEST (A, B, C)
A=A+3
B=B+2
SUM=A+B+C/3
PRINT SUM
END SUB

i.What will be the output of the above program?
ii.List the arguments and parameters used in the above program.

7.      DECLARE SUB TEST (A, B, C)
INPUT "Enter three different numbers:"; X, Y, Z
CALL TEST(X, Y, Z)
END

SUB TEST (A, B, C)
IF A > B AND A > C THEN
T = A + B + C
ELSEIF B > A AND B > C THEN
T = A * B * C
ELSE
T = (B + A) / C
END IF
PRINT T
END SUB

i.List formal and real parameters used in the above program. 
ii.What happens if “CALL TEST(X,Y,Z)” is replace by “CALL TEST(A,B,C)”.

8.      DECLARE FUNCTION ADD(N)
CLS
FOR  CNT= 1 TO 3
READ  NUM
PRINT ADD (NUM)
NEXT CNT
DATA  8, 7, 3
END

FUNCTION ADD(N)
S=0
FOR G=1 TO N
S=S+G
NEXT G
ADD=S
END FUNCTION

i.Name the actual and formal parameter used in above program.
ii.What is the value of NUM when the value of CNT is 2?

9.      DECLARE SUB RESULT (N)
CLS
INPUT "ENTER ANY NUMBER"; NUM
CALL RESULT (NUM)
END

SUB RESULT (N)
DO UNTIL N = 0
R = N MOD 10
IF R MOD 2 = 0 THEN
S = S + R
END IF
N = N \ 10
LOOP
PRINT S
END SUB

i.List the actual and formal parameters in the above program.
ii. What will be the output of the program if the input is 1234?

10.   DECLARE SUB TEST (W$)
CLS
INPUT ”ENTER AWORD”; A$
CALL TEST (A$)
END

SUB TEST (W$)
FOR K=1 TO LEN (W$)
U$=MID$(W$,K,1)+U$
NEXT K
PRINT U$
END SUB

i.List the argument and parameters used in the above program.
List the library function used in the above program.

11.   DECLARE  SUB EXAM (N$)
CLS
INPUT "Enter Word", WO$
CALL EXAM (WO$)
END

SUB EXAM(N$)
FOR I=1 TO LEN (N$)
PRINT RIGHT $(N$,1)
NEXT I
END SUB

i.Write the names of two built in functions used in the program.
ii.List the real name and formal parameter in the program.

12.   DECLARE SUB RESULT (TXT$)
TEXT$ = "SYSTEM PROGRAMMING"
CALL RESULT (TEXT$)
END

SUB RESULT (TXT$)
FOR I = 1 TO LEN(TXT$)
SCAN$ = UCASE$(MID$(TXT$, I, 1))
IF I MOD 2 = 0 THEN
TEMP$ = TEMP$ + UCASE$(SCAN$)
ELSE
TEMP$ = TEMP$ + LCASE$(SCAN$)
END IF
NEXT I
PRINT TEMP$
END SUB
i.What is the output of the above program?
ii.List the actual and the formal parameters sued in the program.

13.   DECALRE SUB ADD(A,B)
CLS
X= 4
Y= 3
CALL ADD(X,Y)
END

SUB ADD(A,B)
Z = A +B
PRINT A;”+”;B;’”=”;Z
END SUB

i.List the local and global variables.
ii.What  is the name of procedure used in above program?
14.   DECLARE FUNCTION XYZ(N)
CLS
A = 135 : B = A
A = XYZ(A)
PRINT “THE RESULT IS”,
IF X = B THEN PRINT “OK” ELSE PRINT “NO”
END

FUNCTION XYZ(N)
DO WHILE N > 0
RE = N MOD 10
N = N / 10
T = N * 10 + RE
LOOP
XYZ = T
END FUNCTION

a)      What will be the output of the above program?
b)     Count the total number of global and local variables in the above program and list them.
c)      Can we replace the fourth line of the program X = XYZ(A) by X = XYZ(131) or not? Differentiate between X = XYZ(A) and XYZ(131)
d)     If the value of variable N = 7 the what will be the value of variable RE?

15.   DECLARE FUNCTION PRO (A,B)
CLS
INPUT “Enter two number “:A,B
RES= PRO (A,B)
PRINT “PRODUCT =”: RES
END

FUNCTION PRO (A,B)
P=A*B
PRO = P
END FUNCTION

i) Write the local variables and global variables used in the program.
ii) Writ the name of the function used in the program.

16.   DECLARE FUNCTION Prod(A,B)
CLS
INPUT “Enter first number:”;A
INPUT “Enter second number:”;B
PRINT “the product of two number=”;Prod(A,B)
END

FUNCTION Prod(A,B)
P=A*B
Prod=P
END FUNCTION

i.List all the numerical variables used in the program.
ii.List all the local variables used in the program.

17.   DECLARE FUNCTION DESP$(A$,B$,C$)
INPUT A$,B$,C$
PRINT DISP$( A$,B$,C$)
END

FUNCTION DESP$(A$, B$, C$)
L1=LEN(A$)
L2=LEN(B$)
L3=LEN(C$)
IF L1>L2 AND L1>L3 THEN
ANS$=A$
ELSEIF L2>L3 AND L2>L1 THEN
ANS$=B$
ELSE
ANS$=C$
END IF
DISP$=ANS$
END FUNCTION

i.Make a list of local variables in the given program.
ii.What is the function of PRINT DISP$(A$,B$,C$)?


18.   DECLARE FUNCTION COUNT (N ())
DIM N(10)
FOR I = 1 TO 10
READ N(I)
NEXT
DATA 12,34,56,11,13,45,33,90,99,78,87
A= COUNT (N ())
END

FUNCTION COUNT (N ())
FOR J = 1 TO 10
IF N (I) MOD 2= 0 THEN
E=E+1
ELSE
O=O+1
NEXTPRINT O, E
END FUNCTION

i.What may be the output of the above program?
ii.List out global and local variables used in the program.
iii.List out expression used in the program.
iv. How the argument is passed either by reference or by value?
19.   DECLARE FUNCTION NUM(N)
CLS
N=14
PRINT NUM(N)
END

FUNCTION NUM(N)
WHILE N<>0
R=N MOD 2
S=S+R*10^P
P=P+1
N=N\2
WEND
NUM=S
END FUNCTION

i.List the local variable used in the function procedure.
ii.What will be the output if the program?

20.   DECLARE SUB TEST(A,B)
CLS
X=2: Y=2
CALL TEXT(X,Y)
PRINT X,Y
END

SUB TEST(P,Q)
FOR I= P TO Q
P=P+Q
Q=P+Q
NEXT
PRINT P,Q
END SUB

i.What will be the output of the above program?
ii.List down the global variable used in the above program.

21.   DECLARE SUB CONVERT(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL CONVERT(N)
END

SUB CONVERT(N)
A=2
WHILE A<>0
R = N MOD A
A = A \ B
B$ = STR$(R) +B$
WEND
PRINT R
END SUB

i.List out the number of local variable used in SUB procedure.
ii.What will be the output of above program if N=12

22.   DECLARE SUB SERIES(A, B)
DECLARE FUNCTION SUM(P,Q)
COMMON SHARED N
INPUT “Enter First Term”;X
INPUT “Enter Second Term”;Y
INPUT “Enter Number of Terms to be generated”; N
CALL SERIES(X, Y)
END

SUB SERIES (A, B)
FOR I = 1 TO N
PRINT A
A=SUM(A,B)
NEXT I
END SUB
FUNCTION SUM (P,Q)
SUM=P+Q
END FUNCTION

i.What will the output if X=10, Y=8 and Z=5.
ii.List out the local variables and global variable in the above program.

23.   DECLARE SUB SERIES(X, Y, Z)
DECLARE FUNCTION SUM(X, Y)
DIM SHARED I
CLS
INPUT “Enter First Term”;X
INPUT “Common Difference”;Y
INPUT “Enter Number of Terms to be generated”; Z
CALL SERIES(X, Y, Z)
END

SUB SERIES (X, Y, Z)
FOR I = 1 TO Z
PRINT X
X = SUM(X, Y)
NEXT I
END SUB

FUNCTION SUM (X, Y)
SUM=X+Y
END FUNCTION
a)      What will be the output of the program if the user inputs 2, 3, 4 for the variables X, Y, Z respectively?
b)     How many times the function SUM(X, Y) will be executed if the values of X, Y, Z are 2, 4, 6 respectively?
c)      What type of variables X, Y and I are?
d)     Will the program run if the value of Z is less than X and Y?

24.   DECLARE SUB CHECK()
CLS
CALL CHECK()
END

SUB CHECK
A=1
FOR I= 1 TO 5
PRINT A
A=A+3
NEXT I
END SUB

i.Write the name of the procedure used in the above program.
ii.What will happen if CALL statement is missing.


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


i.Write the name of the function used in the above program.
ii.List out the mathematical function (Library function) used in the above program.

Tuesday, September 26, 2017

Debug the Qbasic Programs [SEE Qbasic Practice PART V]

1.      REM program to copy Data from exam.dat to test.dat
OPEN"exam.dat" FOR OUTPUT AS #1
INPUT AS #2
DO UNTIL EOF(#2)
INPUT #2, N$,A$,A
WRITE #2,N$,A$,A
LOOP
CLOSE #1, #2
END

2.      REM TO READ RECORDS FROM DATA FILE
OPEN STUD.DAT FOR OUTPUT AS #1
WHILE NOT EOF(2)
LINE INPUT #2, REC$
PRINT REC$
LOOP
CLOSE #3
END

3.      REM to read data from the data file and display them
OPEN “TEST.TXT” FOR OUTPUT AS #10
WHILE NOT EOF(1)
LINE INPUT R$
PRINT R$
WEND
CLOSE ALL

4.      REM to read data from a sequential data file
OPEN STUDENT.DAT FOR INPUT #1
DO WHILE EOF (2)
INPUT NAME$, ADD$, TELNO$, AGE
IF AGE IS GREATER THAN 15 THEN
PRINT NAMES$, ADD$, TELNO$, AGE
LOOP
CLOSE #1
END

5.      REM to DISPLAY ALL THE RECORDS FROM DATA FILE ABC.DAT
OPEN”ABC.DAT” FOR OUTPUT #1
DO WHILE EOF (“ABC.DAT”)
INPUT N$, A
PRINT N$, A
CLOSE #1
END

6.      REM to display all records from the sequential data file.
CLS
OPEN "REC.DAT" FOR OUTPUT AS #1
WHILE NOT EOF()
INPUT A$,B$,C
PRINT  A$,B$,C
LOOP
CLOSE #1
END

7.      OPEN info.dat FOR OUTPUT AS #2
CLS
PRINT “NAME”, “POST”, “DEPT”, “SALARY”
WHILE NOT EOF (1)
INPUT 1, N$, P$, D$, S
PRINT N$, P, D$, S$
LOOP
KILL #2
END

8.      OPEN “MAAF.DOC” FOR OUTPUT AS #10
CLS
DO WHILE NOT EOF(MAAF.DOC)
INPUT #1, N$,R,M1,M2,M3
PRINT #1,N$,R,M1,M2,M3
LOOP
CLOSE#10
END

9.      REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INP AS #1
PRINT “ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”
DO WHILE NOT EOF
INPUT #1,RN,N$,AD$,CL,S$
PRINT RN,N$,AD$,CL,S$
NEXT
CLOSE #1
END

10.   Rem to display the contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
            INPUT #1, Name$, Age, Add$
            DISPLAY Name$, Age, Add$
WEND
CLOSE 1
END


11.   REM add data to existing data file
DIM n, p, c AS STRING
OPEN “file.txt” FOR OUTPUT AS 1
DO
INPUT “Enter name, post”; n, p
WRITE n, p
INPUT “Press y/Y to add more”; c
LOOP WHILE c = “Y” or c = “y”
CLOSE 1
END


12.   REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR INPUT AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T$
ADD #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS
LOOP WHILE UCASE(ANS$) = Y
CLOSE
END

13.   REM Program to store data in a sequential data file.
CLS
DO
OPEN “Address.txt” FOR INPUT AS #1
INPUT “Name”; N$
INPUT “Address”; A$
INPUT “Age”; A
Input “Phone”; P$
WRITE N$,A$,A,P$
INPUT “Do you want some more….”; ans$
LOOP WHILE UCASE(ans$)=”Y”
CLOSE #1
END

14.   REM To add more records in the existing data file which contains some records
OPEN “ABC.TXT” FOR INPUT AS #2
DO
INPUT “ENTER NAME”; N$
INPUT ”ENTER POST”; P$
INPUT “ENTER SALARY”; S
ADD #2, N$, P$, S
INPUT ”Want to add more records (Y/N)”; YN$
LOOP WHILE UCASE(YN$)=Y
CLOSE
END

15.   Rem to overwrite existing data in a sequential file with new data
OPEN “MYFILE.DAT” FOR INPUT AS #1
DO
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “TEL NO.”; T$
INPUT #1, N$, A$, T$
PRINT “CONTINUE”; C$
LOOP WHILE C$(UCASE$)=”Y”
CLOSE #1
END

16.   REM To store Name, post and salary
OPEN EMP.DOC” FOR OUT AS #1
INPUT” Enter name”;N
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #2, N$,P$, S
CLOSE #1
END

17.   REM to  add records in a sequential data file.
OPEN “STUDENT.DAT” FOR INPUT #1
DO
INPUT “Enter name, class and roll no.”; N$, C, R]
PRINT #1, N$, C, R$
INPUT “Do you have more records(y/n)”; y$
UNTIL LCASE$(Y)= “n”
END

18.   REM store records
CLS
OPEN "peaks.xls" FOR INPUT AS #75
DO
INPUT "Enter peak"; P$
INPUT "Enter district";D
INPUT "Height"; H
WRITE P$,D$,H
INPUT "Do U 1 2 add more";mor$
LOOP WHILE UCASE$(mor$)="y"

19.   REM To add records in an existing file
CLS
OPEN "record.dat" FOR OUTPUT AS #1
aa:
INPUT"Name, class&roll"; n$, c, r
INPUT #2, n$, c, r
INPUT "more records"; y$
IF y$="y" THEN GOTO aa
CLOSE "record.dat"
END

20.   REM to add records in “marks.dat” sequential data file
OPEN “A”, 2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE#1, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
TERMINATE
END