A student file contain the marks of students scored in various subjects in a class. Each record contain Register Number, Name of Student and Marks scored for Subject1, Subject2 and Subject3(maximum marks 100). Write a COBOL program to prepare a Rank List.


      *
      *   A student file contain the marks of students scored
      *   in various subjects in a class. Each record contain
      *   Register Number, Name of Student and Marks scored for
      *   Subject1, Subject2 and Subject3(maximum marks 100).
      *
      *   Write a COBOL program to prepare a Rank List.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RANKING.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STU-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT TOT-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT WORK-FILE ASSIGN TO DISK.
           SELECT RANK-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STU-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "MARK.DAT"
           DATA RECORD IS STU-REC.
       01  STU-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
       FD  TOT-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "TOTAL.DAT"
           DATA RECORD IS TOT-REC.
       01  TOT-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       SD  WORK-FILE
           DATA RECORD IS WORK-REC.
       01  WORK-REC.
           02 REGNO PIC 9(3).
           02 NAME  PIC X(20).
           02 M1    PIC 9(3).
           02 M2    PIC 9(3).
           02 M3    PIC 9(3).
           02 TOTAL PIC 9(3).
       FD  RANK-FILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "RANK.DAT"
           DATA RECORD IS RANK-REC.
       01  RANK-REC.
           02 REGNO   PIC 9(3).
           02 NAME    PIC X(20).
           02 M1      PIC 9(3).
           02 M2      PIC 9(3).
           02 M3      PIC 9(3).
           02 TOTAL   PIC 9(3).
           02 RANK    PIC 9(3).
       WORKING-STORAGE SECTION.
       01  PRE-TOTAL  PIC 9(3) VALUE 0.
       01  T-RANK     PIC 9(3) VALUE 0.
       01  SHOW-REC.
           02 REGNO   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 NAME    PIC X(20).
           02 FILLER  PIC X(2).
           02 M1      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M2      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 M3      PIC ZZ9.
           02 FILLER  PIC X(2).
           02 TOTAL   PIC ZZ9.
           02 FILLER  PIC X(2).
           02 RANK    PIC ZZ9.
       PROCEDURE DIVISION.
       TOT-PARA.
           OPEN INPUT STU-FILE
                OUTPUT TOT-FILE.
       READMARK-PARA.
           READ STU-FILE RECORD INTO TOT-REC
                AT END GO TO CLOSE-STU-PARA.
           COMPUTE TOTAL OF TOT-REC = M1 OF TOT-REC +
                                      M2 OF TOT-REC +
                                      M3 OF TOT-REC.
           WRITE TOT-REC.
           GO TO READMARK-PARA.
       CLOSE-STU-PARA.
           CLOSE STU-FILE TOT-FILE.
       SORT-PARA.
           SORT WORK-FILE ON DESCENDING KEY TOTAL OF WORK-REC
           USING TOT-FILE
           GIVING RANK-FILE.
       OPEN-PARA.
           OPEN I-O RANK-FILE.
       READ-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-PARA.
           IF PRE-TOTAL NOT = TOTAL OF RANK-REC
              COMPUTE T-RANK = T-RANK + 1
              MOVE TOTAL OF RANK-REC TO PRE-TOTAL.
           MOVE T-RANK TO RANK OF RANK-REC.
           REWRITE RANK-REC.
           GO TO READ-PARA.
       CLOSE-PARA.
           CLOSE RANK-FILE.
           OPEN INPUT RANK-FILE.
           DISPLAY "--------------------------------------------------".
           DISPLAY "                   RANK LIST".
           DISPLAY "--------------------------------------------------".
           DISPLAY "REG  NAME                   M1   M2   M3  TOT RANK".
           DISPLAY "==================================================".
       READRANK-PARA.
           READ RANK-FILE RECORD AT END GO TO CLOSE-RANK-PARA.
           MOVE CORRESPONDING RANK-REC TO SHOW-REC.
           DISPLAY SHOW-REC.
           GO TO READRANK-PARA.
       CLOSE-RANK-PARA.
           CLOSE RANK-FILE.
           DISPLAY "==================================================".
           DISPLAY " ".
           STOP RUN.

No comments:

Post a comment