Set C
1. What
is the use of immediate window in QBASIC’s editor?
2. Write
down the output of the following program:
CLS
X=7
FOR C= 1 TO 10
PRINT X;
IF X MOD 2=0 THEN
X=X/2
ELSE
S=3*X+1
END IF
NEXT C
END
3. Re-write
the following program correcting the bugs:
CLS
INPUT “ENTER A NAME”,N
PRINT LEFT$(N$,1);
FOR I = 1 TO LEN$(N$)
IF MID$(N$,1 1)=SPACE$(1) THEN
PRINT MIND$(N$,I+1,1);
NEXT N
END
4. Re-write
the following program using FOR….NEXT:
SUN#=0
COUNT%=0
DO
INPUT NUM
IF NUM<>0 THEN
SUM#=SUM#+NUM
END IF
COUNT%=COUNT%+1
LOOP UNTIL COUNT%>10
PRINT SUM#
END
5. Write
a program to generate the following series: 2, 1, 3, 4, 7, 11, 18, ….Up to 10th terms.
6. A
sequential file ABC.REC contains the name and marks secured by students in 3
different subjects. Assuming the mark for each subject is 32, write a BASIC
program to count the number of passed students.
Answers:
1. The
use of immediate window in QBASIC’s editor is that it execute statements as
soon as enter key is pressed.
2. OUTPUT
7 22 11 34 17 52 26 13 40 20
3. CLS
INPUT “ENTER A NAME”,N$
PRINT LEFT$(N$,1);
FOR I = 1 TO LEN(N$)
IF MID$(N$,I, 1)=SPACE$(1) THEN
PRINT MID$(N$,I+1,1);
END IF
NEXT I
END
4. SUM#=0
FOR COUNT%=0 TO 10
INPUT NUM
IF NUM<>0 THEN
SUM#=SUM#+NUM
END IF
NEXT COUNT%
PRINT SUM#
END
5. DECLARE
SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES
A=2
B=1
FOR I = 1 TO 5
PRINT A; B;
A=A+B
B=A+B
NEXT I
END SUB
6. OPEN
“ABC.REC” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, M1, M2, M3
IF M1>=32 AND M2>=32 AND M3>=32 THEN
C=C+1
END IF
WEND
PRINT “Total number of pass students=”; C
CLOSE #1
END
DOWNLOADED FROM SUSHILUPRETI.COM.NP
Set D
1. What
is the use and syntax of LET statement?
2. Write
the output of the following program:
CLS
ST$=”PLNMPBENPLA”
FOR I = 1 TO 5
READ N
PRINT MID$(ST$,N,1)
NEXT I
DATA 3, 7, 9, 11, 2
END
3. Re-write
the following program correcting the bugs:
Rem Find the sun of ASCII codes of
characters
st$=”COMPUTER”
C=1
S=0
DO WHILE C<=LENGTH(ST$)
AC=ASC(MID(ST,C,I)
S=S+AC
C=C+1
NEXT
PRINT “SUM:”;S
END
4. Re-write
the following program using DO-LOOP WHILE condition.
CLS
FOR X=20 TO 2 STEP -2
LET Z=X^2
PRINT Z
NEXT X
END
5. Write
a program to declare a user-defined function to reverse a given string using
FUNCTION-END FUNCTION statement. The program should input string in the main
module and reverse same using defined function.
6. Write
a program to open a data file “INFO.DAT” in output mode and store information
of employees. Data file should store information such as employees
name, post, department and salary. The program should allow user to input
records as needed.
Answer:
1. The
use of LET statement is that it assigns the value of an expression to a
variable. The syntax of LET statement is:
[LET]variable=statement
2. OUTPUT
N
E
P
A
L
3. Rem
Find the sun of ASCII codes of characters
ST$=”COMPUTER”
C=1
S=0
DO WHILE C<=LEN(ST$)
AC=ASC(MID$(ST$,C,1))
S=S+AC
C=C+1
LOOP
PRINT “SUM:”;S
END
4. CLS
X=20
DO
LET Z=X^2
PRINT Z
X=X-2
LOOP WHILE X>=2
END
5. DECLARE
FUNCTION REV$(S$)
CLS
INPUT ”Enter a string”; S$
PRINT “The reverse string=”; REV$(S$)
END
FUNCTION REV$(S$)
FOR I = LEN(S$) TO 1 STEP -1
B$=MID$(S$,I,1)
W$=W$+B$
NEXT I
REV$=W$
END FUNCTION
6. OPEN
“INFO.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter employees’ name”; N$
INPUT “Enter employees’ post”; P$
INPUT “Enter employees’ department”; D$
INPUT “Enter employees’ salary”; S
WRITE #1, N$, P$, D$, S
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END
No comments:
Post a Comment