QUICK-BASIC
BASIC
G BASIC à Interpreter
Q BASIC à ”
Q/B à Compiler
String Data Numeric Data
( alpha numeric
data ) (number)
Variable String constant string Variable no. constant no.
X
= 6
Numeric Variable Numeric
Constant
N$ = “RiiT”
String Variable String
Constant
NB
1) A
variable name Always start with a character, can’t start with a number.
2) Maximum
number of character can be up to 40.
3) No
Special Character can’t be allowed inside a variable name other then
underscore.
Ë Write a Program to enter the name and basic pay of
an employee.
INPUT
“Enter a name”, N$
INPUT
“Enter the Basic pay”, BP
PRINT N$, BP
END
Ë WAP to enter name and marks in two subjects print
the name and total marks.
INPUT
“Enter Name”, N$
INPUT
“Enter 1st mark”, N1,
INPUT “Enter 2nd
mark”,N2
Tot
= N1+N2
PRINT N$, Tot
END
Ë WAP to enter name and three marks. Print name total
marks and average marks.
INPUT
“Enter name”, N$
INPUT
“ Enter three marks”, N1, N2, N3
Tot
= N1+N2+N3
Ave
= Tot/3
?
N$, Tot, Ave.
END
Ë WAP to enter the number of units of electricity
consumed by customer. Print the bill amount . Electric Charge 80p/unit.
INPUT
“Enter the number of units”, U
BA
= (U*80)/100
?
BA
END
Ë WAP to enter name and basic pay of an employee
Calculate the net pay as Follows.
DA
= 3% of BP
HRA = 2% of BP
TAX = 1% of BP
at the end of the program print the name and the Net-pay.
INPUT
“Enter a Name”, N$
INPUT
“ Enter the basic-pay”, BP
DA
= BP * 3/100
HRA
= BP * 2/100
TAX
= BP * 1/100
NP
= BP+DA+HRA-TAX
?
N$, NP
END
Flow chat helping in write a program.
à Start / Stop à
DESICCON BOX
à
Connector.
à
Processing
Ë Draw a flow chart. Write a program to enter name and
age of person. If age less than 18 print you can not vote else print you can
vote.
Start CLS
INPUT N$ INPUT
“Enter the age”, age
<18 à can vote
à
Stop Else
â
? N$, “You can’t vote”
can’t vote END
Stop
Ë Draw a flow chart. WAP
to enter name and two marks. If average marks is <40 print fail Else print
Pass.
Start
INPUT N$ M1, M2.
? N$, “Pass” CLS
Stop INPUT “Enter the marks”, M1,M2
IF AVM
< 40 Then
? N$, ”Fail”
Else
? N$, “Pass”
End If
END
Ë WAP to enter name and
basic pay of an employee Calculate and print the net pay.
IF
BP <= 5000 then DA = 2% of BP
HRA
= 3% of BP
No
TAX
If BP between 5000 then 10000
then DA = 3% of BP
HRA = 3% of BP
TAX = 1% of BP
If BP>10000 then DA = 3% of BP
HRA = 5% of BP
TAX = 2% of BP
Input
“Enter the name ", N$
Input
“Enter the Basic Pay”, BP
If <=5000 Then
DA
= BP*2/100
HRA = BP*3/100
Else
If BP> 5000 and BP <= 10000 then
DA
= BP*3/100
HRA = BP*3/100
TAX = BP*1/100
Else
If
BP > 10000
DA = BP*3/100
HRA = BP*5/100
TAX = BP*2/100
End
If
NP
= BP+DA+HRA-TAX
?
NP
END
Ë Draw a flow chart and
write a program to enter name and age of a person.
If
age <5 print you are a child.
Between
5 and 12 print you are an young.
Between
13 and 19 print you are a teenager.
If
age>19 then print you are an adult.
Input “Enter the age”, Age Input N$ Age
Else If Age<13 Then Age<5 à ? “You are a child” N
? “You are a Young” ê
? “You are a teenager” Age<13à ? “You are a Young
Else Age >19 then
End IF Age<=19 à?“You are a Teenager”
End
? “You are an adult”
Stop
Ë Draw a Flow Chart and
write a program to enter the number of electricity consumed. Print the Bill amount given That
1st
100 = 80 p/unit
2nd
100 = 1 p/unit
3rd
100 = 1.20 p/unit
>400 =
1.50 p/unit
Start
Input U
ê
U<=100 à BA = (U*80)/100
ê
U<=200 à BA = (100*80)/100 + (U-100) * 1.00
ê
U<=400 à BA = (100*80)/100 + (100*1.00) + (U-200)*1.20
ê
BA = (100*80)/100 + (100*1.00) + (200*1.20)
+ (U-400) * 1.50
ê
? BA
Stop
Input
“ Enter the number of unit “ U
If
U<=100 then
BA
= (U*80)100
Else
If U<= 200 Then
BA
= (100*80)/100 + (U-100)*1.00
Else
If U<=400 Then
BA
= (100*80)/100 + (100*1.00) + (U-200)*1.20
Else
U>400 Then
BA
= (100*80)/100 + (100*1.00) + (200*1.20) + (U-400)*1.50
End
If
?
BA
End
FOR……………………NEXT
WHILE………………..WEND
DO
WHILE…………...LOOP
DO
UNTIL……………LOOP
Ë Write a program to enter name and two marks for 10
students print name and total marks for each student.
FOR
I = 1 to 10
Input
“Enter The Name”, N$
Input “two
marks”, m1 , m2
TM =
(m1+m2)
? N$ , TM
NEXT
END
Ë Write a program to print all the number from 1 to
100
FOR I = 1 to 100
? I
NEXT
END
Ë Write a program to enter a name and print the name
10 times.
Input
“Enter the name “, N$
FOR I = 1 to 10
?
N$
NEXT
END
Ë Write a program to print all the event number from
100 to 1.
For
I = 1 to 100 Step -2
?
I
NEXT
END
Ë Write a Program to print the sum of the first 10
even numbers.
FOR
I = 2 to 20 Step 2
SUM
= SUM + I
NEXT
?
SUM
END
Ë Write a program to enter the number of student in
class for each student enter two mark. If average marks is >= 40 then the
student has pass else fail. Print total number of failers and pass.
Input
“ Enter the number of student “, S
For
I = 1 to S
Input
“ Enter two marks”, m1 , m2
IF AVM
>= 40 THEN
PASS
= PASS + 1
FAIL
= FAIL + 1
END IF
NEXT
?
PASS
?FAIL
END
Ë WAP to enter the number of student in a class for
each student enter total marks score print the average marks.
Input
“ Enter the number of student “, S
For
I = 1 to S
Input
“ Enter total marks”, To
TM
= TM + To
NEXT
? AVM
END
Ë WAP to enter names each times print the name. The
programs Stop When the name zzz is enter.
Input
“ Enter the name”, N$
DO
WHILE N$ <> “zzz”
?
N$
Input
N$
END
Ë Write a program to enter 10 numbers. Print the
product of all numbers.
P
= 1
FOR I = 1 to 10
Input
“ Enter ten number “, N
P
= P * N
NEXT
? P
END
Ë Write to enter numbers (terminated by 0) find the
sum of all the numbers.
Input
“ Enter the number “, N
DO
WHILE N <>0
SUM = SUM
+ N
Input
“Enter the number “, N
? N
END
Ë WAP to enter the number of employee in a company.
Each time input basic pay. Find out the total payment made by the company to
the employee.
Input
“ Enter the number of employee “, NE
FOR I = 1 to NE
Input
“Basic Pay “, BP
Tot
= Tot + BP
NEXT
? TOT
END
Ë WAP to enter the run score by 11 players of a team.
Find the total runs score by the team and average run and run rate in 50 overs.
For I = 1 to 10
Input “ Enter the run score by a player “, R
Tot
= Tot + R
NEXT
RR
= Tot / 50
?
Tot, AVR , RR
END
FUNCTION
If helps us to do specific Job.
Interior
(Int)
If bring the number
nearest smallest number.
Int (-
- - -)
Ë Write a program enter a number print number of
digit.
Input “Enter a number”, N
DO WHILE N <> 0
N
= Int (N/10)
ND
= ND + 1
? ND
END
NB à The mod operator return the remainder of division
Ë Write a program to enter a number and print the last
digit.
Input
“ Enter a number”, N
LD
= N mod 10
?
LD
END
Ë Write a program to enter a number print the sum of
all Digit.
Input
“ Enter the number”, N
DO
WHILE N <> 0
LD
= N Mod 10
S = S + LD
N = Int (N/10)
?
S
END
Ë Write a program to enter a number print if even or
odd.
Input
“Enter a number “, N
LD
= N Mod 2
If
ld = 0 Then
?
“Even”
Else
?
“Odd”
END
IF
END
Ë Write a number count the number of digit. If number
of digit even print even digited number Else Odd digited number.
Input
“Enter a Number “, N
Do
While N <> 0
N = Int (N/10)
ND = ND + 1
If ND Mod 2
= 0 then
?
“ Even digited number”
Else
?
“Odd digited number”
End if
End
Ì Write a program to enter a number print the first
and last digit.
Input
“Enter the number “, N
T
= N
Do
While N <> 10
N = N Mod 10
ND = ND +1
N
= T
LD
= N Mod 10
X
= 10^(nd-1)
Fd
= Int (t/n)
?
“Last Digit” LD
?
“First Digit” FD
END
Ë Enter a number print if it is ARMSTRONG
number. ( An Armstrong number is a number whose sum
of the qubes of digit is equal to the number of itself.)
Input
“Enter a number “, N
T
= N
Do
While N <> 0
LD
= N Mod 10
Q
= Ld * Ld *Ld
Sum
= Sum + Q
N
= Int (N/10)
N
= T
If
Sum = N Then
?
“Armstrong Number”
Else
?
“ Non Armstrong Number”
End
If
End
Ë Enter a number count the number of digit., If number
of digit even then print the sum of all digit, else print odd digit.
Input
“Enter a number”, N
T
= N
Do
While N <> 0
N
= N\10
Nd
= Nd + 1
N
= T
Nd
= Nd Mod 2
If
nd = 0 then
Do
While N <> 0
Ld
= N mod 10
Sum
= Sum + ld
N
= N\10
?
“Sum of even digit”, Sum
Else
?
“Odd digit”
End
If
END
Ë Print the Armstrong
number from 1 to 1000.
For
I = 1 to 1000
Sum
= 0
T
= I
Do
While T <> 0
LD
= T Mod 10
Q
= Ld^3
Sum
= Sum + Q
T
= T\10
If I = Sum then
?
I
End
If
Next
End
Ë Write a program to enter a number. If prime or
Composit.
Input
“ Enter the number “, N
For
I = 2 to (n-1)
Ld = N Mod I
If Ld =
0 then
Fl
= 1
Exit
for
End
If
Next
If
Fl = 0 then
?
“Prime”
Else
?
“Composit”
End
If
END
Ë Print the prime and composit number from 1 to 100
For
I = 1 to 100
For
A= 2 to 99
Ld = I Mod A
If
Ld = 0 then
Fl = 1
Exit
for
Next
If Fl
= 0 then
? I “Prime”
Else
?
I “Composit”
End
If
Next
End
STRING
RIGHT
$ ( )
LEFT
$ ( )
MID
$ ( )
Ë WAP to enter a string print the number of character.
Input
“Enter a String ”, N$
X
= LEN (N$)
?
X
END
Ë Write a program to get output as follows :-
H
HE
HELL
HELLO
N$
= HELLO
For
I = 1 to 5
X$ = Left $ (N$,I)
?
X$
Next
END
Ë WAP to enter a string print all the character.
Input
“Enter a string”, N$
L
= LEN (N$)
For
I = 1 to L
X$
= Mid $ (N$,I,1)
?
X$
Next
END
Ë Write a program to enter a string print the
alternate characters.
Input
“Enter a number “, N$
L
= Len (N$)
For
I = 1 to L Step 2
X$
= Mid $ (N$,I,1)
?
X$
Next
End
Ë Write a program to enter a string. Print reverse
String.
Input
“Enter a string”, N$
L
= Len (N$)
FOR
I = L to 1 Step -1
X$
= Mid$ (N$,I,1)
?
X$
Next
END
Ë Write a program to enter a word print if it is a
pallendrome.
Input
“Enter the Word”, N$
L
= Len (N$)
For
I = L to 1 Step -1
X$
= Mid $ (N$,I,1)
L$
= L$ + X$
Next
If
L$ = N$ then
?
“It is a pallendrome”
End
If
END
Ë Enter a sentence count the number of times the
character “A” Occurs.
Input
“Enter a Sentence”, N$
L=
Len (N$)
For
I = 1 to L
X$
= Mid$ (N$,I,1)
If
X$ = “A” then
S=
S+1
End
If
Next
?
S
END
Ë WAP to enter a sentence count the no. of word in a
sentence.
Input
“Enter a sentence”, N$
L
= Len (N$)
For
I = 1 to L
X$
= Mid $ (N$,I,1)
If
X$ = “ “ Then
Sum
= Sum + 1
End
If
Next
W=
Sum + 1
?
“Word” W
End
Ë Write a program to enter a sentence count the number
of Vowels.
Input
“Enter a Sentence “, N$
L
= Len (N$)
For
I = 1 to L
X$
= Mid$ (N$,I,1)
IF
X$ = “A” or X$ = “E” or X$ = “I” or X$ = “O” or X$ = “U” then
Sum
= Sum + 1
End
If
Next
?
Sum
End
Ë WAP to enter a sentence count the number of times
“is” Occurs
Input
“Enter a sentence “, N$
L
= Len (N$)
For
I = 1 to L
X$
= Mid $ (N$,I,2)
IF
X$ = “is” then
Sum
= Sum + 1
End
If
Next
?
Sum
End
Ë WAP to enter a sentence count the number of words.
(The word may be separated by more then a one space).
Input
“Enter a sentence”, N$
L
= Len (N$)
For
I = 1 to L
X$
= Mid $ (N$,I,1)
Y$
= Mid $ (N$,I+1,1)
If
X$ = “ ” And Y$ <> “ ” then
S = S+1
End
If
Next
?
W = S+1
?
W
End
Ë Write a program to enter a sentence. Enter a word to
insert and a position to insert the Word in Proper Position.
Input
“Enter a Sentence “, N$
Input
“ Enter a Word “, W$
Input
“Enter a Position”, P
L
= Len (N$)
X$
= Left $ (N$, P)
Y$
= Mid $ (N$, P, L-P)
?
X$ + W$ + Y$
END
Ë Enter a Name print the Surname first and then the
name. If the name does not a surname print illegal.
Input
“Enter a Name”, N$
L
= Len (N$)
For
I = L to 1 Step -1
X$
= Mid $ (N$,I,1)
If
X$ = “ ” then
Exit
for
End
If
Next
C$ = MID $
(N$,I,1)
For J = 1
to L
B$
= Mid $ (N$,J,1)
If
B$ = “ ” Then
Exit For
End
If
Next
D$ = Mid $
(N$,1,J-1)
P$ = C$ + “
” + D$
IF
I = 0 then
?
“Illegal Name”
Else
?
P$
End
If
End
Ë WAP to enter a name print the enitials of the name.
Input
“Enter a name “, N$
L
= Len (N$)
A$
= Mid $ (N$,I,1)
For
I = 1 to L
B$
= Mid $ (N$,I,1)
If
B$ = “ ” Then
A$ = A$ + “ . ” Mid $ (N$,I+1,1)
End
If
Next
?
A$
End
Ë Write a program to enter a name print enitials and
full surname.
Input
“Enter a name “, N$
L
= Len (N$)
For
I = L to 1 Step -1
A$
= Mid $ (N$,I,1)
If
A$ = “ ” Then
Exit
For
End
If
Next
X$
= Mid $ (N$,I+1)
Y$
= Mid $ (N$,I,1)
For
J = 1 to I-1
B$
= Mid $ (N$,J,1)
If
B$ = “ ” Then
Y$
= Y$ + “ . ” + Mid $ (N$,J+1,1)
. End
If
Next
?
Y$ + “ . ” + X$
End
Ë WAP to enter a sentence. Enter a word to delete from
the text.
Input
“Enter a sentence “, N$
Input
“ Enter the word to delete”, W$
N$
= N$ + “ ”
L
= Len (N$)
For
I = 1 to L
A$
= Mid $ (N$,I,1)
If
A$ = “ ” Then
If
P$ <> W$ then
H$ = H$ + P$ + “ ”
End
If
P$ = “ ”
Else
P$
= P$ + A$
End
If
Next
?
H$
End
Ë Write a program to enter a sentence replace all the
word “is” to “was”.
Input “Enter a sentence “, N$
Input
“Enter a word to delete “, W$
Input
“Enter a word to replace”, R$
N$
= N$ + “ ”
L
= Len (N$)
For
I = 1 to L
A$
= Mid $ (N$,I,1)
If
A$ = “ ” Then
If
P$ = W$ Then
H$ = H$ + R$ + “ ”
Else
H$ = H$ + P$ + “ ”
End
If
P$ = P$ + A$
Else
P$ = P$ + A$
End
If
Next
?
H$
End
ASCII à American Standard code
for information Interchange.
X = ASC (A) X$ = CHR $
(65)
Ascu value of Character
a Character
Capital Letters Small
Letters Diffrence
A TO Z a to z 32
Value à 65 to 95 Value
à
97 to 122
Ë WAP to enter a character in small. Print the
character in capital.
Input “Enter a small character ”, N$
X = ASC (N$)
D$
= CHR $ (X-32)
?
D$
END
Ë WAP to enter a character in any cash convert all
character in small.
Input
“Enter a character “, N$
X
= ASC (N$)
If
X > 64 and X <= 90 Then
N$
= CHR $ ( X + 32)
End
If
?
N$
End
Ë WAP to enter a word in lower case convert to upper
case.
Input
“ Enter a word in lower case ”, N$
L
= (N$)
For
I = 1 To L
D$
= Mid $ (N$,I,1)
X
= ASC (D$)
D$
= CHR $ (X - 32)
P$
= P$ + D$
Next
? P$
End
Ë WAP to enter a sentence or word in mixed case
convert to upper case.
Input “Enter a sentence in any case “, N$
L
= Len (N$)
For
I = 1 to L
D$
= Mid $ (N$,I,1)
X
= ASC (D$)
If
X > 96 and X <= 122 Then
D$
= CHR $ (X – 32)
End
If
P$
= P$ + D$
Next
? P$
End
Ë WAP to enter a sentence convert lower case into
upper case and upper case into lower case.
Input
“Enter a sentence in any case”, N$
L
= Len (N$)
For
I = 1 to L
D$
= Mid $ (N$,I,1)
X
= ASC (D$)
If
X > 96 And X <= 122 then
D$
= CHR $ (X – 32)
End
If
If
X > 64 And X <= 90 then
D$
= CHR $ (X + 32)
End
If
P$ = P$ + D$
Next
? P$
End
Ë WAP to Enter a string and convert the string so that
if the string is ABC then convert
from BCD.
Input “Enter a string”, N$
L
= Len (N$)
For
I = 1 to L
A$
= Mid $ (N$,I,1)
X
= ASC (A$)
If
X = 90 or X = 122 Then
A$
= CHR $ (X – 25)
Else
A$
= CHR $ (X + 1)
End
If
P$
= P$ + A$
Next
? P$
End
Ë WAP to enter a sentence in any case convert the 1st
character of every word in capital and next in small.
Input “Enter a sentence”, N$
L
= Len (N$)
S$
= Mid $ (N$,I,1)
X
= ASC (S$)
If
X > 96 And X <= 122 Then
S$
= CHR $ (X – 32)
End
If
For
I = 2 to L
B$
= Mid $ (N$,I,1)
X
= ASC (B$)
If
X > 64 And X <= 122 Then
B$
= CHR $ (X – 32)
End
If
Else
I
= I + 1
B$
= Mid $ (N$,I,!)
X
= ASC (B$)
If
X > 96 And X <= 122 Then
B$
= CHR $ (x-32)
End
If
B$
= “ ” + B$
End
If
S$ = S$ + B$
Next
? S$
End
ARRAY HANDLING
Ë Enter ten names & print ten names.
DIM
N$ (10)
FOR
I = 1 to 10
Input
“Enter ten names”, N$ ( I )
Next
For
I = 1 to 10
? N$ ( I )
Next
Ë WAP to enter a number between 1 to 10 print the
numbers in words.
DIM
N$ (10)
FOR
I = 1 to 10
Read
N$ ( I )
Next
Input
“Enter a number”, X
? N$ (X)
END
Ë WAP to enter number 1 to 99 print in words
DIM N$ (19), N$ (8)
For
I = 1 to 19
Read N$ (1)
Next
For
J = 1 to 8
Read N$ (J)
Next
Input
“Enter a number”, N
If
N > 99 Then
? “Can’t Display”
? N$ (N)
Else
LD = N Mod 10
FD = N/10
If LD = 0 then
? N$ (FD – 1)
Else
? N$ (FD – 1) + N$ (LD)
End If
End If
END
Ë WAP to enter ten names in an array. Enter a name to
search. Print “Founds” or “Not Found”
Dim N$(10)
For
I = 1 to 10
Input
N$ (1)
Next
Input
“Enter a name to search”, S$
For
I = 1 to 10
If
S$ = N$ (1) Then
? “Found”
End
End
If
Next
? “Not Found”
End OR
(PTO)
Dim
N$ (10)
For
I = 1 to 10
Input
“Enter names”, N$ (I)
Next
Input
“Enter name to score”, N$
For
I = 1 to 10
If
M$ = M$ (1) Then
FL
= 1
Exit
For
End
If
Next
If
FL = 0 Then
?
“Not Found”
Else
?
“Found”
End
If
END
Ë WAP to Enter ten number in an array. Print sum of
the alternate number.
DIM
N (10)
For
I = 1 to 10
Input
“Enter number”, N (1)
Next
For
I = 1 to 10 Step 2
S
= S+N (1)
Next
? S
End
Ë Write a program to enter name and address for 10
people. Enter name and print the corresponding address.
DIM
N$ (10), M$ (10)
For
I = 1 to 10
Input
“Enter name”, N$ (I)
Input
“Enter address”, N$ (I)
Next
Input
“Enter name”, P$
For
J = 1 to 10
If
P$ = N$ (J) Then
Fl
= 1
Exit
for
End
If
Next
If
Fl = 1 Then
?
M$(J)
Else
End
IF
End
Ë Enter 10 numbers and print the maximum number.
Input
“Enter a number”, N
For
I = 1 to 9
Input
“Enter number “,
If
N > Max Then
End
If
Next
? Max
END
Ë WAP to enter 10 marks and 10 names. Print the
highest Marks and names.
DIM
N$(10), N(10)
Input
“Enter a number”, N
For
I = 1 to 10
Input
“Enter the name”, N$(I)
Input
“Enter the marks”, N$ (I)
IF
N (I) > Max
Then
P$
= N$ (I)
EndIf
Next
? P$, Max
END
SORTING
Bubble Sort
Advance Sort
Ë WAP to enter 5 numbers.
Print the number in ascending order.
DIM N (S)
For I = 1 to 5
Input “Enter
numbers”, N(I)
Next
For I = 1 to
4
For
J = 1 to 5 –I
If
N (J) > N(J+1) Then
Swap N (J), N(J+1)
End
If
Next
Next
For I = 1 to 5
? N(I)
Next
Next
End
Ë WAP to Enter 10 names.
Print the names in descending order.
DIM N$(10)
For I 1 to 10
Input “
Enter the names”, N$ (I)
Next
For I = 1 to
9
For
J = 1 to 10-I
If
N$(J) < N$ (J+1) Then
Swap N(J), N (J+1)
End
If
Next
J
Next I
For I = 1 to 10
? N$ (I)
Next I
End
Ë WAP to enter names and
marks in two – arrays, Sort display the names and marks in descending order of
marks.
DIM N$ (10), M(10)
For I = 1 to 10
Input “Enter
the names”, N$(1)
Input “Enter
the marks”, M$(I)
Next
For I = 1 to 9
FL = 0
For J = 1 to
10 – Z
IF
M(J) < M(J+1) Then
Swap M(J), M(J+1)
Swap# N$(J), N$(J+1)
End
If
Next J
If FL = 0
Then
Exit
for
End If
Next I
For I = 1 to 10
? N$ (I),
M(I)
Next I
End
BINARY SEARCH
Ë Write a program to enter 10 numbers in ascending order. Enter a number
to search. Print “Found” or “not found”.
DIM N(10)
For I = 1 to 10
Input “Enter
the number”, N(1)
Next I
Input “Enter
the number to search”, P
L = 1
H = 10
Do While L < = H
M
= (L+H)/2
If
N(M) = P Then
?
“Found”
End
Else
If P < N (M) Then
H
= M-1
Else
L
= M+1
End
If
? “Not
Found”
End
Ë WAP to enter names and two
marks in three arrays. Enter a name and print the total marks(in Binary
search).
CLD
DIM N$(10), M1(10),
M2(10)
For I = 1 to 10
Input “Enter
the name”, N$(I)
Input “Enter
1st marks”, M1(I)
Input “Enter
2nd marks”, M2(I)
Next I
For I = 1 to
9
Fl
= 0
For
J = 1 to 10 – I
If
N$ (J) > N$ (J+1) Then
Swap
N$(J), N$(J+1)
Swap
M1(J), M1(J+1)
Swap
M2(J), M2 (J+1)
Fl = 1
End If
If Fl = 0 Then
Exit For
End If
Next J
Next I
Input “Enter a name to search”, P$
L = 1
H = 10
Do While L
< = H
M = (L+H)/2
If P$ = N$ (M) Then
Tot = M1(M) + M2(M)
? N$ (M), Tot
Else If P$ > N$ (M) Then
L = N+1
Else
H = N-1
End If
?
“Not Found”
End
Data File à j Sequential file
k Random File
Sequential
File which will be access Random File can be record randomly.
Sequential File Random
File
j Sequential file variable j Random file fixed length
file
Length file
k Sequential files updation k Random file updation is
easern
is very difficult.
SEQUENTIAL
FILE
Mode “ I ” à Input.
“O”
à Output.
“A”
à Append.
ô CLS
Open “o”. #1, “C:\Student\Jay\ab.dat”
For I = 1 to 10
Input “Enter
the name”, N$
Input “Enter
two marks”, M1, M2
Next
Close #1
End
Ë WAP to read the above file.
Open “I”, #1,
“C:\Student\Jay\ab.dat”
For I = 1 to 10 or Do
While Not EOF(1)
Input #1,
N$, M1, M2
?
N$, M1, M2
Next or Loop
Close #1
Ë Sequential file called
EMP.DAT Contains Employee Code, Name and basic pay. WAP to create a new file
called NEW.DAT with those salary is greater than Rs. 5000.
Open “I” #1, “EMP.DAT”
Open “o” #2, “NEW.DAT”
Do While Not EOF(1)
Input #1,
C$, N$, BP
If
BP > 5000 Then
Write
#2. C$, N$, BP
End
If
Close #1, #2
Add
Three more record to the employee files.
Open “A”, #1 , “EMP.DAT”
For I = 1 to 3
Input #1,
C$, N$, BP
Write #1,
C$, N$, BP
Next I
Close #1
Ë WAP to enter a name to
search display. The Full employee record from the EMP.file
Open “I”, #1 , “ EMP.DAT
Input “ Enter a name to search ”, P$
DO WHILE NOT EOF ( I)
Input
#1 ,C$,N$,BP
If
P$ = N$,.BP Then
Print C$ , M$ , Bp
FL = I
END
END IF
IF FL = 0 THEN
PRINT
: NOT FOUND
CLOSE
# 1
Ë Wap to delete the third
record from the employee file.
Open “I” #1, “EMP.DAT”
Open “o” #2, “EMP.DAT”
Do While Not EOF (1)
Input #1,
C$, N$. BP
C
= C+1
If C
<> 3 Then
Write
# 2 , C$ , N$, BP
End If
Close
Kill “EMP.DAT”
NAME “TEMP.DAT” As “EMP.DAT”
Ë Give an increment of 1000
Rs. of all employee.
Open “I” , #1, “Emp.Dat”
Open “o”, #2 , “ Temp.DAT”
Do While Not EOF (1)
Input #1, C$
, N$, BP
Write #2,
C$, N$, (Bp+1000)
Close
Kill “EMP.DAT”
Name “TEMP.DAT” As “EMP.DAT”
Ë WAP to display the fifth
record from a file named library.dat
Book
Author
Subject
Number of copies
Open “I”. #1. “LIBRARY.DAT”
Do While Not EOF (1)
Input #1,
B$, A$, S$,N
C
= C+1
If C=5 Then
Print B$, A$, S$, NC
End
End If
Close #1
LOCATE
Ë WAP to print your name on
the monitor in right must button corner.
Locate 24, 75
? “KISHOR”
Beep
End
Ë WAP to print your name in
middle of the screen.
Locate 12, 38
? “ Kishor”
Play “ABCDEFG”
End