identification division.

       program-id. movie-practice.

 

       environment division.

       input-output section.

       file-control.

           select movie-data assign to "movieinlab4.dat"

               organization is line sequential.

           select movie-listing assign to "movieout.dat"

               organization is line sequential.

             

       data division.

      *

       file section.

       fd  movie-data.

       01  movie-record.

           05 movie-theatre-loc       pic x(17).

           05 movie-title-in          pic x(18).

           05 prod-company-in         pic x(12).

           05 movie-rating-in         pic x(5).

           05 date-rel-in             pic 9(8).

           05 box-office-ratings.

               10 box-wk-one-in       pic 99.

               10 box-wk-two-in       pic 99.

               10 box-wk-three-in     pic 99.

               10 box-wk-four-in      pic 99.

           05 gross-earnings-in       pic 9(9)V99.

           05 ticket-cost             pic 99v99.

      * senior citizens receive a 10% ticket discount

      * children receive a 20% ticket discount

      * students receive a 15% ticket discount

      * matinees receive a 20% ticket discount

           05 ticket-reduction-options.

               10 senior-cit          pic x.

               10 child               pic x.

               10 matinee             pic x.

               10 student             pic x.

           05 number-of-reviews       pic 9.

              

       01 movie-reviewer-ratings      pic x(12).

          

       fd  movie-listing.

       01  print-rec               pic x(135).

      *

       working-storage section.

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

       77  cbval-rating            pic x(5) value "nada".

       77  cbval-theatre           pic x(17) value spaces.

       77  movie-theatre           pic x(17) value spaces.

       77  movie-location          pic x(17) value spaces.

       77  num-cb-recs             pic 99 value 0.

       77  total-box               pic 9(5) value 0.

       77  total-rating-gross      pic 9(11)v99.

       77  total-num-movies        pic 99 value 0.

       77  temp-comments-out       pic x(40).

       77  new-number-of-reviews   pic 9.

      

01 current-date.

           05 cd-yy pic 99.

           05 cd-mm pic 99.

           05 cd-dd pic 99.

       01 current-time.

           05 ct-hh pic 99.

           05 ct-mm pic 99.

           05 ct-ss pic 99.

       01  page-header.

           05 page-header-date.

               10  ph-date-mm  pic 99.

               10              pic x value "/".

               10  ph-date-dd  pic 99.

               10              pic x value "/".

               10  ph-date-yy  pic 99.

           05                  pic x(18) value spaces.

           05 pic x(24) value "Mom and Dad's Movie List".

           05 pic x(18) value spaces.

           05 page-header-time.

               10 ph-time-hh   pic 99.

               10              pic x value ":".

               10 ph-time-mm   pic 99.

               10              pic x value ":".

               10 ph-time-ss   pic 99.

               10              pic x value space.

               10 ph-time-ampm pic xx.

       01  column-header1.

           05                     pic x(5) value spaces.

           05 pic x(19) value spaces.

           05 pic x(13) value "Production".

           05 pic x(11) value "Date".

           05 pic x(31) value "****** At the Box Office ******".

       01  column-header2.

           05                     pic x(5) value spaces.

           05 pic x(11) value "Movie Title".

           05 pic x(8) value spaces.

           05 pic x(7) value "Company".

           05 pic x(6) value spaces.

           05 pic x(8) value "Released".

           05 pic x(3) value spaces.

           05 pic x(16) value "Wk1 Wk2 Wk3 Wk4 ".

           05 pic x(14) value "Gross Earnings".

       01  under-line.

           05                     pic x(5) value spaces.

           05 pic x(11) value all "_".

           05 pic x(8) value spaces.

           05 pic x(7) value all "_".

           05 pic x(6) value spaces.

           05 pic x(8) value all "_".

           05 pic xxx value spaces.

           05 pic x(16) value "___ ___ ___ ___ ".

           05 pic x(14) value all "_".

 

       01  movie-theatre-label.

           05                      pic x(9) value "Theatre: ".

           05 movie-theatre-out    pic x(17).

 

       01  movie-location-label.

           05                      pic x(10) value "Location: ".

           05 movie-location-out   pic x(17).

          

       01  Rating-Label.

           05                      pic x(11) value "   Rating: ".

           05 movie-rating-out     pic x(5).

          

       01  Rating-Description.

           05                      pic x(16) value "   Description: ".

           05 rating-desc-out      pic x(77).

 

       01  Rating-Description-Messages.

           05 g-desc       pic x(8) value "everyone".

           05 pg-desc      pic x(27) value

                   "parental guidance suggested".

           05 pg13-desc    pic x(49) value

                   "parental guidance for children under 13 suggested".

           05 r-desc.       

               10 r-desc1       pic x(47) value

                   "restricted; children over 17 years of age only ".

               10 r-desc2       pic x(30) value

                   "unless accompanied by an adult".

          

       01  ws-print-rec.

           05                     pic x(5) value spaces.

           05 movie-title-out     pic x(18).

           05                     pic x value spaces.

           05 prod-company-out    pic x(12).

           05                     pic x value spaces.

           05 date-rel-out        pic xx/xx/xxxx.

      *        10 dr-mm-out        pic 99.

      *        10                  pic x value "/".

      *        10 dr-dd-out        pic 99.

      *        10                  pic x value "/".

      *        10 dr-yyyy-out      pic 9999.

           05                     pic x value space.

           05 box-wk-one-out      pic z9.

           05                     pic xx value space.

           05 box-wk-two-out      pic z9.

           05                     pic xx value space.

           05 box-wk-three-out    pic z9.

           05                     pic xx value space.

           05 box-wk-four-out     pic z9.

           05                     pic xx value space.

           05 gross-earnings-out  pic $$$$,$$$,$$9.99.

           05                     pic xx value space.

           05 comments-out        pic x(40).

 

       01 Average-Rating-Label.

           05 pic x(5) value spaces.

           05 pic x(16) value "Average Rating: ".

           05 average-cbnum-rating pic z9.99.

 

       01 Total-CB-Movies-Label.

           05 pic x(5) value spaces.

           05 pic x(24) value "Total Number of Movies: ".

           05  total-cbnum-movies pic z9.

 

       01  Total-Gross-Earnings-Label.

           05 pic x(5) value spaces.

           05 pic x(22) value "Total Gross Earnings: ".

           05 total-cbnum-earnings  pic $$$,$$$,$$$,$$9.99.

 

       01 Total-file-Movies-Label.

           05 pic x(24) value "Total Number of Movies: ".

           05  total-num-movies-out pic z9.

 

       01 High-avg-rate-label.

           05 pic x(48) value

               "Movie Category with the highest average rating: ".

           05 high-avg-rate-out    pic x(5).

          

       77 high-avg-value           pic 99v99 value 0.

       77 high-avg-rating            pic x(5) value "nada".

       77 avg-cbnum-rate           pic 99v99.

       77 prev-avg-cbnum-rate      pic 99v99 value 0.

     

       procedure division.

      

       100-main-module.

           open input movie-data

           open output movie-listing

 

           perform 150-page-header

          

           read movie-data

               at end

                   move "no" to are-there-more-records

           end-read

 

           if are-there-more-records = "yes"

               move movie-rating-in to cbval-rating

               unstring movie-theatre-loc

                   delimited by "@"

                   into movie-theatre movie-location

               move movie-theatre to cbval-theatre

               perform 375-theatre-headers

               perform 175-rating-headers

           end-if

              

           perform 200-movie-routine

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

 

           perform 300-rating-totals

          

           move total-num-movies to total-num-movies-out

           write print-rec from total-file-movies-label

               after advancing 2 lines

 

           move high-avg-rating to high-avg-rate-out

           write print-rec from high-avg-rate-label

               after advancing 1 line.

 

           move "put all totals here!" to print-rec.

           write print-rec after advancing 2 lines.

              

           move "END OF REPORT" to print-rec

           write print-rec after advancing 2 lines

          

           close movie-data

           close movie-listing

      *    accept omitted

           stop run.

 

       150-page-header.

           accept current-date from date.

           move cd-yy to ph-date-yy.

           move cd-mm to ph-date-mm.

           move cd-dd to ph-date-dd.

 

           accept current-time from time.

           move ct-mm to ph-time-mm.

           move ct-ss to ph-time-ss.

           if ct-hh = 0

               move 12 to ph-time-hh

               move "AM" to ph-time-ampm

           else if ct-hh < 12

               move ct-hh to ph-time-hh

               move "AM" to ph-time-ampm

           else if ct-hh = 12

               move ct-hh to ph-time-hh

               move "PM" to ph-time-ampm

           else

               subtract 12 from ct-hh giving ph-time-hh

               move "PM" to ph-time-ampm

           end-if.

 

      * if no period above, does not print out page header!

          

           write print-rec from page-header

               before advancing 0 lines.

 

       175-rating-headers.

           move movie-rating-in to movie-rating-out.

           write print-rec from rating-label

               after advancing 2 lines.

 

      * notice that input case is important!

      * could also put "G" or "g"

      * good to use else for data validation purposes

     

           if movie-rating-in = "G"

               move g-desc to rating-desc-out

           else if movie-rating-in = "PG"

               move pg-desc to rating-desc-out

           else if movie-rating-in = "PG-13"

               move pg13-desc to rating-desc-out

           else if movie-rating-in = "R"

               move r-desc to rating-desc-out

           else

               move "invalid movie rating" to rating-desc-out.

                  

           write print-rec from rating-description

              after advancing 1 line.

 

           write print-rec from column-header1

               after advancing 2 line.

           write print-rec from column-header2

               after advancing 1 line.

           write print-rec from under-line

               after advancing 0 lines.

              

       200-movie-routine.

           move spaces to movie-theatre movie-location

           unstring movie-theatre-loc

               delimited by "@"

               into movie-theatre movie-location

           end-unstring

              

           if cbval-theatre not = movie-theatre

               perform 300-rating-totals

               perform 350-theatre-totals

             

               move movie-rating-in to cbval-rating

               move movie-theatre to cbval-theatre

               perform 375-theatre-headers

               perform 175-rating-headers

           end-if

      

           if cbval-rating not = movie-rating-in

               perform 300-rating-totals

               move movie-rating-in to cbval-rating

               perform 175-rating-headers

           end-if

 

           add 1 to num-cb-recs total-num-movies.

           add box-wk-one-in box-wk-two-in box-wk-three-in

               box-wk-four-in to total-box giving total-box

           add gross-earnings-in to total-rating-gross

          

           perform 250-output-data-line.

        

           read movie-data

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

 

       250-output-data-line.

           move spaces to print-rec.

           move movie-title-in to movie-title-out.

           move prod-company-in to prod-company-out.

           move date-rel-in to date-rel-out.

           move box-wk-one-in to box-wk-one-out.

           move box-wk-two-in to box-wk-two-out.

           move box-wk-three-in to box-wk-three-out.

           move box-wk-four-in to box-wk-four-out.

           move gross-earnings-in to gross-earnings-out.

 

           move spaces to temp-comments-out

           if number-of-reviews > 0

               move spaces to movie-reviewer-ratings

               read movie-data

               move movie-reviewer-ratings to temp-comments-out

               subtract 1 from number-of-reviews

                   giving new-number-of-reviews

               perform new-number-of-reviews times

                   move spaces to comments-out movie-reviewer-ratings

                   read movie-data

                   string

                       temp-comments-out delimited by space

                       "," delimited by size

                       movie-reviewer-ratings delimited by space

                       into comments-out

                   end-string

                   move comments-out to temp-comments-out

               end-perform

           end-if.

           move temp-comments-out to comments-out.

          

           write print-rec from ws-print-rec.

              

       300-rating-totals.

           compute average-cbnum-rating avg-cbnum-rate =

               total-box / (num-cb-recs*4)

           write print-rec from average-rating-label

               after advancing 2 lines.

           move 0 to total-box

      

           move num-cb-recs to total-cbnum-movies

           write print-rec from total-cb-movies-label

               after advancing 1 line

           move 0 to num-cb-recs

 

           move total-rating-gross to total-cbnum-earnings

           write print-rec from total-gross-earnings-label

               after advancing 1 line

           move 0 to total-rating-gross

  

           if avg-cbnum-rate > prev-avg-cbnum-rate

               move cbval-rating to high-avg-rating

               move avg-cbnum-rate to prev-avg-cbnum-rate

           end-if.

 

       350-theatre-totals.

           move "put theatre totals here" to print-rec

           write print-rec after advancing 2 lines.

 

       375-theatre-headers.

           move movie-theatre to movie-theatre-out

           write print-rec from movie-theatre-label

               after advancing 2 lines.

              

           move movie-location to movie-location-out

           write print-rec from movie-location-label

               after advancing 1 line.