IMPORTANT QUESTIONS
1.Write a QBASIC program using sub procedure to reverse the given string.
Ans.
DECLARE SUB REV(N$)
INPUT”ENTER A STRING”;N$
CALL REV(N$)
END
SUB REV(N$)
FOR I =LEN(N$) TO 1 STEP-1
K$= MID$(N$,I,1)
R$= R$+ K$
NEXT I
PRINT “THE REVERSED STRING IS “; R$
END SUB
2.Write a QBASIC program using sub procedure to reverse the given number.
Ans.
DECLARE SUB REV(N)
INPUT”ENTER A NUMBER”;N
CALL REV(N)
END
SUB REV(N)
P=N
WHILE N<>0
R= N MOD 10
S= S*10 + R
N = N\10
WEND
PRINT”THE REVERSED NUMBER IS:”;S
END SUB
3.Write a QBASIC program using Function ... End Function to find the area of parallelogram. [Hint: A= (B*H)]
Ans.
DECLARE FUNCTION AREA(B,H)
INPUT”ENTER BASE AND HEIGHT”;B,H
PRINT”THE AREA OF PARALEELOGRAM IS”;AREA(B,H)
END
FUNCTION AREA(B,H)
A= B*H
AREA=A
END FUNCTION
4.Write a QBASIC program using Function ... End Function to find the HCF of two numbers.
Ans.
DECLARE FUNCTION HCF(A,B)
INPUT”ENTER TWO NUMBERS”;A,B
IF A>B THEN SWAP A,B
PRINT”THE HCF OF TWO NUMBERS IS”;HCF(A,B)
END
FUNCTION HCF(A,B)
FOR I = 1 TO A
IF A MOD I= 0 AND B MOD I=0 THEN
H=I
END IF
NEXT I
HCF=H
END FUNCTION
5.A sequential data file called “staff.dat” contains some records under fields name, post and salary of employees. Write a program to display records whose salary is between 15000 to 600000.
Ans.
OPEN “staff.dat” FOR INPUT AS#1
CLS
WHILE NOT EOF(1)
INPUT#1, N$, P$, S
IF S<=150000 AND S>= 600000
PRINT N$,P$,S
END IF
WEND
CLOSE #1
END
6.WAP to create a sequential file named “staff.dat” and store records under the fields name, post and salary. The program should terminate when user desires.
Ans.
OPEN “staff.dat” FOR OUTPUT AS #1
DO
INPUT”ENTER NAME”;N$
INPUT”ENTER POST”;P$
INPUT”ENTER SALARY”;S
WRITE #1,N$, P$,S
INPUT”DO YOU WANT TO CONTINUE?(Y/N)?”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END
7.WAP to store the details of 5 students in the file “student.rec” containing the fields name, percentage and section.
Ans.
OPEN “staff.dat” FOR OUTPUT AS #1
FOR I= 1 TO 5
INPUT”ENTER NAME”;N$
INPUT”ENTER POST”;P$
INPUT”ENTER SALARY”;S
WRITE #1,N$, P$,S
NEXT I
CLOSE #1
END
8.WAP to count the total number of records from the sequential file“staff.dat” containing some records under fields name, post and salary of employees.
Ans.
OPEN “staff.dat” FOR INPUT AS#1
CLS
WHILE NOT EOF(1)
INPUT#1, N$, P$, S
C=C+1
WEND
PRINT”THE TOTAL RECORDS IS”;C
CLOSE #1
END
9.Analyze the given program and answer the questions:
DECLARE FUNCTION factorial(N)
INPUT "Enter any number : " ; N
Print "The Factorial is "; factorial(N)
End
FUNCTION factorial(N)
D = 1
FOR I= 1 TO N
D = D * I
NEXT I
factorial = D
End Function
(a) Which loop is used in above program?
Ans. FOR… NEXT loop
(b) Write the name of procedure used in above program.
Ans. factorial
10. Analyze the given program and answer the questions:
DECLARE SUB res(a$)
CLS
A$="CANDLELIGHTS"
CALL res(a$)
END
SUB res(a$) L=LEN(a$)
FOR x= L to 1 STEP -2
PRINT MID$(a$, x, 1);
NEXT x
END SUB
a. Does the program execute if DECLARE SUB… is removed?
Ans. Yes, it runs.
b. What will be the output if we change STEP -2 into STEP-3 ?
Ans. SGEN
11.Read the following program and answer the following questions.
DECLARE FUNCTION COUNT(A$)
Input “Enter a word”; W$
END
FUNCTION COUNT(A$)
B=LEN(A$)
C$=UCASE$(A$)
FOR I=1 TO B
E$=MID$(C$,I,1)
IF E$=”A” OR E$=”E” OR E$=”I” OR E$=”O” OR E$=”U” THEN C=C+1
END IF
NEXT I
COUNT=C
END FUNCTION
a) List the string Library functions used in the above program.
Ans. MID$, LEN, UCASE$
b) Write down the missing statements in the main module to execute the program.
Ans. Print COUNT(A$)
12.Study the following program and answer the given questions.
DECLARE SUB RESULT ( )
CLS
CALL RESULT
END
SUB RESULT ( )
W$=”SCIENCE”
L=LEN (W$)
X=1; Y=3
FOR I=1 TO L STEP 2
PRINT TAB (Y); MID$(W$,X,L)
X=X+1
L=L-2
Y=Y+1
NEXT I
END SUB
a.) Name the user defined function used in the above program.
Ans. RESULT
b.) How many times does the loop execute?
Ans. 7 times
13.Find the output of given program:
DECLARE SUB RESULT ( )
CLS
CALL RESULT
END
SUB RESULT ( )
W$=”ROSEBUD”
L=LEN (W$)
X=1; Y=3
FOR I=1 TO L STEP 2
PRINT TAB (Y); MID$(W$,X,L)
X=X+1
L=L-2
Y=Y+1
NEXT I
END SUB
Ans.
ROSEBUD
OSEBU
SEB
E
DECLARE SUB PATTERN ( )
CALL PATTERN
END
SUB PATTERN
A=1
FOR I = 1 TO 10
PRINT A
A=A+2
NEXT I
END SUB
Ans.
1 3 5 7 9 11 13 15 17 19
32. Re-write the given program after correcting the bugs.
REM Sub program to find average of three numbers
DECLARE
SUB AVG (A,B,C)
INPUT
“ENTER ANY THREE NUMBERS” , A,B,C
CALL
SUB AVG(A,B,C)
END
SUB
AVG(A,B,C)
A= (A+B+C)/3
DISPLAY
“AVERAGE OF THREE NUMBERS IS” ; B
SUB END
Program after correction:
REM Sub program to find average of three numbers
DECLARE SUB AVG (A,B,C)
INPUT “ENTER ANY THREE NUMBERS” , A,B,C
CALL AVG(A,B,C)
END
SUB AVG(A,B,C)
S= (A+B+C)/3
PRINT “AVERAGE OF THREE NUMBERS IS” ; S
END SUB
33. Study the following program and answer the given questions.
DECLARE SUB FACT (N)
INPUT “ENTER ANY NUMBER”, N
CALL FACT (N)
END
SUB FACT(N)
F= 1
FOR I = 1 TO 10
F
= F * I
PRINT
F
NEXT I
END SUB
a. Write the sub procedure name used in above program.
Ans. FACT
b.Will the program run, if Declare Sub ... is removed from above program?
Ans. Yes, it runs.
34. Write a SUB program to check whether the supplied number is even or odd.
DECLARE SUB CHECK(N)
INPUT "ENTER A NUMBER ";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N MOD 2 = 0 THEN
PRINT "IT IS EVEN"
ELSE
PRINT "IT IS ODD"
END IF
END SUB
35. Write a program to check whether the given number is positive, negative or zero using Sub… end sub.
DECLARE SUB CHECK(N)
INPUT "ENTER A NUMBER ";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N > 0 THEN
PRINT "IT IS POSITIVE"
ELSEIF N<0 THEN
PRINT "IT IS NEGATIVE"
ELSE
PRINT “IT IS ZERO”
END IF
END SUB
36. WAP to find simple interest using SUB…. END SUB
DECLARE SUB INTEREST( P, T , R )
INPUT “ENTER PRINCIPAL, TIME AND RATE ”; P, T , R
CALL INTEREST( P, T , R )
END
SUB INTEREST( P, T , R )
I = ( P* T * R )/ 100
PRINT “THE SIMPLE INTEREST IS :”;I
END SUB
37. WAP using sub to display the multiplication table of a given number.
DECLARE SUB MUL(N)
INPUT”ENTER A NUMBER”;N
CALL MUL(N)
END
SUB MUL(N)
FOR I = 1 TO 10
PRINT N; “X” ; I; “=”;N*I
NEXT IEND SUB
38. WAP TO PRINT THE POSSIBLE FACTORS OF GIVEN NUMBER USING SUB END SUB.
DECLARE SUB FACTOR(N)
INPUT “ENTER A NUMBER”;N
CALL FACTOR(N)
END
SUB FACTOR(N)
PRINT” THE FACTORS OF”;N; “ARE”
FOR I = 1 TO N
IF N MOD I =0 THEN PRINT I
NEXT I
END SUB
39. WAP to find the factorial of a given number using Sub End Sub.
DECLARE SUB FACT (N)
INPUT”ENTER A NUMBER”;N
CALL FACT (N)
END
SUB FACT (N)
F=1
FOR I = 1 TO N
F = F* I
NEXT I
PRINT “THE FACTORIAL OF”;N; “IS”; F
END SUB
40. WAP to check whether the multidigit number is palindrome or not using SUB.. END… SUB.
DECLARE SUB REV(N)
INPUT”ENTER A MULTIDIGIT NUMBER”;N
CALL REV(N)
END
SUB REV(N)
P=N
WHILE N<>0
R= N MOD 10
S=S*10+R
N=N\10
WEND
IF P= S THEN
PRINT “IT IS PALINDROME”
ELSE
PRINT “IT IS NOT PALINDROME”
END IF
END SUB
41. WAP to check whether the multidigit number is Armstrong or not using SUB.. END… SUB.
DECLARE SUB ARM(N)
INPUT”ENTER A MULTIDIGIT NUMBER”;N
CALL ARM(N)
END
SUB ARM(N)
P=N
WHILE N<>0
R= N MOD 10
S=S+ R^3
N=N\10
WEND
IF P= S THEN
PRINT “IT IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
END SUB
No comments:
Post a Comment