Friday, October 21, 2016

SOLVED QBASIC SET Y AND Z


SOURCE : DOWNLOADED FROM SUSHILUPRETI.COM.NP

1a) What is an intrinsic function? Give any two examples.

b) Write the output of the following program
CLS
S$ = "COMPUTER"
L = LEN(S$)
C = 1
WHILE L > 0
T$ = LEFT$(S$, L)
IF L / 2 = L \ 2 THEN
PRINT C; T$
C = C + 1
END IF
L = L - 1
WEND
END

c) Re-write the following program correcting the bugs:
REM TO DISPLAY THE REVERSE OF DATA
CLS
FOR A = 1 TO 5
READ A$
REV$ = ""
FOR X = LEN(A$) TO 1 STEP -1
RV$ = RV$ + MID$(W$, X, 1)
NEXT X, A
PRINT A$
DATA ABC, XYZ, MNO, PQR, STU
END


d) Re-write the following program using FOR……NEXT as inner loop and IF …..THEN…..GOTO as outer loop.
CLS
FOR M = 1 TO 4
Z = 10
N = 1
DO
PRINT Z;
Z = Z + 1
N = N + 1
LOOP UNTIL N > M
PRINT
NEXT M
END



e) WAP that asks any three numbers and display the middle one using SUB…END SUB.

f) Write a program that prompts the user to supply Employee’s name, Salary and Gender and stores it into FEMALE.DAT if the gender is “FEMALE”. The user can supply 10 records after each execution of this program.

Answers

1a) Intrinsic functions are built - in or ready – made functions provided by the QBASIC software. Any two examples are : SQR( ) and INT ( ).

b) Output
            1  COMPUTER
            2  COMPUT
            3  COM
            4  CO

c) Debugged Program

REM TO DISPLAY THE REVERSE OF DATA
CLS
FOR A = 1 TO 5
READ A$
RV$ = ""
FOR X = LEN(A$) TO 1 STEP -1
RV$ = RV$ + MID$(A$, X, 1)
NEXT X
PRINT RV$
NEXT A
DATA ABC, XYZ, MNO, PQR, STU
END


d) program using FOR……NEXT as inner loop and IF …..THEN…..GOTO as outer loop

M = 1
TOP:
Z = 10
FOR N = 1 TO M
PRINT Z;
Z = Z + 1
NEXT N
PRINT
M = M + 1
IF M <= 4 THEN GOTO TOP
END



e) WAP that asks any three numbers and display the middle one using SUB…END SUB.
DECLARE SUB MIDDLE (A, B, C)
CLS
INPUT "ENTER ANY THREE NUMBERS"; A, B, C
CALL MIDDLE (A, B, C)
END

SUB MIDDLE (A, B, C)
IF A>B AND A<C OR A<B AND A>C THEN
M=A
ELSEIF B>A AND B<C OR B<A AND B>C THEN
M=B
ELSE
M=C
END IF
PRINT “THE MIDDLE NUMBER =”; M
END SUB

f) Write a program that prompts the user to supply Employee’s name, Salary and Gender and stores it into FEMALE.DAT if the gender is “FEMALE”. The user can supply 10 records after each execution of this program.
CLS
OPEN "FEMALE.DAT" FOR OUTPUT AS #1
FOR I = 1 TO 10
CLS
INPUT "ENTER EMPLOYEE’S NAME:"; N$
INPUT "ENTER SALARY:"; S
INPUT "ENTER GENDER:"; G$
IF UCASE$(G$)=”FEMALE” THEN WRITE#1, N$, S, G$
NEXT I
CLOSE #1
END
***


SOURCE : DOWNLOADED FROM SUSHILUPRETI.COM.NP

1a) Write down the syntax and use of SELECT – CASE statement.

b) Write the output of the following program
CLS
s$ = "THIS IS MY BOOK"
FOR i = 1 TO LEN(s$)
b$ = MID$(s$, i, 1)
IF i = 1 THEN a$ = a$ + UCASE$(b$)
             IF i >= 2 THEN
                IF ASC(b$) = 32 THEN
                        a$ = a$ + b$
                        a$ = a$ + UCASE$(MID$(s$, i + 1, 1))
                        i = i + 1
                ELSE
                        a$ = a$ + LCASE$(b$)
                END IF
             END IF
NEXT i
PRINT a$
END

c) Re-write the following program correcting the bugs:
REM to calculate hex equivalent of a decimal no.
INPUT "DECIMAL NO.:"; D
DO WHILE NOT D = 0
R = D / 16
IF R < 10 THEN
R = R + 55
A$ = STR$(R) + A$
ELSE
A$ = CHR$(R) + A$
END IF
D = D \ 16
WEND
PRINT "HEXADECIMAL EQUIVALENT:"; A$

d) Re-write the following program using DO….LOOP
DIM A(5)
FOR I = 1 TO 5
READ A(I)
DATA 54, 24, 31, 13, 71, 99
S = S + A(I)
NEXT I
AV = S / 5
PRINT S, AV
END


e) WAP that uses a function procedure to find whether the supplied number is perfect square or not.

f) Write a program that prompts the user to supply Symbol no., Name and Percentage of any number of students and sends the records of only those students securing distinctions (Percentage from 80 onwards) into a sequential data file DIST.DAT. The program should also display how many records were entered by the user and how many were stored.

Answers

1a) Syntax of SELECT CASE statement
SELECT CASE textexpression
CASE expressionlist1
                        [statement block-1]
[CASE expressionlist2
                        [statementblock-2]]….
[CASE ELSE
                        [statementblock-n]]
END SELECT

Use of SELECT CASE statement
-          Executes one of several statement blocks depending on the value of an expression.

b) Output
            This Is My Book

c) Debugged Program

REM to calculate hex equivalent of a decimal no.
INPUT "DECIMAL NO.:"; D
DO WHILE D < > 0
R = D MOD 16
IF R < 10 THEN
A$ = STR$(R) + A$
ELSE
A$ = CHR$(R + 55) + A$
END IF
D = D \ 16
LOOP
PRINT "HEXADECIMAL EQUIVALENT:"; A$
END

d) Program using DO……LOOP

DIM A(5)
I = 1
DO
READ A(I)
DATA 54, 24, 31, 13, 71, 99
S = S + A(I)
I = I + 1
LOOP WHILE I <= 5
AV = S / 5
PRINT S, AV
END

e) WAP that uses a function procedure to find whether the supplied number is perfect square or not.
DECLARE FUNCTION CHECK (N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = CHECK(N)

IF SQR(N) = INT(A) THEN
PRINT N; "IS PERFECT SQUARE"
ELSE
PRINT N; "IS NOT PERFECT SQUARE"
END IF
END
FUNCTION CHECK (N)
CHECK = SQR(N)
END FUNCTION

f) Write a program that prompts the user to supply Symbol no., Name and Percentage of any number of students and sends the records of only those students securing distinctions (Percentage from 80 onwards) into a sequential data file DIST.DAT. The program should also display how many records were entered by the user and how many were stored.
CLS
OPEN "D:\SUS\DISTINCT.DAT" FOR OUTPUT AS #1
DO
CLS
INPUT "ENTER SYMBOL NUMBER:"; S
INPUT "ENTER NAME:"; N$
INPUT "ENTER PERCENTAGE:"; P
IF P >= 80 THEN
WRITE #1, S, N$, P
RC = RC + 1
END IF
NRC = NRC + 1
INPUT "CONTINUE(Y/N)"; CH$
LOOP WHILE UCASE$(CH$) = "Y"
CLOSE #1
PRINT "TOTAL NUMBER OF RECORDS ENTERED BY THE USER"; NRC
PRINT "TOTAL NUMBER OF RECORDS ENTERED INTO THE DATA FILE="; RC
END
***

1 comment:

  1. Where is solved objectives of Sanjiwani Publication???sir if you have time then please do this for SEE students...

    ReplyDelete