Friday, October 21, 2016

SOLVED QBASIC SET M AND N



 DOWNLOADED FROM SUSHILUPRETI.COM.NP 

1a) Write use and syntax of the keyboard DATE$ as statement.

b) Write down the output of the following program.

CLS
I = 5
WHILE I >= 1
J = 5
WHILE J >= 1
PRINT I;
J = J - 1
WEND
PRINT
I = I - 1
WEND
END



c) Re-write the following program correcting the bugs:
           
REM COUNTING WORDS
INPUT "STRING:"; S$
FOR I% = 1 TO LENGTH(S$)
IF MID$(STRING, I%, 1) = SPACE THEN C = C + 1
NEXT I%
PRINT "NO. OF WORDS IN THE GIVEN STRING:"; C
END





d) Rewrite the following program with WHILE….WEND
CLS
A = 1
DO
B = 1
DO
PRINT A * B;
B = B + 1
LOOP UNTIL B > 3
A = A + 1
PRINT
LOOP WHILE A <= 4
END


e) Write a program to check whether the supplied string is palindrome or not using SUB…END SUB
f) WAP to create a sequential data file PASS.DAT in which the user should not be prompted to enter the records having various fields as Symbol no., Name and Percentage. Program should terminate according to user’s choice.

Answers SET M
1a) use of the keyboard DATE$  statement : It sets the current system date of the computer.
syntax of the keyboard DATE$  statement : DATE$ = stringexpression$
           
b) Output
           

            5   5   5   5   5
            4   4   4   4   4
            3   3   3   3   3
            2   2   2   2   2
            1   1   1   1   1

           
c) Debugged Program

REM COUNTING WORDS
C = 1
INPUT "STRING:"; S$
FOR I% = 1 TO LEN(S$)
IF MID$(S$, I%, 1) = SPACE$(1) THEN C = C + 1
NEXT I%
PRINT "NO. OF WORDS IN THE GIVEN STRING:"; C
END

d) program with WHILE….WEND

CLS
A = 1
WHILE A <= 4
B = 1
WHILE B <= 3
PRINT A * B;
B = B + 1
WEND
A = A + 1
PRINT
WEND
END


           


e) Write a program to check whether the supplied string is palindrome or not using SUB…END SUB
            DECLARE SUB REV (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL REV(S$)
END

SUB REV (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
IF S$ = W$ THEN
PRINT  S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
END SUB

f) WAP to create a sequential data file PASS.DAT in which the user should not be prompted to enter the records having various fields as Symbol no., Name and Percentage. Program should terminate according to user’s choice.
OPEN “PASS.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER SYMBOL NUMBER”; S
INPUT “ENTER NAME”; N$
INPUT “ENTER PERCENTAGE”; P
WRITE #1, S, N$, P
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END


***


 
DOWNLOADED FROM SUSHILUPRETI.COM.NP

1a) What is an expression? Mention its types.

b) Write down the output of the following program.
CLS
I = 1
DO UNTIL I > 3
J = 1
DO WHILE J <= 5
PRINT (I + J) * 3,
J = J + 1
LOOP
PRINT
I = I + 1
LOOP
END



c) Re-write the following program correcting the bugs:
            REM EVEN MULTIPLES OF 3 BETWEEN 30 AND 60
FOR I% = 60 TO 30 STEP -1
IF I MOD 3 <> 0 THEN
PRINT I%
NEXT I%
END

d) Rewrite the following program with FOR….NEXT
            CLS
CNT = 1: A = 1: B = 2
DO
PRINT A; "/"; B,
A = A + 1
B = B + 1: CNT = CNT + 1
LOOP UNTIL CNT > 5
END


e) Write a program that asks a number and checks whether the supplied number is Armstrong or not.
f) Write a program that reads the data from “info.dat” having fields Name and Marks in three subjects and display only the records of pass students. And also counts the total number of records stored in it.

Answers SET N
1a) An expression can be a string or numeric constant, a variable or a combination of constants, variables with operators. Its types are
i)                    Arithmetic Expression
ii)                  Logical Expression
iii)                String Expression
           
b) Output
            6          9          12        15        18
            9          12        15        18        21
            12        15        18        21        24

           
c) Debugged Program
CLS
REM EVEN MULTIPLES OF 3 BETWEEN 30 AND 60
FOR I% = 60 TO 30 STEP -1
IF I% MOD 3 = 0 THEN
PRINT I%,
END IF
NEXT I%
END


d) program with FOR….NEXT

CLS    
CNT = 1: A = 1: B = 2
FOR CNT = 1 TO 5
PRINT A; "/"; B,
A = A + 1
B = B + 1:
NEXT CNT
END

e) Write a program that asks a number and checks whether the supplied number is Armstrong or not.
            DECLARE SUB ARM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL ARM (N)
END

SUB ARM (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S  + R ^ 3
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS ARMSTRONG NUMBER"
ELSE
PRINT A; "IS NOT ARMSTRONG NUMBER"
END IF
END SUB


f) Write a program that reads the data from “info.dat” having fields Name and Marks in three subjects and display only the records of pass students. And also counts the total number of records stored in it.

            OPEN “info.dat” FOR INPUT AS #1
            CLS
            WHILE NOT EOF(1)
            INPUT #1, N$, M1, M2, M3
            C=C+1
            IF M1>=40 AND M2>=40 AND M3>=40 THEN PRINT N$, M1, M2, M3
            WEND
            PRINT “TOTAL NUMBER OF RECORDS=”; C
            CLOSE #1
            END
           


***

No comments:

Post a Comment