PRACTICE QUESTIONS: 'DEBUG'
Re-write the following programs after correcting the bugs:
Question no. 1
CLS
OPEN "Marks.dat" FOR INPUT AS #1
DO WHILE EOF(1)
INPUT #2, Name$, Subject$, Marks
IF Marks > 80 THEN
PRINT Name$
LOOP
CLOSE
END
Question no. 2
CLS
OPEN "Student.dat" FOR INPUT #1
WHILE NOT EOF(1)
INPUT ROLL, NAME$, CLASS
PRINT ROLL, NAME, CLASS
LOOP
CLOSE #1
END
Question no. 3
CLS
DISPLAY "Staff.dat" FOR APPEND AS #1
INPUT "Enter name"; NAME$
INPUT "Enter post"; POST
PRINT #1, NAME$, POST$
CLOSE 1
END
Question no. 4
DECLARE SUB SQUARE(N)
CLS
INPUT "Enter a number"; N
CALL SQUARE(N)
END
SUB SQUARE(N)
SQR = N x N
PRINT "Square is"; SQR
END
Question no. 5
DECLARE SUB FACTORIAL(N)
CLS
INPUT "Enter a number"; N
CALL FACTORIAL(A)
END
SUB FACTORIAL(N)
F = 1
FOR I = 1 TO N
F = F x n
NEXT
PRINT "Factorial is"; F
END
Question no. 6
DECLARE FUNCTION SQUARE(N)
DECLARE SUB SQUAREROOT(N)
CLS
INPUT "Enter a number"; N
PRINT "Square is"; SQUARE(N)
CALL SQUAREROOT(N)
FUNCTION SQUARE(N)
SQUARE = N * 2
END FUNCTION
SUB SQUAREROOT(N)
PRINT "Square root is"; SQUARE(N)
END SUB
Question no. 7
DECLARE SUB SI(P, R, T)
CLS
REM "Enter Principal, Rate, and Time"; P, R, T
CALL SUB SI(P, R, T)
END
SUB SI(P, R, T)
SIMPLEINTEREST = (P * R * T) ÷ 100
PRINT "Simple Interest is"; SIMPLEINTEREST
END
Questions no. 8
REMARK to display Employee Records
OPEN "Employee.dat" FOR OUTPUT AS #1
WHILE NOT EOF(1)
INPUT #1, ID, NAME$, SALARY$
PRINT ID, NAME$, SALARY
LOOP
CLOSE #1
END
Question no. 9
OPEN "Employee.dat" FOR APPEND AS #1
DO WHILE NOT EOF(1)
INPUT #1, ID, NAME$, SAL
PRINT "ID:"; ID; "Name:"; NAME$; "Salary:"; SALARY
WEND
CLOSE #2
STOP
Question no. 10
REM to write Student Marks to a File
OPEN "Marks.dat" FOR INPUT AS #1
INPUT "Enter name": NAME$
INPUT "Enter marks"; MARKS
WRITE NAME$, MARKS
CLOSE 1
END
Question no. 11
REM Calculate Factorial
DECLARE SUB FACTORIAL(N)
CLS
READ "Enter a number"; N
CALL FACTORIAL(N)
END
SUB FACTORIAL(N)
F = 1
FOR I = 1 TO N
F = F * 1
NEXT I
PRINT "Factorial is"; F
FACTORIAL=F
END
Question no. 12
REM Display Even Numbers Between 1 to 20
DECLARE SUB EVEN NUMBERS()
CLS
CALL EVEN_NUMBERS
END
SUB EVEN_NUMBERS()
FOR I = 1 TO 20
IF I MOD 0 = 2 THEN PRINT I
NEXT
END
Question no. 13
REM Calculate Cube of a Number
DECLARE FUNCTION CUBE(N)
CLS
INPUT "Enter a number"; N
R=CUBE
PRINT "Cube is"; CUBE(R)
END
FUNCTION CUBE(N)
CUBE = N * 3
END
Question no. 14
REM Calculate Area of a Circle
DECLARE FUNCTION AREA(R)
CLS
INPUT "Enter radius"; Radius
PRINT "Area of circle is"; AREA(R)
END
FUNCTION AREA(R)
ARE = 3.14 * R * 2
FUNCTION
Question no. 15
REM Calculate Square and Square Root
DECLARE FUNCTION SQUARE(N)
DECLARE SUB SQUAREROOT(N)
CLS
INPUT "Enter a number"; N
PRINT "Square is"; SQR(N)
CALL SQUAREROOT(N)
END
FUNCTION SQUARE(N)
SQR = N * 2
END FUNCTION
SUB SQUAREROOT
PRINT "Square root is"; SQR(N)
END SUB
Question no. 16:
REM Calculate Simple Interest Using Sub Procedure
DECLARE SUB SI(P, R, T)
CLS
INPUT "Enter Principal, Rate, and Time"; P, R, T
SI(P, R, T)
END
SUB SI(P, R, T)
SIMPLEINTEREST = (P * R * T) / 100
PRINT "Simple Interest is"; SI
END
No comments:
Post a Comment