1.
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 > B THEN
A$
= L$
ELSEIF
B > A OR B > C THEN
L$
= B$
ELSE
L$
= C$
END
IF
LONGEST$(A$,
B$, C$) = L$
FUNCTION
END
2.
DECLARE
SUB REV(S$)
CLS
ACCEPT
“ENTER ANY STRING”;S$
CALL
REV$(S$)
END
SUB
REV(S$)
FOR
I = LEN(S$) TO 1 STEP -1
B$
= MID$(S$,1,I)
W$
= W$ + B$
NEXT
I
IF
S$ = W$ THEN
PRINT
S$;”IS PALINDROME”
ELSE
PRINT
S$;”IS PALINDROME”
END SUB
3.
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
4.
DECLARE
SUB Hello (N)
CLS
INPUT “Enter a number”; Num
CALL Hello (N)
END
SUB Hello (N)
WHILE N > < 0
R=N MOD 10
REV=REV * 10 + R
N = N \ 10
WEND
PRINT “Its reversed form is”;
reverse
SUB END
5. 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
6. Rem program to reverse the string or word
DECLARE SUB REV(W$)
CLS
INPUT “Enter a wod”;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
7.
REM
to display the string in reverse form
CLS
DECLARE SUB REV(A$)
INPUT "ENTER A
STRING";A$
CALL REV(A)
END
SUB REV(A$)
FOR I=1 TO TEN
B$=MID(A$,I,1)
C$=B$+C$
NEXT I
PRINT C$
END SUB
8.
DECLARE
FUNCTION REV$(ST$)
CLS
INPUT “Enter a
string”; S$
LET R$=REV$(ST$)
PRINT “The string in reverse is”; R$
END
LET R$=REV$(ST$)
PRINT “The string in reverse is”; R$
END
FUNCTION REV$(ST$)
FOR I = LEN(ST$) TO 1
RV$=RV$+MID$(ST$,1,I)
NEXT I
RV$=REV$
END FUNCTION
NEXT I
RV$=REV$
END FUNCTION
9.
DECLARE
FUNCTION TEST(A$)
CLS
INPUT
"ENTER A STRING";N$
CALL
TEST$(N$)
PRINT
"Reverse of supplied string";D$
END
FUNCTION
TEST$(M$)
FOR I=1
TO LEN$(M$)
B$=MID$(M$,I,1)+B
NEXT I
B$=TEST$
END FUNCTION
10.
Rem
to count the character of given string
CLS
DECLARE
SUB Count (word$)
INPUT
”enter a string”, word$
Count
W$
END
SUB
Count (w$)
B$=MID$(WORD$,
C, 1)
WHILE
B$ < > ” ”
C=C+1
WEND
PRINT
C, “CHARACTERS IN “, W$
END FUNCTION
11.
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
12.
REM
to display a word by extracting characters of even position
CLS
DECLARE
SUB NAME$(X$,Y$)
INPUT”ENTER
A WORD”;X$
CALL
SUB NAME$(X$,Y$)
PRINT
Y$
END
SUB
WORD$(X$,Y$)
FOR P=1
TO LEN (X$) STEP 2
E$=LEFT$(X$,1,P)
WORD$=E$+WORD$
NEXT P
Y$=WORD$
END SUB
13.
REM
TO COUNT VOWELS USING NEPAL
DECLARE SUB REV(N$)
CALL REV(NEPAL)
END
SUB REV (N$)
N$=UCASE$(N$)
FOR K = 1 TO LEN(N$)
X$= MID$ (N$, 1, K)
SELECT CASE X$
CASE “A”, “E”,”I”,”O”,”U”
C = C+1
SELECT END
NEXT K
PRINT “VOWELS=”; C
END SUB
14.
DECLARE
FUNCTION OCCUR(C$)
INPUT
“Enter any sentence”; S$
PRINT
“Occurrence of A is”; OCCUR(C$)
END
SUB
OCCUR(C$)
C$
= UCASE$(C$)
L
= LEN(C$)
A
= 0
FOR
J = 1 TO L STEP -1
IF
“A” = MID$(C$, J, 1) THEN A = A + 1
NEXT
OCCUR
= A
END
FUNCTION
15.
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
16.
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
17.
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$,NS
WEND
KILL "EMP.DAT"
CLOSE #1,#2
NAME "TEMP.DAT" AS
"EMP.DAT"
END
18.
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
19.
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
20. 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
No comments:
Post a Comment