Friday, October 21, 2016

SOLVED QBASIC SET E AND F


 
DOWNLOADED FROM SUSHILUPRETI.COM.NP

Set E
1.      Define counter with example.
2.      Read the following program and answer the following questions:
DECLARE SUB take(x,y)
CLS
FOR I= 1 TO 5
READ c, d
CALL take(c,d)
NEXT I
DATA 13, 15, 16, 12, 31, 12, 16, 17, 21, 22
END

SUB take(a,b)
STATIC s
IF a>b THEN
s=s+a
ELSE
s=s+b
END IF
PRINT s
END SUB
a.      What is the output of the above program?
b.      If the statement STATIC s is removed, then what will be the change in its output?
c.       If the statement PRINT s is places in main module just below the statement CALL take(a,b), then what will be the output?
d.      List out the formal arguments and actual arguments from the above program.
3.      Write down the output of the following program:
CLS
FOR I = 1 TO 5
READ A$,A
PRINT MID$(A$,A,1)
NEXT I
DATA COMPUTER, 4, ORACLE, 1, WINDOW, 6
DATA KEYBOARD, 2, FORTRAN, 5
END
4.      Re-write the following program correcting the bugs:
REM to find product of the even numbers from 10 to supplied nos.
P=0
FOR C=1 TO TEN
INPUT N
IF N MOD 2>0 THEN
P=P*N
END IF
NEXT
DISPLAY P
END
5.      Write a program to find the greatest number among the 10 numbers given by the users.
6.      A sequential data file “STUDENT.DAT” has fields name, roll and address. Write a program to display those records.
Answers:
1.      Counter is a variable that counts the iterations of a loop. Example: I=1 to 10, I is a counter variable.

2.      a. OUTPUT
15
31
62
79
101

b. OUTPUT
15
16
31
17
22

c. OUTPUT
0
0
0
0
0

d. The formal arguments are: a and b and actual arguments are: c and d

3.      OUTPUT
P
O
W
E
R

4.      REM to find product of the even numbers from 10 to supplied nos.
P=1
FOR C=1 TO 10
INPUT N
IF N MOD 2=0 THEN
P=P*N
END IF
NEXT
PRINT P
END

5.      DECLARE SUB GREAT (N)
CLS
INPUT “Enter first number”; N
CALL GREAT(N)
END

SUB GREAT(N)
FOR I = 2 TO 10
INPUT “Enter next number”; G
IF G>N THEN N=G
NEXT I
PRINT “The greatest number is”; N
END SUB

6.      OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, R, A$
PRINT N$, R, A$
WEND
CLOSE #1
END



 DOWNLOADED FROM SUSHILUPRETI.COM.NP 

1a) What command is used to do following tasks in QBASIC?
            i) To list files from current directory.
            ii) To create a directory
b) Write down the output of the following program.
CLS
C = 1
FOR I = 2 TO 8 STEP 2
PRINT C;
SWAP B, C
C = B + 1
NEXT I
END


c) Re-write the following program correcting the bugs:
            REM To find the sum of square upto ten natural nos.
CLS
X = 1
DO WHILE X >= 10
A = X2
S = S + A
LOOP
PRINT "Sum of Square:"; SUM
END


d) Re-write the following program using WHILE……..WEND.
            CLS
FOR I = 1 TO 5
FOR J = 1 TO I
PRINT J;
NEXT J
PRINT
NEXT I
END



e) Write a program to declare a user defined function to check whether the supplied string is palindrome or not using FUNCTION….END FUNCTION statement. The program should input string and uses the above function to check whether it is palindrome or not.

f) WAP to open a data file “LIBRARY.DAT” in output mode and store information of books. Data file should store information such as book title, author price, date of purchase and publisher. The program should allow user to input records as needed


Answers SET F
1a)       i) To list files from current directory.
            Ans: FILES
            ii) To create a directory
ANs: MKDIR
b) Output:
            1   2   3   4
c) Debugged Program
           

            REM To find the sum of square upto ten natural nos.
CLS
X = 1
DO WHILE X <= 10
A = X ^ 2
S = S + A
X = X + 1
LOOP
PRINT "Sum of Square:"; S
END

d) program using WHILE….WEND
            CLS
I = 1
WHILE I <= 5
J = 1
WHILE J <= I
PRINT J;
J = J + 1
WEND
PRINT
I = I + 1
WEND
END



e) Write a program to declare a user defined function to check whether the supplied string is palindrome or not using FUNCTION….END FUNCTION statement. The program should input string and uses the above function to check whether it is palindrome or not.
           
DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
C$ = REV$(S$)
IF S$ = C$ THEN
PRINT  S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
END

FUNCTION REV$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
REV$ = W$
END FUNCTION




f) WAP to open a data file “LIBRARY.DAT” in output mode and store information of books. Data file should store information such as book title, author price, date of purchase and publisher. The program should allow user to input records as needed

OPEN “LIBRARY.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER  BOOK TITLE”; B$
INPUT “ENTER PRICE”; P
INPUT “ENTER DATE OF PURCHASE”; D$
INPUT “ENTER NAME OF PUBLISHER”; P$
WRITE #1, B$, P, D$, P$
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END




***

No comments:

Post a Comment