Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to Create result statement for a given semester

Posted By: Reuben Brown     Category: Cobol     Views: 4020

Write a Program to Create result statement for a given semester.

Code for Program to Create result statement for a given semester in Cobol

environment division.
 input-output section.
  file-control.
    select student-file assign to 'student.dat'.
    select subject-file assign to 'subject.mst'.
    select result-file assign to 'result.rpt'.
    select sort-file assign to disk.

data division.
 file section.
  fd student-file.
   01 stud-rec.
      05 sem-no     pic 9.
      05 stud-no     pic 999.
      05 name         pic x(40).
      05 result-tbl occurs 6 times.
         10 subj-no     pic 9.
         10 marks     pic 999.
  fd subject-file.
   01 subj-rec.
      05 sem-no     pic 9.
      05 subj-no     pic 9.
         88 valid-subject value 1 thru 6.
      05 subj-name     pic x(40).
  fd result-file.
   01 result-rec    pic x(80).

  sd sort-file.
   01 sort-rec.
      05 s-sem-no     pic 9.
      05 s-stud-no     pic 999.
      05         pic x(64).

 working-storage section.
   01 eof         pic x value'n'.
*   01 i            usage index.
   01 i            pic 9.
   01 subj-tbl value spaces.
    05 subject-name occurs 6 times pic x(40).
   01 line-cnt        pic 99 value 80.
   01 max-lines        pic 99 value 55.
**************************************************************************
*         1         2         3         4         5         6         7
*123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789

*MCA Semester 9                Result statement                Date:99/99/9999
*                                                              Page:99
*
*No. Name                               <--Marks in Subjects--> Total    %  Clas
s
*                                        1   2   3   4   5   6  Marks 
*
*999 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 999 999 999 999 999 999  999 999.99 XXXXX
X
*123 123456789012345678901234567890123 123 123 123 123 123 123  123 123456 12345
6
*
* Actually 40 characters in name. But as shown below, it will exceed 80 col.
* So, here it prints only 33 characters.
* In real life, one should print all 40 characters
*999 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 999 999 999 999 999 999 999 99.99 
XXXXXX
****************************************************************************

   01 header-line-1.
      05         pic x(13) value"MCA Semester".
      05 h1-sem-no    pic 9.
      05                pic x(17) value spaces.
      05         pic x(31) value"Result Statement".
      05         pic x(5)  value"Date:".
      05 h1-dd        pic 99.
      05        pic x value'/'.
      05 h1-mm        pic 99.
      05        pic x value'/'.
      05 h1-yy        pic 99.

   01 header-line-2.
      05        pic x(62) value spaces.
      05        pic x(5) value"Page:".
      05 h2-page-no    pic 99.

   01 col-title-1.
      05         pic x(04) value"No.".
      05         pic x(34) value"Name".
      05         pic x(42) 
                       value"<--Marks in Subjects--> Total     %  Class".
* On VAX terminal format, margin B may go beyond 72

   01 col-title-2.
      05         pic x(38) value spaces.
      05         pic x(42) value"  1   2   3   4   5   6  Marks ".
   01 detail-line.
      05 dtl-no        pic 9(3).
      05         pic x.
      05 dtl-name    pic x(33).
      05 dtl-marks-tbl occurs 6 times.
         10        pic x.
         10 dtl-marks    pic 999.
      05        pic xx.
      05 dtl-tot-marks  pic 999.
      05         pic x.
      05 dtl-prcnt    pic 999.99.
      05         pic x.
      05 dtl-result    pic x(6).

   01 dash-line        pic x(80) value all "=".
   01 blnk-line        pic x(80) value all spaces.
   
   01 stud-tot-marks    pic 999.
   01 t-subj-no        pic 9.
   01 t-marks        pic 999.
   01 tot-student    pic 999   value zero.
   
   01 prcnt        pic 999v99.
      88 fail   values  0 thru 49.99.
      88 second values 50 thru 59.99.
      88 first1 values 60 thru 69.99.
      88 dist   values 70 thru 100.
   01 t-result        pic x(6).

   01 tot-failed    pic 999.
   01 tot-dist        pic 999.
   01 tot-first    pic 999.
   01 tot-second    pic 999.
   01 tot-pass        pic 999.

   01 avg-tbl value zeros.
      05 avg-marks    occurs 6 times pic 999v99.

   01 smry-avg-header-1    pic x(80)
           value"Subject  Subject                                    Average".
   01 smry-avg-header-1    pic x(80)
           value"    No.  Name                                       Marks".

*   1     1234567890123456789012345678901234567890   123456
*zzz9     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX   999.99
*Subject  Subject                                    Average
*    No.  Name                                       Marks

   01 smry-line.
      05 smry-subj-no    pic 9.
      05        pic x(3) value spaces.
      05 smry-subj-name pic x(40).
      05        pic x(3) value spaces.
      05 smry-avg-marks   pic 999.99.

   01 smry-line2.
      05                pic x(4).
      05 smry-msg    pic x(40).
      05 smry-tot    pic 999.
      


**************************

procedure division.
  main.
        perform a10-store-subjects.
        perform b10-init-result-processs.
        perform c10-prepare-result.
        perform d10-prn-summary.
        perform e10-close.
        stop run.

  a10-store-subjects.
        display "Enter Semester No." with no.
    accept h1-sem-no.
        open input subject-file.
        perform a20-init-subj-names.
        perform a30-read-store.
    
  a20-init-subj-names.
        perform varying i from 1 by 1 until i > 6
            move spaces to subject-name(i)
        end-perform.

  a30-read-store.
************************
* sorted subject file may reduce time, 
*   but here very few records will be there,
*      and initial records may still be required to read and skip (ex.for sem 5)

*      so no need to spend time in sorting
************************
        perform until eof='y'
          move spaces to subj-rec
      read subject-file 
          at end move 'y' to eof
             not at end perform a40-store-subj-name
          end-read  
        end-perform.
        close subject-file.

  a40-store-subj-name.
        if sem-no of subj-rec is equal to h1-sem-no
           if valid-subject
              move subj-name to subject-name(subj-no of subj-rec)
           else
              display "Invalid subject code, out of range (1,6)"
           end-if
        end-if.

  b10-init-result-processs.
      perform b20-sort-student.
    perform b30-open-files.
    perform b40-get-first-student.

  b20-sort-student.
    sort sort-file 
       on ascending key s-sem-no s-stud-no
       using student-file giving student-file.

  b30-open-files.
      open input  student-file
             output result-file. 
    
  b40-get-first-student.
*  read student file till getting first student record of given sem.
    move 'n' to eof.
        move zero to sem-no of stud-rec.
    perform until eof = 'y' or sem-no of stud-rec = h1-sem-no
       read student-file
              at end move 'y' to eof
       end-read
    end-perform.

  c10-prepare-result.
    if eof='y'
       display "No student records to process"else
       perform c20-process-students
        end-if.
     
  c20-process-students.
    perform until eof = 'y' or sem-no of stud-rec not = h1-sem-no
       add 1 to tot-student
       perform c30-get-result
       perform c40-prn-detail-line
       read student-file 
              at end move 'y' to eof
* if c30-c04 are used with: not at end, will process one more rec.
           end-read
        end-perform. 

  c30-get-result.
        move spaces to detail-line.
        move zeros to stud-tot-marks.
        move spaces to t-result

    perform varying i from 1 by 1 until i > 6
*       move subj-no(i) of stud-rec to t-subj-no   *** invalid
       move subj-no of stud-rec(i) to t-subj-no
       move marks(i) to t-marks, dtl-marks(t-subj-no)
* marks may be 'A00'if t-marks is numeric
                add t-marks to stud-tot-marks
        add t-marks to avg-marks(t-subj-no)
        if t-marks < 40
            move "fail" to t-result
        end-ifelse 
         move "fail" to t-result
           end-if
    end-perform.

        divide stud-tot-marks by 6 giving prcnt.

*       fail may be due to < 40 or A00, In evaluate, may change if % > 50
        if t-result not = "fail"
*        evaluate prcnt   -- invalid, with condition name
          evaluate true
          when  fail
          move "fail" to t-result
        when  second
          move "second" to t-result
          add 1 to tot-second
        when  first1
          move "first" to t-result
          add 1 to tot-first
        when  dist
          move "dist" to t-result
          add 1 to tot-dist
          end-evaluate
        end-if.
        if t-result = "fail" add 1 to tot-failed.        
    
  c40-prn-detail-line.
    perform c50-move-detail-line.
    add 1 to line-cnt.
    if line-cnt > max-lines
       perform c60-prn-header.
    write result-rec from detail-line.
    move spaces to detail-line.

  c50-move-detail-line.
    move stud-no of stud-rec to dtl-no.
    move name to dtl-name.
*    marks already moved during get-result
    move stud-tot-marks to dtl-tot-marks.
    move prcnt to dtl-prcnt.
    move t-result to dtl-result.

  c60-prn-header.
    write result-rec from header-line-1 after advancing page.
    add 1 to h2-page-no.
    write result-rec from header-line-2.
    write result-rec from col-title-1 after 2 lines.
    write result-rec from col-title-2.
    write result-rec from dash-line.
    move 7 to line-cnt.

  d10-prn-summary.
        write result-rec from dash-line.
        move "Summary..." to result-rec.
    write result-rec after 2.
        move "Average marks in different Subjects..." to result-rec.
    write result-rec after 2.
    write result-rec from blnk-line.
    
    move spaces to smry-line.
    perform varying i from 1 by 1 until i > 6
      divide avg-marks(i) by tot-student giving smry-avg-marks
      move i to smry-subj-no
          move subject-name(i) to smry-subj-name
          write result-rec from smry-line
    end-perform.
        write result-rec from dash-line.

    move spaces to smry-line2.
        move "No. of students failed" to smry-msg.
     move tot-failed to smry-tot.
     write result-rec from smry-line2 after 2.
        move "No. of students having second class" to smry-msg.
     move tot-second to smry-tot.
     write result-rec from smry-line2.
        move "No. of students having first class" to smry-msg.
     move tot-first to smry-tot.
     write result-rec from smry-line2.
        move "No. of students having distinction" to smry-msg.
     move tot-dist to smry-tot.
     write result-rec from smry-line2.
     
  e10-close.
      close student-file
            result-file.     
     
  
Share: 


Didn't find what you were looking for? Find more on Program to Create result statement for a given semester Or get search suggestion and latest updates.

Reuben Brown
Reuben Brown author of Program to Create result statement for a given semester is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
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!