Friday, October 21, 2016

SOLVED QBASIC SET W AND X

SOURCE : DOWNLOADED FROM SUSHILUPRETI.COM.NP


1a) What do the following declaration represent?
            N$, N#, N!, N%, N&

b) Write the output of the following program
CLS
n = 39
FOR j = 1 TO n - 1
IF n MOD j = 0 THEN
PRINT j;
END IF
NEXT j
END

c) Re-write the following program using DO……LOOP UNITL as inner loop and DO WHILE …..LOOP as outer loop.
CLS
FOR I = 10 TO 40 STEP 5
FOR J = 2 TO I - 1
IF I MOD J = 0 THEN
PRINT I
GOTO BB
END IF
NEXT J
BB:
NEXT I
END

d) Write a program that asks any two numbers and calculates the remainder when greater number is divided by smaller one using:
i) FUNCTION…..END FUNCTION
ii) SUB….END SUB
Note: Program should not contain MOD operator.

Answers
1a)
N$ = String Variable
 N# = Double Precision Variable
 N! = Single Precision Variable
 N% = Integer Variable
 N& = Long Integer variable

b) Output
            1   3   13

c) program using DO……LOOP UNITL as inner loop and DO WHILE …..LOOP as outer loop

CLS
I = 10
DO
J = 2
DO WHILE J <= I - 1
IF I MOD J = 0 THEN
PRINT I
GOTO BB
END IF
J = J + 1
LOOP
BB:
I = I + 5
LOOP WHILE I <= 40
END

d) Write a program that asks any two numbers and calculates the remainder when greater number is divided by smaller one using:
i) FUNCTION…..END FUNCTION
ii) SUB….END SUB
Note: Program should not contain MOD operator

i) FUNCTION…..END FUNCTION

DECLARE FUNCTION CALCULATE (N, D)
CLS
INPUT "ENTER ANY TWO NUMBERS"; N, D
IF D > N THEN SWAP N, D
PRINT "REMAINDER="; CALCULATE(N, D)
END

FUNCTION CALCULATE (N, D)
I = 1
P = 0
WHILE P <= N
P = D * I
I = I + 1
WEND
CALCULATE = N - (P - D)
END FUNCTION

ii) SUB….END SUB

DECLARE SUB CALCULATE (N, D)
CLS
INPUT "ENTER ANY TWO NUMBERS"; N, D
IF D > N THEN SWAP N, D
CALL CALCULATE(N, D)
END

SUB CALCULATE (N, D)
I = 1
P = 0
WHILE P <= N
P = D * I
I = I + 1
WEND
PRINT "REMAINDER="; N - (P - D)
END SUB




***


SOURCE : DOWNLOADED FROM SUSHILUPRETI.COM.NP
1a) What is symbolic constant? Illustrate with an example.

b) Write the output of the following program
CLS
FOR X = 5 TO 1 STEP -1
FOR Y = 1 TO X
PRINT Y;
NEXT Y
PRINT
NEXT X
END


c) Re-write the following program correcting the bugs:
REM To count frequency of consonants
CLS
S$ = "JACKDAWS LOVE MY BIG SPHINX OF QUARTZ"
FOR I = 1 TO LEN(S$)
A$ = MID$(S$, 1, I)
B$ = UCASE$(A$)
SELECT CASE A$
CASE "A", "E", "I", "O", "U"
T = T + 1
END SELECT
X = VAL(B$)
IF X >= 65 AND X <= 122 THEN ALPHA = ALPHA + 1
NEXT I
PRINT ALPHA - T
END



d) Re-write the following program using WHILE……..WEND.

FOR I = 10 TO 1 STEP -1
IF I / 2 = I \ 2 THEN
S = S + I ^ 2
END IF
NEXT I
PRINT S
END



e) WAP that asks the radius and height of a cylinder and calculates its volume using function procedure.

f) A sequential file “DATA.INF” has 3245 records containing the fields Name, Salary and Address and displays only those records either whose salary is above N.Rs. 15,000 or who are from “Kathmandu” and also counts the number of records stored in that file whose salary is below or equal to Nrs. 15,000.

Answers

1a) A symbolic constant is a symbol represented by a name such as a variable which stores one and one value throughout the whole program. It is declared using CONST statement.
For Example: CONST PI = 3.14

b) Output
            1   2   3   4   5
            1   2   3   4  
            1   2   3  
            1   2  
            1  
c) Debugged Program

REM To count frequency of consonants
CLS
S$ = "JACKDAWS LOVE MY BIG SPHINX OF QUARTZ"
FOR I = 1 TO LEN(S$)
A$ = MID$(S$, I, 1)
B$ = UCASE$(A$)
SELECT CASE B$
CASE "A", "E", "I", "O", "U"
T = T + 1
END SELECT
X = ASC(B$)
IF X >= 65 AND X <= 122 THEN ALPHA = ALPHA + 1
NEXT I
PRINT ALPHA - T
END


d) program using WHILE….WEND

I = 10
WHILE I >= 1
IF I / 2 = I \ 2 THEN
S = S + I ^ 2
END IF
I = I - 1
WEND
PRINT S
END



e) WAP that asks the radius and height of a cylinder and calculates its volume using function procedure.
DECLARE FUNCTION VOLUME(R, H)
CLS
INPUT “ENTER RADIUS AND HEIGHT”; R, H
PRINT “VOLUME OF A CYLINDER”; VOLUME(R, H)
END
FUNCTION VOLUME (R, H)
VOLUME = 3.14 * R^2 * H
END FUNCTION


f) A sequential file “DATA.INF” has 3245 records containing the fields Name, Salary and Address and displays only those records either whose salary is above N.Rs. 15,000 or who are from “Kathmandu” and also counts the number of records stored in that file whose salary is below or equal to Nrs. 15,000.

CLS
OPEN "DATA.INF" FOR INPUT AS #1
FOR I = 1 TO 3245
INPUT #1, N$, S, A$
IF S > 15000 OR UCASE$(A$) = "KATHMANDU" THEN PRINT N$, S, A$
IF S <= 15000 THEN C = C + 1
NEXT I
PRINT "Total number of records whose salary is below or equal to 15000"; C
CLOSE #1
END

***

No comments:

Post a Comment