Friday, October 21, 2016

SOLVED QBASIC SET Q AND R

 DOWNLOADED FROM SUSHILUPRETI.COM.NP

1a) Write down the name of two logical operators in QBASIC.

b) Write down the output of the following program.
CLS
LET ST = 1
LET EN = 5
FOR PEACE = ST TO EN
PRINT PEACE; MID$("PEACE", PEACE, 1)
NEXT PEACE
END


c) Re-write the following program correcting the bugs:
            CLS
BROWSER = "BROWSER"
BROWSERLEN$ = LEN(BROWSER$)
FOR KOUNTER = 1 TO BROWSERLEN
PRINT MID(BROWSER$, KOUNTER, 1);
NEXT BOUNCER
END



d) Re-write the following program using WHILE….WEND.
            CLS
            FOR AA= 1 TO 5
            PRINT “---WEB BROWSERS ARE---“
            PRINT “1.   INTERNET EXPLORER”
            PRINT “2.   NETSCAPE NAVIGATOR”
            NEXT AA
            END


e) Write a program to generate following output of the string “YAHOO.COM”
            YAHOO.COM
               AHOO.COM
                  HOO.COM
                        O.COM 
                           .COM
                               OM
                                  M

f) A sequential data file “WEBSITES.DAT” contains 5000 records. Write a program to display records from 5th to 20th on the monitor.

           



Answers SET Q
1a) The name of two logical operators used in QBASIC are AND & OR.

b) Output
            1  P
            2  E
            3  A
            4  C
            5  E
           
c) Debugged Program

CLS
BROWSER$ = "BROWSER"
BROWSERLEN = LEN(BROWSER$)
FOR KOUNTER = 1 TO BROWSERLEN
PRINT MID$(BROWSER$, KOUNTER, 1);
NEXT KOUNTER
END





d) program using WHILE……WEND

CLS    
            AA=1
WHILE A<=5
            PRINT “---WEB BROWSERS ARE---“
            PRINT “1.   INTERNET EXPLORER”
            PRINT “2.   NETSCAPE NAVIGATOR”
            AA=AA+1
            WEND
END


e) Write a program to generate following output of the string “YAHOO.COM”
            YAHOO.COM
               AHOO.COM
                  HOO.COM
                        O.COM 
                           .COM
                               OM
                                  M



CLS
A$ = "YAHOO.COM"
B = 1
FOR I = LEN(A$) TO 1 STEP -1
PRINT TAB(B); RIGHT$(A$, I)
B = B + 1
NEXT I
END



f) A sequential data file “WEBSITES.DAT” contains 5000 records. Write a program to display records from 5th to 20th on the monitor.

            OPEN “WEBSITES.DAT” FOR INPUT AS#1
            CLS
            FOR I = 1 TO 5000
            LINE INPUT #1, REC$
            C=C+1
            IF C>=5 AND C<=20 THEN PRINT REC$
            NEXT I
            CLOSE#1
            END





***


 
DOWNLOADED FROM SUSHILUPRETI.COM.NP
1a) QBASIC is an interpreter. What do you mean by interpreter?

b) Write down the output of the following program.
CLS
FOR I = 1 TO 5
READ N
PRINT USING "**###.##"; N
NEXT I
DATA 766.4, 651.234, 8.569, 12373.67, 45
END

c) Re-write the following program correcting the bugs:
            REM to print even number from 32 to 12
N = 12
WHILE N >= 12
IF N MOD 2 = 0 THEN PRINT N;
N = N - 1
NEXT N
END

d) Re-write the following program using FOR….NEXT.
            CLS
A = 10
WHILE A >= 2
B = 1
DO
LET C = A + B
PRINT C
B = B + 2
LOOP WHILE B <= 9
A = A - 2
WEND
END

e) Write a program convert time in second into equivalent minutes and hour. If you input 3941, the output should be: [using a sub procedure]
1 hour
5 minutes
41 seconds

f) Write a program that allows us to store Name, Department, Post and Salary of an employee into a data file STAFF.DAT. The program should prompt to user for adding next records.
           



Answers SET S
1a) An interpreter is a language processor or language translator that translates high level language to machine language one statement at a time.

b) Output
            **766.40
            **651.23
            ****8.57
            12373.67
            ***45.00
           
c) Debugged Program

REM to print even number from 32 to 12
N = 32
WHILE N >= 12
IF N MOD 2 = 0 THEN PRINT N;
N = N - 1
WEND
END




d) program using FOR…NEXT

CLS
FOR A = 10 TO 2 STEP -2
B = 1
DO
LET C = A + B
PRINT C
B = B + 2
LOOP WHILE B <= 9
NEXT A
END


e) Write a program convert time in second into equivalent minutes and hour. If you input 3941, the output should be: [using a sub procedure]
1 hour
5 minutes
41 seconds

            DECLARE SUB CONVERT (S)
CLS
INPUT "ENTER TIME IN SECONDS"; S
CALL CONVERT(S)
END

SUB CONVERT (S)
H = S \ 3600
M = S MOD 3600
MIN = M \ 60
SEC = M MOD 60
PRINT H; "hour"
PRINT MIN; "minutes"
PRINT SEC; "seconds"
END SUB


f) Write a program that allows us to store Name, Department, Post and Salary of an employee into a data file STAFF.DAT. The program should prompt to user for adding next records.
            OPEN “STAFF.DAT” FOR OUTPUT AS #1
            DO
            CLS
            INPUT  “ENTER NAME”; N$
            INPUT  “ENTER DEPARTMENT”; D$
            INPUT ”ENTER POST”; P$
            INPUT ”ENTER SALARY”; S
            WRITE #1, N$, D$, P$, S
            INPUT “DO YOU WANT TO CONTINUE(Y/N)”;CH$
            LOOP WHILE UCASE$(CH$)=”Y”
            END







***

No comments:

Post a Comment