Sunday 30 September 2018

QBASIC PROGRAM - Debugging Programs

QBASIC PROGRAM - Debugging Programs - Computer Science [SLC / SEE] with answers (2075)



QBASIC PROGRAM - Debugging Programs - Computer Science [SLC / SEE] with answers



1.      DECLARE SUB correct( )
CLS
REM to calculate the area of rectangle
CALL SUB correct
END

SUB Correct
INPUT “enter length”;L
INPUT “enter breadth”;B
A= LENGTH* BREADTH
PRINT “area of rectangle=”;Area
SUB END

DECLARE SUB correct( )
CLS
REM to calculate the area of rectangle
CALL correct
END

SUB Correct
INPUT “enter length”;L
INPUT “enter breadth”;B
A= L*B
PRINT “area of rectangle=”; A
END SUB

2.      Rem program to find the cube of the cube of a given number
DECLARE FUNCTION CUBE(R)
ENTER R
DISPLAY CUBE(R)
END

FUNCTION CUBE(R)
S=R^3
PRINT S
COMPLETE

Rem program to find the cube of the cube of a given number
DECLARE FUNCTION CUBE(R)
INPUT R
PRINT CUBE(R)
END

FUNCTION CUBE(R)
S=R^3
CUBE = S
END FUNCTION
3.      [SLC 2065]
DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number; y
PRINT SUM(a,b)
END


FUNCTION SUM(x,y)
SUM=a+b
END

[SLC 2065]
DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number”; y
PRINT SUM(x, y)
END


FUNCTION SUM(a, b)
SUM=a+b
END FUNCTION

4.      [SLC 2072]
FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
DISPLAY SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
S = SUM
END SUM

[SLC 2072]
DECLARE FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
PRINT SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
SUM = S
END FUNCTION



5.      [SLC 2068]
CREATE FUNCTION Square(A)
Rem to print square of a number
CLS
Get “a number”; A
CALL square(A)
END


FUNCTION square(A)
Ans=A^2
Square=Ans
END Square(A)

[SLC 2068]
DECLARE FUNCTION Square(A)
Rem to print square of a number
CLS
INPUT “a number”; A
PRINT square(A)
END


FUNCTION square(A)
Ans=A^2
Square=Ans
END FUNCTION

6.      DECLARE FUNCTION AREA (X)
CLS
REM TO FIND THE AREA OF CIRCLE
INPUT “ENTER THE VALUE OF RADIUS”;R
CALL  AREA (R)
END

FUNCTION AREA (X)
 AR=    (22/7)* R^2
AR=AREA
FUNCTION END

DECLARE FUNCTION AREA (X)
CLS
REM TO FIND THE AREA OF CIRCLE
INPUT “ENTER THE VALUE OF RADIUS”;R
PRINT  AREA (R)
END

FUNCTION AREA (X)
 AR=    (22/7)* X^2
AREA=AR
END FUNCTION





7.      [SLC 2064] [SLC 2067 S]
DECLARE SUB Series()
CLS
EXECUTE Series
END
SUB Series()
REM program to generate  3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1
DISPLAY A;B;
A=A+B
B=A+B
NEXT ctr
END Series()

DECLARE SUB Series()
CLS
CALL Series
END
SUB Series()
REM program to generate  3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1 STEP-1
PRINT A;B;
A=A+B
B=A+B
NEXT ctr
END SUB

8.      [SLC 2066]
DECLARE SUB Fibonic ()
REM *Fibonic series*
CALL SUB Fibonic
END
SUB Fibonic
A=1
B=1
FOR x=1 to 10
DISPLAY a;
a=a+b
b=a+b
END Fibonic

  [SLC 2066]
DECLARE SUB Fibonic ()
REM *Fibonic series*
CALL Fibonic
END
SUB Fibonic
A=1
B=1
FOR x=1 to 10
PRINT a; b;
a=a+b
b=a+b
NEXT x
END SUB
9.      [SLC 2070]
DECLARE SUB Series(.)
CLS
EXECUTE Series
END
SUB Series
REM  to generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR           Ctr=1 TO 5
DISPLAY P,Q,
P=P+Q
Q=P+Q
WEND
END Series()

[SLC 2070]
DECLARE SUB Series(.)
CLS
CALL Series
END
SUB Series
REM  to generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR ctr=1 TO 5
PRINT P,Q,
P=P+Q
Q=P+Q
NEXT ctr
END SUB


10.   [SEE 2073]
DECLARE SUB SUM (N)
INPUT "Any Number"; N
PRINT SUM (N)
END

SUB SUM (N)
S = 0
WHILE N = 0
R = R MOD 10
S = S+R
N = N/10
WEND
PRINT "Sum of digits"; s
END





[SEE 2073]
DECLARE SUB SUM (N)
INPUT "Any Number"; N
CALL SUM (N)
END

SUB SUM (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S+R
N = N\10
WEND
PRINT "Sum of digits"; s
END SUB


11.   REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER MULTI-DIGITS NUMBER  ”N
PRINT “SUM  = ” ; SUM(N)
END

FUNCTION SUM(N)
WHILE N=0
R= N MOD 10
IF R MOD 2 = 1 THEN S=S+R
N = N / 10
WEND
SUM (N) =S
END FUNCTION

REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER MULTI-DIGITS NUMBER  ”N
PRINT “SUM  = ” ; SUM(N)
END

FUNCTION SUM(N)
WHILE N < > 0
R= N MOD 10
IF R MOD 2 = 0 THEN S=S+R
N = N \ 10
WEND
SUM  =S
END FUNCTION




12.   DECLARE FUNCTION arm (n)
INPUT” enter number”; n
FOR I = 1 TO n
a = I
b = arm (a)
IF b = I THEN
PRINT b
NEXT J
END

FUNCTION arm (n)
S = 0
WHILE a <> 0
r = n MOD 10
s = s + r ^ 3
n = n \ 10
up
arm = a
END FUNCTION

DECLARE FUNCTION arm (n)
INPUT” enter number”; n
FOR I = 1 TO n
a = I
b = arm (a)
IF b = I THEN
PRINT b
NEXT I
END

FUNCTION arm (n)
S = 0
WHILE n < > 0
r = n MOD 10
s = s + r ^ 3
n = n \ 10
WEND
arm = s
END FUNCTION

13.   DECLARE SUB ARM(NN)
CLS
INPUT “ENTER A NUMBER”; N
CALL ARM(N)
END

SUB ARM(A)
A = NN
WHILE A < > 0
R = A MOD 10
ACC = ACC + R ^ 10
A = A \ 3
WEND
IF ACC = A THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
END SUB

DECLARE SUB ARM(A)
CLS
INPUT “ENTER A NUMBER”; N
CALL ARM(N)
END

SUB ARM(A)
NN = A
WHILE A < > 0
R = A MOD 10
ACC = ACC + R ^ 3
A = A \ 10
WEND
IF ACC = NN THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
END SUB

14.   DECLARE GREAT SUB(a,b,c)
CLS
INPUT "ENTER 3 NUMBER";X,Y,Z
PASS GREAT (a,b,c)
END

SUB GREAT (a,b,c)
IF a>b and a>c THEN
g=a
ELSEIF b>a and b>c THEN
b=g
ELSE
g=c
END IF
PRINT g
SUB END

15.   DECLARE GREAT SUB(a,b,c)
CLS
INPUT "ENTER 3 NUMBER"; X,Y,Z
CALL GREAT (a,b,c)
END
SUB GREAT (a,b,c)
IF a>b and a>c THEN
g=a
ELSEIF b>a and b>c THEN
g=b
ELSE
g=c
END IF
PRINT g
END SUB
16.   [SLC 2074]
REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N$)
CLS
INPUT "Enter a number", X
PRINT "The Factorial is: ", FACTO (N)
END
FUNCTION FACTO (N)
F = 1
WHILE N = 0
F = F*N
N = N - 1
WEND
F = FACTO
END FUNCTION

REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N)
CLS
INPUT "Enter a number", X
PRINT "The Factorial is: ", FACTO (X)
END
FUNCTION FACTO (N)
F = 1
WHILE N < > 0
F = F*N
N = N - 1
WEND
FACTO = F
END FUNCTION

17.   DECLARE SUB FACT (N)
CLS
REM PRINT FACTORS OF INPUT NUMBER WITH SUB PROCEDURE
INPUT “ENTER NUMBER:”, A
CALL FACT(N)
END

SUB FACT (N)
FOR K=1 TO N
IF N MOD K =1 THEN
PRINT K
IF END
END FUNCTION

DECLARE SUB FACT (N)
CLS
REM PRINT FACTORS OF INPUT NUMBER WITH SUB PROCEDURE
INPUT “ENTER NUMBER:”, A
CALL FACT(A)
END
SUB FACT (N)
FOR K=1 TO N
IF N MOD K =0 THEN
PRINT K
END IF
END SUB
18.   DECLARE FUNCTION factor(N)
CLS
GET “Enter a number”; X
LET S = factor(X)
PRINT “Frequency of factor is” ; S
END Function

FUNCTION factor(N)
FOR I = 1 to N
G = N MOD I
IF G = 0 THEN
F=F+1
NEXT I
F = Factor
END FUNCTION

DECLARE FUNCTION factor(N)
CLS
GET “Enter a number”; X
LET S = factor(X)
PRINT “Frequency of factor is” ; S
END

FUNCTION factor(N)
FOR I = 1 to N
G = N MOD I
IF G = 0 THEN
F=F+1
END IF
NEXT I
Factor = F
END FUNCTION

19.   REM to check whether the supplied no is odd or even
DECLARE SUB TEST(N)
CLS
INPUT”ENTER THE NUMBER;”;N$
CALL TEST(N)
END

SUB TEST(N)
Y=2
R=Y MOD N
IF R=1 THEN
PRINT”EVEN”
OR
PRINT”ODD”
END
END SUB



REM to check whether the supplied no is odd or even
DECLARE SUB TEST(N)
CLS
INPUT”ENTER THE NUMBER;”;N
CALL TEST(N)
END

SUB TEST(N)
Y=2
R=N MOD Y
IF R=0 THEN
PRINT”EVEN”
ELSE
PRINT”ODD”
END IF
END SUB


20.   REM TO FIND LONGEST NAME
DECLARE FUNCTION LONGETS$(A$, B$, C$)
INPUT A$, B$, C$
PRINT LONGEST(A$, B$, C$)
END

FUNCTION LONGEST$(A$, B$, C$)
A = LEN$(A$)
B = LEN(B$)
C = LEN(C$)
IF A > B OR A > C THEN
A$ = L$
ELSEIF B > A OR B > C THEN
L$ = B$
ELSE
L$ = C$
END IF
LONGEST$(A$, B$, C$) = L$
FUNCTION END

REM TO FIND LONGEST NAME
DECLARE FUNCTION LONGETS$(A$, B$, C$)
INPUT A$, B$, C$
PRINT LONGEST$(A$, B$, C$)
END

FUNCTION LONGEST$(A$, B$, C$)
A = LEN(A$)
B = LEN(B$)
C = LEN(C$)
IF A > B AND A > C THEN
L$ =A$
ELSEIF B > A AND B > C THEN
L$ = B$
ELSE
L$ = C$
END IF
LONGEST$ = L$
END FUNCTION

21.   DECLARE SUB CHECK(N$,W$)
INPUT”ENTER A STRING:::”;N$
CHECK CALL (N$,W$)
END

SUB CHECK(N$,W$)
FOR K=1 TO LEN(W$)
A$=MID$(N$,1,K)
W$=W$+A$
NEXT K
IF W$=N$ THEN
PRINT “NOT PALINDROME”
ELSE
PRINT”PALINDROME”
END IF
END SUB

DECLARE SUB CHECK(N$,W$)
INPUT”ENTER A STRING:::”;N$
CALL CHECK (N$,W$)
END

SUB CHECK(N$,W$)
FOR K= LEN(W$) TO 1 STEP-1
A$=MID$(N$,K, 1)
W$=W$+A$
NEXT K
IF W$=N$ THEN
PRINT “PALINDROME
ELSE
PRINT” NOT PALINDROME
END IF
END SUB
22.   [SLC 2069]
Rem program to reverse the string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END

SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=LEFT$(W$,I,1)
S$=D$+1
LOOP
PRINT “Reverse string is:”; D$
CLOSE SUB

[SLC 2069]
Rem program to reverse the string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a word”;W$
CALL REV(W$)
END

SUB REV(W$)
FOR I=LEN(W$) to 1 step -1
C$=MID$(W$,I,1)
S$=S$+C$
NEXT I
PRINT “Reverse string is:”; S$
END SUB

23.   DECLARE FUNCTION REV$(ST$)
CLS
INPUT “Enter a string”; S$
LET R$=REV$(S$)
PRINT “The string in reverse is”; R$
END

FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1 STEP-1
RV$=RV$+MID$(ST$,I,1)
NEXT I
REV$= RV$
END FUNCTION

24.   REM test if user input character is alphabet or digit using sub procedure
DECLARE SUB TEST(C$)
ENTER “Supply a character”; T$
CALL TEST(C$)
END
SUB TEST(C$)
SELECT CASE T$
CASE “A” TO “Z” OR “a” TO “z”
PRINT “Alphabet”
CASE “0” TO “9”
PRINT “Digit”
SELECT END
END SUB

REM test if user input character is alphabet or digit using sub procedure
DECLARE SUB TEST(C$)
INPUT “Supply a character”; T$
CALL TEST(T$)
END
SUB TEST(C$)
SELECT CASE T$
CASE “A” TO “Z” , “a” TO “z”
PRINT “Alphabet”
CASE “0” TO “9”
PRINT “Digit”
END SELECT
END SUB


25.   DECLARE FUNCTION dec(N)
INPUT”ENTER ANY BINARY NUMBER:’;n
PRINT”DECIMAL EQUIVALENT”;dec(n)
END

FUNCTION dec(N)
P=1
WHILE N<>0
R= N MOD 10
S=S+R*10^P
P=P+1
N=N/10
WEND
S=DEC
END FUNCTION

DECLARE FUNCTION dec(N)
INPUT”ENTER ANY BINARY NUMBER:’;n
PRINT”DECIMAL EQUIVALENT”;dec(n)
END

FUNCTION dec(N)
P=0
WHILE N<>0
R= N MOD 10
S=S+R*2^P
P=P+1
N=N\10
WEND
DEC=S
END FUNCTION


26.   REM do display the reverse of the supplied number
DECLARE FUNCTION rev(n)
CLS
INPUT n
PRINT rev(n)
END

FUNCTION rev(n)
WHILE n = 0
R = n MOD 10
D$ = STR$(R) + D$
n = n / 10
WEND
Rev = ASC(D$)
END FUNCTION



REM do display the reverse of the supplied number
DECLARE FUNCTION rev(n)
CLS
INPUT n
PRINT rev(n)
END

FUNCTION rev(n)
WHILE n < > 0
R = n MOD 10
D$ = D$ + STR$(R)
n = n \ 10
WEND
Rev = VAL(D$)
END FUNCTION

27.   DECLARE FUNCTION userlen (a$)
REM length of sting without LEN function
CLS
INPUT “Type any string value: ”; b$
PRINT “Length of the string: “; userlen(a$)
END

FUNCTION userlen (a$)
c=1
aa:
b$ = MID$(a$, p, 1)
IF b$ = “THEN”
p=p+1
c=c+1
GOTO aa
END IF
userlen = c
END FUNCTION

DECLARE FUNCTION userlen (a$)
REM length of sting without LEN function
CLS
INPUT “Type any string value: ”; b$
PRINT “Length of the string: “; userlen(b$)
END

FUNCTION userlen (a$)
c=1
aa:
b$ = MID$(a$, c, 1)
IF b$ < > “”
p=p+1
c=c+1
GOTO aa
END IF
userlen = p
END FUNCTION

28.   REM to print odd numbers from 32 to 12
DECLARE SUB SHOW ( )
CLS
CALL SHOW ( )
END

SUB SHOW ( )
N = 12
WHILE N <= 32
IF N MOD 2 = 0 THEN PRINT N;
N = N-1
NEXT N
END SUB

REM to print odd numbers from 32 to 12
DECLARE SUB SHOW ( )
CLS
CALL SHOW
END

SUB SHOW ( )
N = 32
WHILE N >= 12
IF N MOD 2 = 0 THEN PRINT N;
N = N-1
WEND
END SUB

29.   REM to remove odd digits from a supplied numbers
DECLARE FUNCTION remodd(n)
CLS
INPUT “any number”; a
PRINT “Even digits only”; remodd(n)
END
FUNCTION remodd(n)
p = 0
WHILE n < > 0
R = n MOD 10
IF r MOD 2 = 1 THEN
s = s + r ^ p
p = p * 10
END IF
N = n \ 10
WEND
S = remodd
END FUNCTION





REM to remove odd digits from a supplied numbers
DECLARE FUNCTION remodd(n)
CLS
INPUT “any number”; a
PRINT “Even digits only”; remodd(a)
END
FUNCTION remodd(n)
p = 1
WHILE n < > 0
R = n MOD 10
IF r MOD 2 = 0 THEN
s = s + r * p
p = p * 10
END IF
N = n \ 10
WEND
 remodd = s
END FUNCTION

30.   DECLARE SUB CHECK(N)
CLS
INPUT”ENTER A NUMBER”;NUM
C=CHECK(N)
END
SUB CHECK(A)
FOR I=2 TO N/2
IF N MOD 1=0 THEN
C=C+2
END IF
WEND
IF C>0 THEN
PRINT”IT IS COMPOSITE”
ELSE
PRINT”IT IS PRIME”
END IF
END SUB
DECLARE SUB CHECK(N)
CLS
INPUT”ENTER A NUMBER”;NUM
CALL CHECK(NUM)
END
SUB CHECK(N)
FOR I=2 TO N/2
IF N MOD I=0 THEN
C=C+1
END IF
NEXT I
IF C>0 THEN
PRINT”IT IS COMPOSITE”
ELSE
PRINT”IT IS PRIME”
END IF
END SUB
31.   REM to check the number is prime or not
DECLARE SUB CHECK(N)
CLS
INPUT N
CALL CHECK(N)
END

SUB CHECK(N)
I=3
DO
IF N MOD I = 0 THEN
PRINT “ NOT PRIME
END
END IF
I = I + 1
LOOP UNTIL I >N – 1
PRINT “PRIME”
END SUB

32.   REM to display those records whose name starts from “A”.
OPEN “Employee.dat” FOR OUTPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #, N$, P$, S#
C$=MID$(N$, 1, 1)
IF C$=”A” THEN
PRINT #1, N$, P$, S#
END IF
LOOP       
CLOSE #1
END

REM to display those records whose name starts from “A”.
OPEN “Employee.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S#
C$=MID$(N$, 1, 1)
IF C$=”A” THEN
PRINT N$, P$, S#
END IF
WEND      
CLOSE #1
END
33.   REM to display records from 2nd position to 6th position.
OPEN record.txt FOR INPUT AS #2
DO WHILE EOF(2)
INPUT #1, N$, Add$, DOB$
C=C+1
IF C<=2 AND C>=6 THEN
PRINT N$, Add$, DOB$
END IF
LOOP
CLOSE #2
END

REM to display records from 2nd position to 6th position.
OPEN “record.txt” FOR INPUT AS #2
DO WHILE NOT EOF(2)
INPUT #2, N$, Add$, DOB$
C=C+1
IF C>=2 AND C<=6 THEN
PRINT N$, Add$, DOB$
END IF
LOOP
CLOSE #2
END

34.   REM display all data if post is manager or officer
OPEN “info.dat” FOR INPUT AS #1
CLS
PRINT “Name”, “Post”, “Dept”, “Salary”
DO WHILE NOT EOF(10)
INPUT N$, P$, D$, S
IF P$ = “MANAGER” AND P$ = “OFFICER” THEN
PRINT N$, P$, D$, S
END IF
WEND
CLOSE
END


35.   REM display all data if post is manager or officer
OPEN “info.dat” FOR INPUT AS #1
CLS
PRINT “Name”, “Post”, “Dept”, “Salary”
DO WHILE NOT EOF(1)
INPUT #1, N$, P$, D$, S
IF P$ = “MANAGER” OR P$ = “OFFICER” THEN
PRINT N$, P$, D$, S
END IF
LOOP
CLOSE
END

36.    [SLC 2067]
REM to display all the records from sequential data file ABC.DAT
OPEN “ABC.DAT” FOR OUTPUT AS # 1
DO WHILE NOT EOF(“ABC.DAT”)
INPUT # 1,N$,A
PRINT N$,A
CLOSE 1
END

[SLC 2067]
REM to display all the records from sequential data file ABC.DAT
OPEN “ABC.DAT” FOR INPUT AS # 1
DO WHILE NOT EOF(1)
INPUT # 1,N$,A
PRINT N$, A
LOOP
CLOSE # 1
END

37.   [SLC 2068 S]
Rem to display the contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
            INPUT #1, Name$, Age, Add$
            DISPLAY Name$, Age, Add$
WEND
CLOSE 1
END

[SLC 2068 S]
Rem to display the contents of a data file.
OPEN “Marks.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
            INPUT #1, Name$, Age, Add$
            PRINT Name$, Age, Add$
WEND
CLOSE #1
END

38.   [SLC 2069]
REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INP AS #1
PRINT “ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”
DO WHILE NOT EOF
               INPUT #1,RN,N$,AD$,CL,S$
               PRINT RN,N$,AD$,CL,S$
NEXT
CLOSE #1
               END

[SLC 2069]
REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INPUT AS #1
PRINT “ROLL”, “NAME”, “ADDRESS”, “CLASS”, “SECTION”  
DO WHILE NOT EOF(1)
               INPUT #1, RN, N$, AD$, CL, S$
               PRINT RN, N$, AD$, CL, S$
LOOP
CLOSE #1
               END
39.   REM Program to store data in a sequential data file.
DO
CLS
OPEN “Address.txt” FOR INPUT AS #1
INPUT “Name”; N$
INPUT “Address”; A$
INPUT “Age”; A
INPUT “Phone”; P$
WRITE N$,A$,A,P$
INPUT “Do you want some more….”; ans$
LOOP WHILE UCASE(ans$)=”Y”
CLOSE #1
END

REM Program to store data in a sequential data file.
OPEN “Address.txt” FOR OUTPUT AS #1
DO
CLS
INPUT “Name”; N$
INPUT “Address”; A$
INPUT “Age”; A
INPUT “Phone”; P$
WRITE #1, N$, A$, A, P$
INPUT “Do you want some more….”; ans$
LOOP WHILE UCASE$(ans$)=”Y”
CLOSE #1
END
40.   [SLC 2066 S]
REM To store Name, post and salary
OPEN “EMP.DOC” FOR OUT AS #1
INPUT” Enter name”;N
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #2, N$,P$, S
CLOSE #1
END
[SLC 2066 S]
REM To store Name, post and salary
OPEN “EMP.DOC” FOR OUTPUT AS #1
INPUT” Enter name”;N$
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #1, N$, P$, S
CLOSE #1
END

41.   REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR INPUT AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T
ADD #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS
LOOP WHILE UCASE(ANS$) = Y
CLOSE
END

REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR APPEND AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T
WRITE #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS$
LOOP WHILE UCASE$(ANS$) = “Y”
CLOSE
END


42.   REM to add records in “marks.dat” sequential data file
OPEN “A”, 2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE#1, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
TERMINATE
END

REM to add records in “marks.dat” sequential data file
OPEN “A”, #2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE #2, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
CLOSE #2
END
43.   REM to update the salary by 10%
CLS
OPEN "EMP.DAT" FOR INPUT AS #1
OPEN "TEMP.DAT" FOR OUTPUT AS#1
WHILE NOT EOF(1)
INPUT NM$, POST$, S
LET  NS = S + S*10/100
WRITE NM$, POST$, S
WEND
KILL "EMP.DAT"
CLOSE #1,#2
NAME "TEMP.DAT" AS "EMP.DAT"
END

REM to update the salary by 10%
CLS
OPEN "EMP.DAT" FOR INPUT AS #1
OPEN "TEMP.DAT" FOR OUTPUT AS#2
WHILE NOT EOF(1)
INPUT #1, NM$, POST$, S
LET  NS = S + 10/100*S
WRITE #2, NM$, POST$, S
WEND
KILL "EMP.DAT"
CLOSE #1,#2
NAME "TEMP.DAT" AS "EMP.DAT"
END
44.   CLS
REM copy the data of ‘mark.dat’ file to ‘update.dat’ file.
OPEN "MARK.DAT" FOR OUTPUT AS #1
OPEN “UPDATE.DAT” FOR OUTPUT AS #2
DO UNTIL EOF (1)
INPUT #2, RollNumber, N$, Age
WRITE #2, RN, N$, Age
CLOSE #1, 2
LOOP
END

CLS
REM copy the data of ‘mark.dat’ file to ‘update.dat’ file.
OPEN "MARK.DAT" FOR OUTPUT AS #1
OPEN “UPDATE.DAT” FOR OUTPUT AS #2
DO UNTIL EOF (1)
INPUT #1, RN, N$, Age
WRITE #2, RN, N$, Age
LOOP
CLOSE #1, #2
END

45.   REM COPY THE DATA OF “SRC.INF” TO “DEST.INF”
OPEN “SRC.INF” FOR INPUT AS #1
OPEN “DEST.INF” FOR OUTPUT AS #2
CLS
WHILE NOT EOF( )
INPUT #2, NM$, RN, AGE
WRITE #1, NM$, RN, AGE
CLOSE #1, #2
END

REM COPY THE DATA OF “SRC.INF” TO “DEST.INF”
OPEN “SRC.INF” FOR INPUT AS #1
OPEN “DEST.INF” FOR OUTPUT AS #2
CLS
WHILE NOT EOF( 1)
INPUT #1, NM$, RN, AGE
WRITE #2, NM$, RN, AGE
WEND
CLOSE #1, #2
END


MCQ Question Bank Microsoft PowerPoint