Lab1 Part B Program and HW

 

Directions

Type the program, lab1.cob, into emacs exactly as you see it here – horizontal and vertical spacing included; be sure to put the statements in the correct columns.

Type the input file data, lab1in.dat, into emacs exactly as you see it below; check the record layout under employee-record to make sure the data is in the correct columns.

Compiling and running lab1.cob should generate the output data lab1out.dat.

 

lab1.cob

 

       identification division.

       program-idprelab.

  

       environment division.

       input-output section.

       file-control.

           select employee-data assign to "lab1in.dat"

               organization is line sequential.

           select payroll-listing assign to "lab1out.dat"

               organization is line sequential.

              

       data division.

      *

       file section.

       fd  employee-data.

       01  employee-record.

           05  employee-name-in    pic x(20).

           05  hours-worked-in     pic 9(2).

           05  hourly-rate-in      pic 9v99.

       fd  payroll-listing.

       01  print-rec.

           05  name-out            pic x(20).

           05                      pic x(8).

           05  hours-out           pic 9(2).

           05                      pic x(6).

           05  rate-out            pic 9.99.

           05                      pic x(6).

           05  weekly-wages-out    pic 999.99.

      *

       working-storage section.

       77  are-there-more-records  pic xxx value "yes".

       01  page-header.

           05 pic x(17) value spaces.

           05 pic x(19) value "Weekly Wages Sample".

           05 pic x(16) value spaces.

       01  column-headers.

           05 pic x(23) value "Employee Name".

           05 pic x(12) value "Hours Worked".

           05 pic x(1) value spaces.

           05 pic x(6) value "$/hr".

           05 pic x(10) value "  Earnings".

       01  under-line pic x(54) value all "_".

     

       procedure division.

       100-main-module.

           open input employee-data

                output payroll-listing.

           write print-rec from page-header

               before advancing 0 lines.

           write print-rec from column-headers

               after advancing 2 line.

           write print-rec from under-line

               after advancing 1 lines.

           read employee-data

               at end move "no" to are-there-more-records.

           perform 200-wage-routine

               until are-there-more-records = "no".

           close employee-data payroll-listing.

      *    accept omitted.

           stop run.

 

       200-wage-routine.

           move spaces to print-rec

           move employee-name-in to name-out

           move hours-worked-in to hours-out

           move hourly-rate-in to rate-out

           multiply hours-worked-in by hourly-rate-in

               giving weekly-wages-out

           write print-rec

           read employee-data

                   at end move "no" to are-there-more-records.

        

 

 

lab1in.dat

 

 

robert frost        45500

william shakespeare 50550

john dunne          35425

jane austin         55600

mark twain          30450

 

 

 

 

lab1out.dat as generated by lab1.cob

 

 

                  Weekly Wages Sample

 

Employee Name          Hours Worked $/hr    Earnings

____________________________________________________

robert frost                45      5.00      225.00

william shakespeare         50      5.50      275.00

john dunne                  35      4.25      148.75

jane austin                 55      6.00      330.00

mark twain                  30      4.50      135.00

 

 

 

Lab1 Part B HW

 

Be sure that your program, lab1.cob, compiles and runs correctly before answering the following questions.

Be sure to delete the changes made before going on to the next question.

When making a change to the program, be sure to save before re-compiling the program to check the results of the change.

If you make a change and no compiler error occurs, be sure to run the program to check for run errors, then check the output for logic errors.

It would be helpful to set the column and line numbers for your lab1.cob file (see the tutorial for more information).

 

What happens if you:

capitalize IDENTIFICATION DIVISION?

delete the period after identification division?

put an * in column 7 on the first statement (identification division)?

change the program-id from prelab to sample? 

put the program-id name, prelab. (don’t forget to include the period) on the next line starting in column 10? 

put the program-id name, prelab. (don’t forget to include the period) on the next line starting in column 12? 

move data division to start in column 11? 

move data division to start in column 12? 

delete the period on the line before the data division i.e. after the second organization is line sequential? 

comment out the 3 statements environment division, input-output section and file-control by putting an * in column 7 of each statement? 

comment out the file section statement? 

NOTE:  Delete the * on the accept omitted statement (before the stop run statement) for the next question only.

in the file section, change the pic x(20) on 05 employee-name-in to pic x(18)?

change the 77 level number in the working-storage section to an 01 level number? 

change the non-numeric literal on the value clause for the are-there-more-records variable to “no”?

in the file section, put a $ in front of the 9.99 on the pic clause for rate-out (i.e. pic $9.99)? 

delete the period on the weekly-wages-out pic clause (i.e. pic 99999 instead of 999.99)? 

delete the period before the working-storage section statement? 

in the file section, change the variable name hours-worked-in to hrs-wrk-in? 

in the file section, change the variable name weekly-wages-out to wkly-wgs-out?

change the variable name employee-data on the read statement to employee-record?

change the variable name hours-out in 200-wage-routine paragraph to hrs-out?

change 05 levels on employee-record in the file section to 01 levels?

change the double quotes to single quotes on the select statement?

change the double quotes to single quotes for all the “no” non-numeric literals?

change “no” to “NO” on the perform statement (in paragraph 100-main-module)?

comment out the 100-main-module paragraph name?

comment out the 1st line in the 100-main-module paragraph (open input employee-data)?

delete all the periods under the 100-main-module paragraph?

delete all the periods under the 100-main-module paragraph except on the stop run statement?

correct the change you made to the above question and forget to save before recompiling?

change the line before the read statement to after advancing 0 lines (instead of 1 lines)?

change the line before the read statement to after advancing 1 line (deleting the s off the word lines)?

comment out the close statement?

put employee-data on the close statement on a different line, starting column 12 or after?

comment out the stop run statement?

 

Other:

Notice that the 3rd line and the 11th line are blank; there is no * in the 7th column to denote a comment.  Why is this okay?!

Notice that the non-numeric literal “Employee Name” has a length of 13, but the pic clause has a length of 23.  Why is this okay?

Notice that there are no variable names on the 05 levels under both page-header and column-headers.  Why is this okay?

List the first 20 statements executed by the program.

Delete the * on the accept omitted statement.  Add the following display statement after both the read statements (delete the period after the second read statement and put on display statement):

            display “employee-record is “ employee-record.