Friday, October 21, 2016

SOLVED QBASIC SET I AND J



 DOWNLOADED FROM SUSHILUPRETI.COM.NP 


1a) Convert the following algebraic expression into QBASIC expression.




         







b) Study the following program and answer the following questions:
             DECLARE SUB TEST (A, B)
CLS
X = 1: Y = 3
CALL TEST(X, Y)
PRINT X, Y
END

SUB TEST (P, Q)
FOR I = P TO Q
P = P + Q
Q = Q + P
NEXT I

END SUB


Questions:
i)                    What is the output of the above program?
ii)                  If CALL TEST(X,Y) is modified as CALL TEST(X,(Y)), then what will be the output?
iii)                If the value of X and Y are exchanged then the program will give the same output? Why?
iv)                Will the program give the same output if CALL TEST(X,Y) is written below PRINT X,Y?
c) Write down the output of the following program.
CLS
FOR I = 2 TO 10 STEP 2
FOR J = I TO 10 STEP 2
PRINT J;
NEXT J
PRINT
NEXT I
END


d) Re-write the following program correcting the bugs:
            CLS
REM TO PRINT ODD NUMBER FROM 32 TO 12
N = 12
WHILE N <= 32
IF N MOD 2 IS 0 THEN PRINT N;
N = N - 1
NEXT N
END



e) Write a program to declare a user defined function to convert temperature in Centigrade into Fahrenheit using FUNCTION…END FUNCTION statement. The program should input temperature in centigrade and call the defined function to convert the temperature into Fahrenheit.
f) WAP to display all the records from an existing sequential data file EPS.DAT having unknown no. of records and fields in tabular form.




Answers SET I
1a)
i)                   
= (a^2+b^2)^3 / (a-b^3)^4

ii)               
= ((a+b)^2 / a-b^2)^(1/3)

b) Questions:
i)                    What is the output of the above program?
Output:
            29                    47
ii)                  If CALL TEST(X,Y) is modified as CALL TEST(X,(Y)), then what will be the output?
Output:
            29                    3
iii)                If the value of X and Y are exchanged then the program will give the same output? Why?
No, the output will not be same. The output will be as follows:
Output:
            3                      1
iv)                Will the program give the same output if CALL TEST(X,Y) is written below PRINT X,Y?
No, the output will not be same. The output will be as follows:
Output:
            1                      3
c) Output:
            2   4   6   8   10
            4   6   8   10
            6   8   10
            8   10
            10

d) Debugged Program
            CLS
REM TO PRINT ODD NUMBER FROM 32 TO 12
N = 31
WHILE N >= 12
IF N MOD 2 = 1 THEN PRINT N;
N = N - 1
WEND
END

e) Write a program to declare a user defined function to convert temperature in Centigrade into Fahrenheit using FUNCTION…END FUNCTION statement. The program should input temperature in centigrade and call the defined function to convert the temperature into Fahrenheit.

DECLARE FUNCTION CONVERT (C)
CLS
INPUT “ENTER TEMPERATURE IN CELCIUS”; C
PRINT “TEMPERATURE IN FARENHEIT=”; CONVERT (C)
END

FUNCTION CONVERT (C)
F = (9 / 5) * C + 32
CONVERT = F
END FUNCTION

f) WAP to display all the records from an existing sequential data file EPS.DAT having unknown no. of records and fields in tabular form.

            OPEN “EPS.DAT” FOR INPUT AS #1
            CLS
            WHILE NOT EOF(1)
            LINE INPUT REC$
            PRINT REC$
            WEND
            CLOSE#1
            END





***

 DOWNLOADED FROM SUSHILUPRETI.COM.NP


1a) Write down the syntax of READ….DATA statement.

b) Write down the output of the following program.
CLS
DIM A(10)
S = 0
FOR I = 1 TO 10
READ A(I)
NEXT I
FOR J = 10 TO 1 STEP -1
IF A(J) MOD 10 <> 0 THEN
PRINT A(J);
S = S + A(J)
END IF
NEXT J
PRINT
PRINT S
DATA 5, 10, 15, 20, 25, 30, 35, 40, 45, 50
END


c) Study the following program and answer the following questions:
            CLS
N = 10
FOR X = 10 TO 1 STEP -2
PRINT N + X;
N = N - 1
S = S + X
NEXT X
PRINT "SUM OF THE NUMBERS: "; S
END

Questions:
i)                    Write the output of the above program.
ii)                  Re-Write the above program using DO WHILE…LOOP.
iii)                Which is the counter in the program?
iv)                Which is the accumulator in the program?
v)                  How many variables are used in the program?


Answers SET J
1a) The syntax of READ….DATA statement
             DATA constant[,constant]……
READ variable list
b) Output
            45   35   25   15   5
            125

c) Questions:
i)                    Write the output of the above program.
Output :
            20   17   14   11   8 SUM OF THE NUMBERS:  30

ii)                  Re-Write the above program using DO WHILE…LOOP.
The program using DO WHILE…LOOP
CLS
N = 10
X = 10
DO WHILE X >= 1

PRINT N + X;
N = N - 1
S = S + X
X = X - 2
LOOP
PRINT "SUM OF THE NUMBERS: "; S
END

iii)                Which is the counter in the program?
The counter in the program is X.

iv)                Which is the accumulator in the program?
The accumulator in the program is S.

v)                  How many variables are used in the program?
There are three variables used in the program. They are N, X and S.






***

No comments:

Post a Comment