Friday, October 21, 2016

SOLVED QBASIC SET S AND T


DOWNLOADED FROM SUSHILUPRETI.COM.NP 
1a) What is literal? Illustrate with example.

b) Write down the output of the following program.
CLS
a = 97
FOR i = 5 TO 1 STEP -1
c$ = CHR$(a)
d$ = CHR$(a - 32)
PRINT ASC(c$); TAB(10); c$
PRINT ASC(d$); TAB(10); d$
a = a + 2
NEXT i
END

c) Re-write the following program correcting the bugs:
            REM TO PRINT THE SMALLEST NO.
READ H
FOR X = 1 TO 5
READ N
IF N >= H THEN
H = N
NEXT U
DATA 4, 56, 343, 33, 1, 23422
END
d) Re-write the following program using DO….LOOP UNTIL as inner loop and DO WHILE…..LOOP as outer loop.
            CLS
FOR M = 1 TO 4
Z = 10
FOR N = M TO 1 STEP -1
PRINT Z;
Z = Z + 1
NEXT N
PRINT
NEXT M
END
e) Write a program that asks any number and calculates the sum of its individual digits using:
            i) FUNCTION….END FUNCTION
            ii) SUB….END SUB


Answers SET S
1a) Literal is the value, which are remained fixed during the execution of a program. Example: 15, “NEPAL” whose value remains same during the execution of a program.

b) Output
            97                    a
            65                    A
            99                    c
            67                    C
            101                  e
            69                    E
            103                  g
            71                    G
            105                  i
            73                    I
           
c) Debugged Program

REM TO PRINT THE SMALLEST NO.
READ H
FOR X = 1 TO 5
READ N
IF N > H THEN
H = N
END IF
NEXT X
PRINT H
DATA 5, 56, 343, 33, 1, 23422
END
d) program using DO….LOOP UNTIL as inner loop and DO WHILE…..LOOP as outer loop

M = 1
DO WHILE M <= 4

Z = 10
N = M
DO
PRINT Z;
Z = Z + 1
N = N - 1
LOOP UNTIL N < 1
PRINT
M = M + 1
LOOP
END
e) Program to calculate the sum of its individual digits.
USING SUB PROCEDURE
DECLARE SUB SUM (N)
CLS
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 OF DIGITS"; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUM (N)
PRINT "SUM OF DIGITS"; SU
END
FUNCTION SUM (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S + R
N = N \ 10
WEND
SUM = S : END FUNCTION

***

DOWNLOADED FROM SUSHILUPRETI.COM.NP 


1a) Write a program that to display the below output using a sub procedure.
1

121
12321
1234321
123454321

b) Write down the output of the following program.
CLS
FOR X = Q TO 4
E = R
FOR Y = 1 TO 4
E = X + Y
PRINT E;
IF E / 2 = E \ 2 THEN S = S + E
NEXT
PRINT S
R = E
NEXT
c) Re-write the following program using FOR……NEXT.
CLS
N# = 1
DO
PRINT N#;
S# = S# + N#
N#=N#+1
LOOP UNITL N#>10
PRINT S#
END

d) Re-write the following program correcting the bugs:
            REM to print current month of the system date
D = DATE
N$ = VAL(LEFT(D, 2)
FOR I = 1 TO 12
READ M$
IF I = N$ THEN PRINT "CURRENT MONTH= "; M$
END IF
NEXT I
DATA
January, February, March, April, May, June, July, August, September, October, November, December
END





e) Wap to generate the following series.
            2, 1, 3, 4, 7, 11, 18…….up to 10th terms.
f) WAP that reads the records from “MARKS.DAT” having fields name and marks in English, math and computer and display only the pass records and also count the total number of records stored in it. (Pass Mark for all the subject is 32).

Answers SET T
1a)
CLS
A# = 1
FOR I = 1 TO 5
PRINT A# ^ 2
A# = A# * 10 + 1
NEXT I
END

b) Output
            1   2   3   4    6
            2   3   4   5   12
            3   4   5   6   22
            4   5   6   7   32
            5   6   7   8   46
           

c) program using FOR……NEXT.
           
CLS
FOR N# = 1 TO 10
PRINT N#;
S# = S# + N#
NEXT N#
PRINT S#
END



d) Debugged Program
REM to print current month of the system date
D$ = DATE$
N = VAL(LEFT$(D$, 2))
FOR I = 1 TO 12
READ M$
IF I = N THEN
PRINT "CURRENT MONTH= "; M$
END IF
NEXT I
DATA January, February, March, April, May, June, July, August, September, October, November, December
END

e) Wap to generate the following series.
            2, 1, 3, 4, 7, 11, 18…….up to 10th terms.
           
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



f) WAP that reads the records from “MARKS.DAT” having fields name and marks in English, math and computer and display only the pass records and also count the total number of records stored in it. (Pass Mark for all the subject is 32).
            OPEN “MARKS.DAT” FOR INPUT AS #1
            CLS
            WHILE NOT EOF(1)
            INPUT #1, N$, A, B, C
            D=D+1
            IF A>=32 AND B>=32 AND C>=32 THEN
PRINT  N$, A, B, C
END IF
WEND
PRINT “TOTAL NUMBER OF RECORDS=”;D
END


***
 


No comments:

Post a Comment