Re-write the following program with correcting bugs.
(It carries 2 Marks) A=A+B B=A+B
B=A+B NEXT ctr
1) Specification Grid 2065 Answer: NEXT ctr END SUB
REM to store name and age in REM to store name and age in a sequential END series()
a sequential data file data file [Link]
[Link]
OPEN "[Link]" FOR OUTPUT AS #1
OPEN [Link] FOR OUT 3) SEE Grade Promotion Debugged Program:
AS #1 INPUT "Enter name";n$ Exam 2078
REM to display records from an existing
INPUT "Enter name";n INPUT "Enter age";a REM to display records from file.
an existing file.
INPUT "Enter age";a WRITE #1, n$,a CLS
CLS
WRITE 1, n$,a CLOSE #1 OPEN "[Link]" FOR INPUT AS #1
OPEN "[Link]" FOR
CLOSE #1 END WHILE NOT EOF(1)
APPEND AS #1
END WHILE NOT EOF(#1) INPUT #1, en$, post$, salary
WRITE #1, en$, post$, salary PRINT en$, post$, salary
2) SEE 2078 Debugged program: PRINT en$, post$, salary WEND
DECLARE SUB series() DECLARE SUB series() CLOSE #1 CLOSE #1
CLS CLS END END
EXECUTE series CALL series
END END
4) Debugged program
SUB series SUB series REM to create a new data REM to create a new data file
file
REM program to generate REM program to generate CLS
1 1 2 3 5 ….up to the 1 1 2 3 5 ….up to the 20th term. CLS
20th term. OPEN "[Link]" FOR OUTPUT AS #1
A=1 OPEN "[Link]" FOR
A=1 INPUT AS #1 DO
B=1
B=1 DO INPUT "Enter Name, Roll No and Total. ";
FOR ctr 10 TO 1 STEP -1 N$,R,T
FOR ctr 10 TO 1 INPUT "Enter Name, Roll No
PRINT A;B; WRITE #1, N$, R,T
and Total. "; N$,R,T
DISPLAY A: B:
A=A+B INPUT "Supply more records Y/N"; C$
INPUT #1, N$, R,T
INPUT "Supply more records LOOP WHILE UCASE$(C$)="Y" INPUT “Enter address”;a$ INPUT “Enter salary”;s
Y/N"; CS
CLOSE #1 INPUT “Enter salary”;s$ WRITE #2, n$,a$,s
LOOP WHILE
UCASE$(Y$)="Y" END WRITE #1, n$,a$,s INPUT “Do you want to add more
records”;m$
CLOSE #1 INPUT “Do you want to add
more records”;m$ LOOP WHILE UCASE$(m$)= “Y”
END
LOOP WHILE UCASE(m$)= END
5) Debugged program: “Y”
REM to store record in data REM to store record in data file END
file
CLS OPEN "[Link]" FOR OUTPUT AS
CLS #1
7) Debugged program
OPEN "[Link]" FOR INPUT DO
AS #1 DECLARE FUNCTION DECLARE FUNCTION FACTO (N)
INPUT “Enter Name, Address and Class FACTO (N$)
DO ”;N$,A$,C REM to find factorial of a input number
REM to find factorial of a
INPUT “Enter Name, Address WRITE #1,N$,A$,C input number CLS
and Class ”;N$,A,C INPUT "Enter a number" ; X
INPUT "Do you want to continue " ; Y$ CLS
INPUT #1,N$,A,C PRINT “The factorial is “; FACTO(x)
LOOP WHILE UCASE$(Y$)= "Y" INPUT "Enter a number" ; X
INPUT "Do you want to END
continue " ; Y$ CLOSE #1 PRINT “The factorial is “;
FACTO(N) FUNCTION FACTO(N)
WHILE UCASE$(Y$)= "Y" END
END F=1
CLOSE "[Link]"
FUNCTION FACTO(N) WHILE N <>0
END
F=1 F=F*N
WHILE N=0 N=N-1
6) Pabson Pre-board exam Debugged Program
F=F*N WEND
2078
REM to add more data in sequential data
N=N-1 FACTO=f
REM to add more data in file.
sequential data file. WEND
OPEN “[Link]” FOR APPEND AS #2 END FUNCTION
OPEN “[Link]” FOR INPUT F=FACTO
AS #2 DO
END FUNCTION
DO INPUT “Enter name”;n$
INPUT “Enter name”;n$ INPUT “Enter address”;a$
8) Debugged program
REM program to store name, REM program to store name, post and salary 10) SLC 2065 Answer:
post and salary in data file for in data file for few employees.
few employees. DECLARE SUB series() DECLARE SUB series()
OPEN “[Link]” FOR OUTPUT As #1
OPEN “[Link]” FOR CLS CLS
APPEND As #1 top:
EXECUTIVE series CALL series
top: INPUT “Enter name”;name$
END END
INPUT “Enter name”;name INPUT “Enter post”;post$
SUB series SUB series
INPUT “Enter post”;post$ INPUT “Enter salary”;sal
a=2 a=2
INPUT “Enter salary”;sal WRITE #1, name$,post$,sal
b=2 b=2
WRITE #2, name$,post$,sal INPUT “Do you want to more records”;ch$
FOR ctr = 1 TO 5 FOR ctr = 1 TO 5
INPUT “Do you want to more IF UCASE$(ch$)=”Y” THEN GOTO top
DISPLAY a;b; PRINT a;b;
records”;ch$ CLOSE #1
a=a+b a=a+b
IF UCASE$(ch$)=”Y” THEN END
GOTO top b=a+b b=a+b
ENDIF LOOP ctr NEXT ctr
CLOSE #1 END series() END SUB
END
9) Specification Grid 2065 Answer: 11) SLC supplementary 2065 Answer:
REM to store name and age in REM to store name and age in a sequential DECLARE FUNCTION DECLARE FUNCTION sum(a,b)
a sequential data file data file [Link] sum(a,b)
[Link] REM program to sum given two numbers
OPEN "[Link]" FOR OUTPUT AS #1 REM program to sum given
OPEN [Link] FOR OUT two numbers INPUT "enter first number";x
AS #1 INPUT "Enter name";n$
INPUT "enter first number;x INPUT "Enter second number";y
INPUT "Enter name";n INPUT "Enter age";a
INPUT "Enter second PRINT sum(x,y)
INPUT "Enter age";a WRITE #1, n$,a number";y END
WRITE 1, n$,a CLOSE #1 PRINT sum(a,b) FUNCTION sum(a,b)
CLOSE #1 END END sum=a+b
END FUNCTION sum(a,b) END FUNCTION
sum=a+b CLOSE #1
END END
12) SLC 2066 Answer:
DECLARE SUB fibonic( ) DECLARE SUB fibonic( ) 14) SLC 2067 Answer:
REM *fibonic series* REM *fibonic series* REM to display all the records REM to display all the records from the
from the sequential data file sequential data file [Link]
CALL SUB fibonic CALL fibonic [Link]
OPEN "[Link]"
END END OPEN "[Link]" FOR FOR INPUT AS #1
SUB fibonic SUB fibonic OUTPUT AS #1 DO WHILE
NOT EOF ("[Link]" DO WHILE NOT EOF (1)
a=1 a=1 INPUT #1, n$,a
INPUT #1, n$,a
b=1 b=1 PRINT n$,a
PRINT n$,a
FOR x= 1 TO 10 FOR x= 1 TO 10 LOOP
CLOSE 1
DISPLAY a; PRINT a; CLOSE #1
END
a=a+b a=a+b END
b=a+b b=a+b
END fibonic NEXT x
15) Answer:
END SUB
DECLARE FUNCTION DECLARE FUNCTION vowel(a$)
vowel(a$)
CLS
13) SLC supplementary Answer: CLEAR
INPUT "Enter String:";a$
2066 INPUT "Enter String:";a$
REM to store name, post and salary vo=vowel(a$)
REM to store name, post and vo=vowel(a$)
salary OPEN "[Link]" FOR OUTPUT AS PRINT "Total numbers of "A"
#1 PRINT "Total numbers of "A" characters=";vo
OPEN [Link] FOR OUT characters=";vo
AS #1 INPUT "Enter name";n$ END
INPUT "Enter post";p$ END
INPUT "Enter name";n FUNCTION vowel(a$)
INPUT "Enter salary";s FUNCTION vowel(a$)
INPUT "Enter post";p$ FOR x= 1 to LEN(a$)
WRITE #1, n$,p$,s FOR x= 1 to LEN(a$)
INPUT "Enter salary";s m$=MID$(a$,x,1)
CLOSE #1 m$=MID(a$,x,1)
WRITE 1, n$,p$,s m$=UCASE$(m$)
END m$=UPPERCASE$(m$)
SELECT CASE m$ SELECT CASE m$ REM program to find the INPUT n
square root of given program.
CASE "A" CASE "A" CALL square (N)
DECLARE SUB square(N)
v=v+1 v=v+1 END
ENTER n
END SELECT END SELECT SUB square(N)
DISPLAY square (N)
NEXT x NEXT x S=n^ 0.5
END
v=vowel Vowel=v PRINT s
SUB square(N)
END FUNCTION END FUNCTION END SUB
S=m ^ 0.5
PRINT s
16) SLC 2064 Answer:
FINISH
DECLARE SUB series( ) DECLARE SUB series( )
18) Answer:
CLS CLS
REM program to display all CLS
EXECUTE series CALL series the pass students records on
the screen from the sequential REM program to display all the pass
END END students records on the screen from the
data file "[Link]"
SUB series () SUB series () sequential data file "[Link]"
OPEN "[Link]" FOR
REM program to generate 3 3 REM program to generate 3 3 6 9 15 ….up OUTPUT as #5 OPEN "[Link]" FOR INPUT AS #5
6 9 15 ….up to 20th terms to 20th terms PRINT "Name","Class","Result"
PRINT
A=3 A=3 "Name","Class","Result" DO WHILE EOF(5)
B=3 B=3 DO WHILE EOF(5) INPUT #5, n$, c, r$
FOR CTR = 10 TO 1 FOR CTR = 10 TO 1 STEP -1 OR FOR INPUT n$, c, r$ IF r$="pass" THEN PRINT #5,n$,c,r$
CTR=1 TO 10
DISPLAY A; B; IF r$="pass" THEN PRINT LOOP
PRINT A; B; n$,c,r$
A=A+B CLOSE #5
A=A+B WEND
B=A+B END
B=A+B CLOSE #5
NEXT ctr
NEXT ctr END
END series( )
END SUB
19) Answer:
17) SLC 2063 Answer:
CLS DECLARE FUNCTION sum(n)
DECLARE SUB square(N)
DECLARE FUNCTION INPUT "Enter how many numbers:-";n 21) SLC 2069 Answer:
sum(n)
s=sum(n) Re-write the given program REM display records of students from data
INPUT "Enter how many after correcting the bugs: file
numbers:-";n PRINT "Sum=";s
REM display records of OPEN “[Link]” FOR INPUT AS
s=sum(n) END students from data file #1
PRINT "Sum=";sum FUNCTION sum(n) OPEN “[Link]” FOR PRINT “ROLL”, “NAME”, “ADDRESS”,
FOR x= 1 to n INP AS #1 “CLASS”, “SECTION”
END
su=su+x PRINT “ROLL”, “NAME”, DO WHILE NOT EOF(1)
FUNCTION sum(n) “ADDRESS”, “CLASS”,
NEXT x “SECTION” INPUT #1, RN,N$,AD$,CL,S$
FOR x= 1 to n
Sum=su DO WHILE NOT EOF PRINT RN, N$, AD$, CL, S$
su=su+sum
END FUNCTION INPUT #1, RN,N$,AD$,CL,S$ LOOP
NEXT x
PRINT RN, N$, AD$, CL, S$ CLOSE #1
su=sum
NEXT END
END FUNCTION
CLONE#1
20) SLC 2068 Answer: END
CREATE FUNCTION DECLARE FUNCTION square (a)
square(a) 22) SLC 2070 Answer:
REM to print square of a number
REM to print square of a DECLARE SUB series() DECLARE SUB series()
number CLS
INPUT “A number”;a CLC CLS
CLS
PRINT square(a) EXECUTE series CALL series
GET “a number”;a
END END END
CALL square (a)
FUNCTION square (a) SUB series SUB series
END
ANS =a^2 RE to generate 2 2 4 6 10 REM to generate 2 2 4 6 10 ……upto
FUNCTION square (a) ……upto 10th term 10th term
Ans=a^2 Square = Ans
P=2 P=2
Square =Ans END FUNCTION
Q=2 Q=2
END square(a) FOR ctr=1 TO 5 FOR ctr=1 TO 5
DISPLAY p,q, PRINT p,q,
P=p+q P=p+q B=1 B=1
Q=p+q Q=p+q FOR ctr= 10 to 1 FOR ctr= 1 to 10
WEND NEXT DISPLAY a;b; PRINT a;b;
END series() END SUB A=a+b A=a+b
B=a+b B=a+b
23) SLC 2068 Supp. Ans: NEXT ctr NEXT ctr
REM to display the contents of REM to display the contents of data file END series() END SUB
data file
OPEN “[Link]” FOR INPUT AS #1
OPEN “[Link]” FOR
OUTPUT AS #1 CLS 25) SLC 2070 Ans:
(Supplementary)
CLS WHILE NOT EOF(1) OPEN “[Link]” FOR APPEND AS #1
OPEN “[Link]” FOR
WHILE EOF(1) INPUT #1 name$,age,add$ APPEND AS 1# INPUT “Name”;n$
INPUT #1 name$,age,add$ PRINT name$,age,add$ INPUT “Name”;n$ INPUT “Address”’add$
DISPLAY name$,age,add$ WEND INPUT “Address”’add$ INPUT “Age”;age
WEND CLOSE #1 INPUT “Age”;age$ WRITE #1,n$,add$,age
CLOSE 1 END WRITE #1,n$,add$,age CLOSE #1
END END #1 END
STOP
24) SLC 2067 Supp. Ans:
DECLARE SUB series() DECLARE SUB series() 26) SLC 2071 Ans:
CLS CLS DECLARE SUB cube (n) DECLARE SUB cube (n)
EXECUTE series CALL series CLS CLS
END END FOR I = 1 TO 5 FOR I = 1 TO 5
SUB series SUB series READ READ (no)
REM program to generate REM program to generate 11235…upto the CALL cube (no) CALL cube (no)
11235…upto the 20th term. 20th term.
NEXT x NEXT I
A=1 A=1
DATA 3,5,2,6,4 DATA 3,5,2,6,4
END END C=C+1 C=C+1
SUB cube ( ) SUB cube (n ) IF C<=2 AND C>=6 THEN IF C>=2 AND C<=6THEN
DISPLAY n^3 PRINT n^3 PRINT N$, Add$, DOB$ PRINT N$, Add$, DOB$
END SUB END SUB END IF END IF
LOOP LOOP
27) Ans: CLOSE #2 CLOSE #2
REM to add more records in REM to add more records in the existing END END
the existing data file data file
OPEN “[Link]” FOR OPEN “[Link]” FORAPPENDAS #2
OUTPUT AS #2 29) SEE 2072 Ans:
DO
DO FUNCTION SUM(m,n) DECLARE FUNCTION SUM(m,n)
INPUT “REG”; REG$
INPUT “REG”; REG$ Rem to print sum of two Rem to print sum of two numbers
INPUT “NAME”; NAME$ numbers
INPUT “NAME”; NAME$ a=6
INPUT “TEL”;TEL a=6
INPUT “TEL”; TEL$ b=7
WRITE#2REG$,N$,TEL b=7
WRITE REG$,N$,TEL$ PRINT SUM(a,b)
INPUT “WANT TO ADD MORE(Y/N)”; DISPLAY SUM(a,b)
INPUT “WANT TO ADD YN$ END
MORE(Y/N)”; YN$ END
LOOP WHILE UCASE$(YN$)=” Y ” FUNCTION SUM(m,n)
LOOP WHILE FUNCTION SUM(m,n)
CLOSE #2 S=m+n
UCASE$(YN$)=Y S=m+n
END SUM=s
CLOSE #2 S=SUM
END SUB
END END SUM
28) Ans:
REM to display records from REM to display records from 2ndposition to
2nd position to 6th position 6thposition
OPEN [Link] FOR INPUT OPEN“[Link]”FOR INPUT AS #2
AS #2
DO WHILENOTEOF(2)
DO WHILE EOF(2)
INPUT#2,N$, Add$, DOB$
INPUT #1, N, Add$, DOB$