Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to perform binary search on student name and print roll number

Posted By: Adalicia Fischer     Category: Cobol     Views: 5508

PROGRAM WHICH PERFORM THE BINARY SEARCH THE NAME FROM THE FILE AND DISPLAY THE CORRESPONDING ROLL NO OF THE STUDENT.

Code for Program to perform binary search on student name and print roll number in Cobol

       IDENTIFICATION DIVISION.
        PROGRAM-ID.binary-search1.

       ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
         FILE-CONTROL.
          SELECT infile1 ASSIGN TO DISK
          ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.
        FILE SECTION.
         FD infile1
           VALUE OF FILE-ID IS "search.txt".
          01 in-rec.
            05 ino PIC 99.
            05 iname PIC X(10).

        WORKING-STORAGE SECTION.
          01 tbl.
           05 stu-tbl OCCURS 10 TIMES ASCENDING no1 INDEXED BY idx1.
            10 no1 PIC 99.
            10 name1 PIC X(10).
          01 i PIC 99.
          01 eof PIC X VALUE 'N'.
          01 sno PIC 99.

       PROCEDURE DIVISION.
        PARA1.
            OPEN INPUT infile1.
             READ infile1
              AT END MOVE 'Y' TO eof.
             PERFORM VARYING i FROM 1 BY 1 UNTIL eof='Y'
                MOVE ino TO no1(i)
                MOVE iname TO name1(i)
                READ infile1
                 AT END MOVE 'Y' TO eof
                END-READ
             END-PERFORM.
            CLOSE INFILE1.

            DISPLAY "ENTER THE ROLL NO YOU WANT TO SEARCH".
            ACCEPT sno.

            SET idx1 TO 1.
            SEARCH ALL stu-tbl
             AT END DISPLAY "STUDENT ROLL NO NOT FOUND"
             WHEN sno=no1(idx1)
               DISPLAY "THE ROLL NO IS " sno " OF " name1(idx1)
            END-SEARCH.
            STOP RUN.


*********************INPUT FILE*****************************
******SEARCH.TXT
******01JOLLY
******02HIMANI
******03ISHA
******04MANALI
******05JANKI
******06HITISHA
******07SARITA
******08KINJAL
******09KHUSHBU
******10JOLLY

*********************OUTPUT*********************************
******ENTER THE ROLL NO YOU WANT TO SEARCH
******01
******THE ROLL NO IS 01 OF JOLLY

******ENTER THE ROLL NO YOU WANT TO SEARCH
******11
******STUDENT ROLL NO NOT FOUND
  
Share: 



Adalicia Fischer
Adalicia Fischer author of Program to perform binary search on student name and print roll number is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!