PROGRAM WHICH PERFORM THE BINARY SEARCH THE NAME FROM THE FILE AND DISPLAY THE CORRESPONDING ROLL NO OF THE STUDENT.
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