C & Q Basic, Computer, supported by Podmeswar


QUICK-BASIC

BASIC

G BASIC à Interpreter

Q BASIC à      

Q/B          à    Compiler



DATA TYPE

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.

            CLS
                        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.

            CLS
                        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.
            CLS
                        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.

            CLS
                        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
            NET-PAY = BASIC + DA + HRA – TAX
at the end of the program print the name and the Net-pay.

            CLS
                        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

Flow chat helping in write a program.
 

                        à Start / Stop                                      à DESICCON BOX

 

                        à Input / Output
                                                                                     à 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 “Enter the name”, N$
            INPUT N$                                                       INPUT “Enter the age”, age
                AGE                                                          IF          
                                                                                     Age<18 Then
            Age             ? N$ you                                                   ? N$, “You can vote”
            <18      à    can vote     à Stop                                  Else
â                                                                                 ? N$, “You can’t vote”  
? N$ you                                                                      END IF                                   
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.
             â
AVM=(M1+M2)/2
                 â
                 IF
          AVM<40     à     ?  N$,”Fail”  à  Stop

                 â
         ? N$, “Pass”                              CLS
                 â                                             INPUT “Enter the name”’ N$
              Stop                                             INPUT “Enter the marks”, M1,M2
                                                                  AVM = (M1+M2)/2
                                                                      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


CLS
                 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.


CLS                                                                                 Start
Input “Enter a name”, N$                                                    ê
Input “Enter the age”, Age                                          Input N$ Age
     If age<5then                                                                   ê    
     ? “You are child”                                                             If     y  
Else If Age<13 Then                                                         Age<5  à   ? “You are a child”                                                                                                          N
    ? “You are a Young”                                                        ê
Else IF Age <=19 Then                                                        IF     Y
? “You are a teenager”                                          Age<13à ? “You are a Young
Else Age >19 then                                                              
                                                                                            ê       N
? “You are an Adult”                                                             IF    Y
End IF                                                                              Age<=19 à?“You are a Teenager”
End                                                                                      
                                                                                            ê   N
                                                                                    ?  “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
ê


IF
U<=100    à   BA = (U*80)/100

ê


IF
U<=200     à   BA = (100*80)/100 + (U-100) * 1.00

ê


IF
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


CLS
                 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

LOOP

Loop is a Set of  Statement which is repeatedly executed a number.
                                   
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.

            CLS
                        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

            CLS
                        FOR  I = 1 to 100
            ? I
            NEXT
            END



Ë Write a program to enter a name and print the name 10 times.

            CLS
                        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.

            CLS
                        For I = 1 to 100 Step -2
                        ? I
                        NEXT
            END

Ë Write a Program to print the sum of the first 10 even numbers.

            CLS
                        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.

            CLS
                        Input “ Enter the number of student “, S
                        For I = 1 to S
                        Input “ Enter two marks”, m1 , m2
                        AVM = (m1 + m2) / 2
            IF  AVM >= 40 THEN
                        PASS = PASS + 1
            ELSE
                        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.

            CLS
                        Input “ Enter the number of student “, S
                        For I = 1 to S
                        Input “ Enter total marks”, To
                        TM = TM + To
            NEXT
                        AVM = TM/s
                        ? AVM
            END

Ë WAP to enter names each times print the name. The programs Stop When the name zzz is enter.

            CLS
                        Input “ Enter the name”, N$
            DO WHILE  N$ <> “zzz”
                        ? N$
                        Input N$
            LOOP
            END

Ë Write a program to enter 10 numbers. Print the product of all numbers.

            CLS
                        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.

            CLS
                        Input “ Enter the number “, N
            DO WHILE  N <>0
                        SUM  =  SUM + N
                        Input “Enter the number “, N
            LOOP
            ? 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.
           
            CLS
                        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.

            CLS
                        For I = 1 to 10
                        Input  “ Enter the run score by a player “, R
                        Tot = Tot + R
            NEXT
                        AVR = Tot / 11
                        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.

CLS
                        Input “Enter a number”, N
                        DO WHILE     N <> 0
                                    N = Int (N/10)
                                    ND = ND + 1

                        LOOP
                                    ? ND
END
NB à The mod operator return the remainder of division


Ë Write a program to enter a number and print the last digit.

            CLS
                        Input “ Enter a number”, N
                                    LD = N mod 10
                                    ? LD
                        END

Ë Write a program to enter a number print the sum of all Digit.

            CLS
                        Input “ Enter the number”, N
                        DO WHILE  N <> 0
                                    LD = N Mod 10
                                       S = S + LD
                                       N = Int (N/10)
                        LOOP
                                    ? S
            END

Ë Write a program to enter a number print if even or odd.
                       
            CLS
                        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.

            CLS
                        Input “Enter a Number “, N
                        Do While  N <> 0
                                          N = Int (N/10)
                                       ND = ND + 1
                        LOOP
            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.

            CLS
                        Input “Enter the number “, N
                                    T = N
                        Do While  N <> 10
                                          N = N Mod 10
                                        ND = ND +1
                        Loop
                                    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.)

            CLS
                        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)
                        LOOP
                                    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.

            CLS
                        Input “Enter a number”, N
                        T = N
                        Do While  N <> 0
                                    N = N\10
                                    Nd = Nd + 1
                        LOOP
                        N = T
                                    Nd = Nd Mod 2
                        If nd = 0 then
                                    Do While  N <> 0
                                                Ld = N mod 10
                                    Sum = Sum + ld
                                                N = N\10
                                    Loop
                        ? “Sum of even digit”, Sum
                        Else
                        ? “Odd digit”
                        End If
            END

Ë Print the Armstrong number from 1 to 1000.
           
            CLS
                        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
                        Loop
                           If I = Sum then
                                    ? I
                        End If
                        Next
            End

Ë Write a program to enter a number. If prime or Composit.

            CLS
                        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
           
            CLS
                        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


                                    LEN ( )
                                    RIGHT $ ( )
                                    LEFT $ ( )
                                    MID $ ( )

Ë WAP to enter a string print the number of character.

            CLS
                        Input “Enter a String ”, N$
                                    X = LEN (N$)
                                    ? X
            END

Ë Write a program to get output as follows :-
           
                        H
                        HE
                        HEL
                        HELL
                        HELLO

            CLS
                        N$ = HELLO
                        For I = 1 to 5
                        X$ = Left $ (N$,I)
                        ? X$
                        Next
            END

Ë WAP to enter a string print all the character.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.
           
            CLS
                        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.

            CLS
                        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

            CLS
                        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).

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.
           
            CLS
                        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.

            CLS
                        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.

            CLS
                        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”.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

            CLS
                        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.

CLS
            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.

            CLS
                        DIM N$ (10)
                        FOR I = 1 to 10
                                    Read N$ ( I )
                        Next
                        DATA “one”, “two”, “three”, ……………….. “ten”
                        Input “Enter a number”, X
                           ? N$ (X)
            END


Ë WAP to enter number 1 to 99 print in words

CLS
            DIM N$ (19), N$ (8)
            For I = 1 to 19
                  Read N$ (1)
            Next

DATA “one”, “two”, “three”, ………………………. “nineteen”
            For J = 1 to 8
                   Read N$ (J)
            Next
            DATA “Twenty”, “Thirty”, ……………………. “Ninety”
            Input “Enter a number”, N
                        If N > 99 Then
                             ? “Can’t Display”
                                    ElseIf N < 19 Then
                             ? 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”

            CLS
                        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)
            CLS
                        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.

CLS
                        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.

            CLS
                        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.

            CLS
                        Input “Enter a number”, N
                                    MAX = N
                        For I = 1 to 9
                                    Input “Enter number “,
                                    If N > Max Then
                                                Max = N
                                    End If
                        Next
                            ? Max
            END

Ë WAP to enter 10 marks and 10 names. Print the highest Marks and names.

            CLS
                        DIM N$(10), N(10)    
                        Input “Enter a number”, N
                                    Max = N
                        For I  = 1 to 10
                                    Input “Enter the name”, N$(I)
                                    Input “Enter the marks”, N$ (I)
                                                IF N (I) > Max Then
                                                            Max = M(I)
                                                            P$ = N$ (I)
                                                EndIf
                        Next
                          ? P$, Max
            END

SORTING


Bubble Sort
Advance Sort

Ë WAP to enter 5 numbers. Print the number in ascending order.
            CLS
                        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
            End

Ë WAP to Enter 10 names. Print the names in descending order.

            CLS
                        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.

            CLS
                        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”.

            CLS
                        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
                        Loop
                                    ? “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
                        Loop
                           ? “Not Found”
            End


FILE HANDLING

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
                        Loop
            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
LOOP
            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
                        Loop
            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)
                        Loop
            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

CLS
            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
                        Loop
            Close #1


LOCATE

Ë WAP to print your name on the monitor in right must button corner.

            CLS
                        Locate 24, 75
                        ? “KISHOR”
                        Beep
            End
Ë WAP to print your name in middle of the screen.

CLS
                        Locate 12, 38
                        ? “ Kishor”
                        Play “ABCDEFG”
            End