2016-02-24 130 views
-1

我正在創建一個閱讀文件的程序,該文件由公司及其信息組成。它拒絕評級低於3.5的公司,然後顯示最高報價和最低報價,然後顯示公司之間的平均報價。我是Cobol的新手,所以我不確定如何找到最高,最低和平均水平。我已經編寫了我在Module 2012中的工作,以找到最高的,但是當我運行我的程序時,它不顯示信息。任何幫助,這將不勝感激。謝謝在Cobol中查找最高,最低和平均值

IDENTIFICATION DIVISION. 
    PROGRAM-ID. MOVING-QUOTES. 



    ENVIRONMENT DIVISION. 
    INPUT-OUTPUT SECTION. 
    FILE-CONTROL. 

     SELECT MOVING-QUOTES-FILE ASSIGN TO 'Moving-Quotes.txt' 
      ORGANIZATION IS LINE SEQUENTIAL. 
     SELECT MOVING-QUOTES-RESULTS-FILE ASSIGN TO "MOVING.TXT" 
      ORGANIZATION IS LINE SEQUENTIAL. 

    DATA DIVISION. 
    FILE SECTION. 
    FD MOVING-QUOTES-FILE. 
    01 FS-MOVING-QUOTES-RECORD    PIC X(45). 

    FD MOVING-QUOTES-RESULTS-FILE. 
    01 MOVING-QUOTES-RESULTS-RECORD  PIC X(80). 

    WORKING-STORAGE SECTION. 

    01 WS-MOVING-QUOTES-RECORD. 
     05 FILLER       PIC X(2). 
     05 MQR-COMPANY-NAME     PIC X(15). 
     05 FILLER       PIC X(1). 
     05 MQR-COMPANY-PHONE    PIC X(13). 
     05 FILLER       PIC X(1). 
     05 MQR-MOVING-QUOTE     PIC 999V99. 
     05 FILLER       PIC X(1). 
     05 MQR-NUMBER-ITEMS     PIC 999. 
     05 FILLER       PIC X(1). 
     05 MQR-RATING      PIC 9V9. 

    01 PRT-MOVING-QUOTES-FILE. 
     05 FILLER       PIC X(2). 
     05 PRT-MQR-COMPANY-NAME    PIC X(15). 
     05 FILLER       PIC X(1) VALUE SPACES. 
     05 PRT-MQR-COMPANY-PHONE   PIC X(13). 
     05 FILLER       PIC X(5). 
     05 PRT-MQR-MOVING-QUOTE    PIC $zz99.99. 
     05 FILLER       PIC X(7). 
     05 PRT-MQR-NUMBER-ITEMS    PIC 9(3). 
     05 FILLER       PIC X(15). 
     05 PRT-MQR-RATING     PIC 9.9. 

    01 PAGE-TITLE. 
     05     PIC X(22) VALUE SPACES. 
     05     PIC X(40) VALUE 'MOVING COMPANY QUOTES'. 
     05     PIC X(18) VALUE SPACES. 
     05 PRT-PAGE-NUM  PIC Z9. 

    01 QUOTE-HEADING-1. 
     05        PIC X(7) VALUE SPACES. 
     05        PIC X(7) VALUE 'COMPANY'. 
     05        PIC X(9) VALUE SPACES. 
     05        PIC X(5) VALUE 'PHONE'. 
     05        PIC X(21) VALUE SPACES. 
     05        PIC X(9) VALUE 'NUMBER OF'. 
     05        PIC X(11) VALUE SPACES. 
     05        PIC X(4) VALUE 'YELP'. 
     05        PIC X(7). 

    01 QUOTE-HEADING-2. 
     05         PIC X(8). 
     05         PIC X(4) VALUE 'NAME'. 
     05         PIC X(11) VALUE SPACES. 
     05         PIC X(6) VALUE 'NUMBER'. 
     05         PIC X(9) VALUE SPACES. 
     05         PIC X(5) VALUE 'QUOTE'. 
     05         PIC X(7) VALUE SPACES. 
     05         PIC X(5) VALUE 'ITEMS'. 
     05         PIC X(13) VALUE SPACES. 
     05         PIC X(6) VALUE 'RATING'. 
     05         PIC X(2) VALUE SPACES. 
    01 QUOTE-HEADING-3.   
     05         PIC X(6) VALUE SPACES. 
     05         PIC X(9) VALUE ALL '-'. 
     05         PIC X(7) VALUE SPACES. 
     05         PIC X(8) VALUE ALL '-'. 
     05         PIC X(7) VALUE SPACES. 
     05         PIC X(7) VALUE ALL '-'. 
     05         PIC X(5) VALUE SPACES. 
     05         PIC X(11) VALUE ALL '-'. 
     05         PIC X(7) VALUE SPACES. 
     05         PIC X(8) VALUE ALL '-'. 



    01 WS-SWITCHES-AND-COUNTERS. 
     05 WS-EOF       PIC X  VALUE 'F'. 
     05 NUMBER-OF-PAGES    PIC S9(4) COMP VALUE 0. 
     05 NUMBER-OF-LINES-USED   PIC S9(4) COMP VALUE 0. 
     05 WS-HI-BID      PIC 999V99 VALUE 0. 
     05 WS-LO-BID      PIC 999V99 VALUE 999.99. 
     05 WS-TOTAL-BID-SUM    PIC 999V99 VALUE 0. 
     05 WS-NUMBER-OF-RECORDS   PIC 9(4) VALUE 4. 
     05 WS-AVERAGE      PIC 999V99. 

    01 HI-COMPANY-INFO. 
     05 FILLER       PIC X(6) VALUE SPACES. 
     05 SAV-HI-MQR-COMPANY-NAME   PIC X(15). 
     05 FILLER       PIC X(2) VALUE SPACES. 
     05 SAV-HI-MQR-COMPANY-PHONE   PIC X(13). 
     05 FILLER       PIC X(2) VALUE SPACES. 
     05 SAV-HI-MQR-QUOTE     PIC $ZZ99.99. 

    01 LO-COMPANY-INFO. 
     05 FILLER       PIC X(5) VALUE SPACES. 
     05 SAV-LO-MQR-COMPANY-NAME   PIC X(15). 
     05 FILLER       PIC X(2) VALUE SPACES. 
     05 SAV-LO-MQR-COMPANY-PHONE   PIC X(13). 
     05 FILLER       PIC X(2) VALUE SPACES. 
     05 SAV-LO-MQR-QUOTE     PIC $ZZ99.99. 

    01 AVG-INFO. 
     05         PIC X(6) VALUE SPACES. 
     05 SAV-AVG       PIC $ZZ99.99. 

    01 HI-INFO-HD1. 
     05         PIC X(8). 
     05         PIC X(7) VALUE 'HIGH'. 
     05         PIC X(8). 
     05         PIC X(5) VALUE 'PHONE'. 
     05         PIC X(52). 

    01 HI-INFO-HD2. 
     05         PIC X(6). 
     05         PIC X(7) VALUE 'COMPANY'. 
     05         PIC X(10). 
     05         PIC X(6) VALUE 'NUMBER'. 
     05         PIC X(9). 
     05         PIC X(5) VALUE 'QUOTE'. 
     05         PIC X(37). 
    01 HI-INFO-HD3. 
     05         PIC X(5). 
     05         PIC X(9) VALUE ALL '-'. 
     05         PIC X(8). 
     05         PIC X(8) VALUE ALL '-'. 
     05         PIC X(7). 
     05         PIC X(7) VALUE ALL '-'. 
     05         PIC X(36). 

    01 LO-INFO-HD1. 
     05         PIC X(7). 
     05         PIC X(3) VALUE 'LOW'. 
     05         PIC X(13). 
     05         PIC X(5) VALUE 'PHONE'. 
     05         PIC X(52). 

    01 LO-INFO-HD2. 
     05         PIC X(6). 
     05         PIC X(7) VALUE 'COMPANY'. 
     05         PIC X(10). 
     05         PIC X(6) VALUE 'NUMBER'. 
     05         PIC X(9). 
     05         PIC X(5) VALUE 'QUOTE'. 
     05         PIC X(37). 

    01 LO-INFO-HD3. 
     05         PIC X(5). 
     05         PIC X(9) VALUE ALL '-'. 
     05         PIC X(8). 
     05         PIC X(8) VALUE ALL '-'. 
     05         PIC X(7). 
     05         PIC X(7) VALUE ALL '-'. 
     05         PIC X(36). 

    01 AVG-INFO-HD1. 
     05         PIC X(7). 
     05         PIC X(7) VALUE 'AVERAGE'. 

    01 AVG-INFO-HD2.      
     05         PIC X(6). 
     05         PIC X(9) VALUE ALL '-'. 
     05         PIC X(65). 

    PROCEDURE DIVISION. 
    0000-MAINLINE. 
     PERFORM 1000-START-MOVING-QUOTES 
     PERFORM 2000-READ-N-PRINT-MQ 
      UNTIL WS-EOF = 'T'  
     PERFORM 3000-FINISH-UP 
     STOP RUN 
     . 


    *END OF MAIN BLOCK 

    1000-START-MOVING-QUOTES. 
     OPEN INPUT MOVING-QUOTES-FILE 
      OUTPUT MOVING-QUOTES-RESULTS-FILE 
     PERFORM 8000-READ-MOVING-QUOTES-FILE 
     IF WS-EOF NOT = 'T' 
      PERFORM 8020-PRINT-TITLE-AND-HEADINGS. 
     . 


    8000-READ-MOVING-QUOTES-FILE. 
     READ MOVING-QUOTES-FILE 
      AT END MOVE 'T' TO WS-EOF 
     end-READ 
     MOVE FS-MOVING-QUOTES-RECORD TO 
      WS-MOVING-QUOTES-RECORD 
     .   


    8010-CHECK-LINES. 
     ADD 2 TO NUMBER-OF-LINES-USED 
     IF NUMBER-OF-LINES-USED > 90 
      PERFORM 8020-PRINT-TITLE-AND-HEADINGS 
     . 

    8020-PRINT-TITLE-AND-HEADINGS. 
     ADD 1 TO NUMBER-OF-PAGES 
     MOVE NUMBER-OF-PAGES TO PRT-PAGE-NUM 
     MOVE SPACES TO MOVING-QUOTES-RESULTS-RECORD 
     MOVE PAGE-TITLE TO MOVING-QUOTES-RESULTS-RECORD 
     WRITE MOVING-QUOTES-RESULTS-RECORD AFTER ADVANCING 3 LINES 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM NUMBER-OF-PAGES 
      AFTER ADVANCING 1 LINE   
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-1 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-2 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-3 
      AFTER ADVANCING 1 LINE 
     . 

    8025-PRINT-HI-HD. 
     MOVE SPACES TO MOVING-QUOTES-RESULTS-RECORD 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD1 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD2 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD3 
      AFTER ADVANCING 1 LINE 
     . 

    8026-PRINT-LO-HD. 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD1 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD2 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD3 
      AFTER ADVANCING 1 LINE 
     . 

    8027-PRINT-AVG-HD. 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM AVG-INFO-HD1 
      AFTER ADVANCING 1 LINE 
     WRITE MOVING-QUOTES-RESULTS-RECORD FROM AVG-INFO-HD2 
      AFTER ADVANCING 1 LINE 
     . 


    2000-READ-N-PRINT-MQ. 
    * PERFORM 8010-CHECK-LINES 
     PERFORM 8000-READ-MOVING-QUOTES-FILE 
     IF (MQR-RATING >= 3.5) 
      MOVE WS-MOVING-QUOTES-RECORD TO 
      PRT-MOVING-QUOTES-FILE 
      PERFORM 2001-PRINT-COMP 
      PERFORM 2010-FIND-HI-LO-AVG 
     END-IF 


     . 

    2001-PRINT-COMP. 
     MOVE MQR-COMPANY-NAME TO PRT-MQR-COMPANY-NAME 
     MOVE MQR-COMPANY-PHONE TO PRT-MQR-COMPANY-PHONE 
     MOVE MQR-MOVING-QUOTE TO PRT-MQR-MOVING-QUOTE 
     MOVE MQR-NUMBER-ITEMS TO PRT-MQR-NUMBER-ITEMS 
     MOVE MQR-RATING TO PRT-MQR-RATING 
     MOVE PRT-MOVING-QUOTES-FILE TO MOVING-QUOTES-RESULTS-RECORD 
     WRITE MOVING-QUOTES-RESULTS-RECORD 
      AFTER ADVANCING 2 LINES 
     ADD 1 TO WS-NUMBER-OF-RECORDS 
     . 

    2010-FIND-HI-LO-AVG. 

     PERFORM 2012-FIND-HI 
     PERFORM 2013-STORING-VAL-LO 
     PERFORM 2014-FIND-LO 
     PERFORM 2015-GET-SUM 

     PERFORM 2016-GET-AVERAGE 
    *  PERFORM 8000-READ-MOVING-QUOTES-FILE 
     . 

    2011-STORING-VAL-HI. 
     MOVE MQR-MOVING-QUOTE TO WS-HI-BID 
     . 

    2012-FIND-HI. 
     PERFORM 2011-STORING-VAL-HI 
     IF (MQR-MOVING-QUOTE > WS-HI-BID) 
      MOVE MQR-MOVING-QUOTE TO WS-HI-BID 
      MOVE MQR-COMPANY-NAME TO SAV-HI-MQR-COMPANY-NAME 
      MOVE MQR-COMPANY-PHONE TO SAV-HI-MQR-COMPANY-PHONE 
      MOVE WS-HI-BID TO SAV-HI-MQR-QUOTE 
      MOVE HI-COMPANY-INFO TO MOVING-QUOTES-RESULTS-RECORD 
      WRITE MOVING-QUOTES-RESULTS-RECORD 
       AFTER ADVANCING 2 LINES 
     END-IF 
     .    

    2013-STORING-VAL-LO. 
     MOVE MQR-MOVING-QUOTE TO WS-LO-BID 
     .  

    2014-FIND-LO. 
     IF (MQR-MOVING-QUOTE < WS-LO-BID) 
     MOVE MQR-MOVING-QUOTE TO WS-LO-BID 
     MOVE MQR-COMPANY-NAME TO SAV-LO-MQR-COMPANY-NAME 
     MOVE MQR-COMPANY-PHONE TO SAV-LO-MQR-COMPANY-PHONE 
     MOVE MQR-MOVING-QUOTE TO SAV-LO-MQR-QUOTE 
     .  

    2015-GET-SUM. 
     ADD MQR-MOVING-QUOTE GIVING WS-TOTAL-BID-SUM 
     . 

    2016-GET-AVERAGE. 
     DIVIDE WS-TOTAL-BID-SUM BY WS-NUMBER-OF-RECORDS GIVING 
       WS-AVERAGE 
     MOVE WS-AVERAGE TO SAV-AVG 
     . 


    3000-FINISH-UP. 

     PERFORM 8025-PRINT-HI-HD 
     PERFORM 2012-FIND-HI 
     PERFORM 3010-PRT-HI 
     PERFORM 8026-PRINT-LO-HD 
     PERFORM 2014-FIND-LO 
     PERFORM 3020-PRT-LO 
     PERFORM 8027-PRINT-AVG-HD 
     PERFORM 2016-GET-AVERAGE 
     PERFORM 3030-PRT-AVG 


     CLOSE MOVING-QUOTES-FILE 
      MOVING-QUOTES-RESULTS-FILE 
     . 

    3010-PRT-HI. 
     MOVE HI-COMPANY-INFO TO MOVING-QUOTES-RESULTS-RECORD 
     . 

    3020-PRT-LO. 
     MOVE LO-COMPANY-INFO TO MOVING-QUOTES-RESULTS-RECORD 
     . 

    3030-PRT-AVG. 
     MOVE SAV-AVG TO MOVING-QUOTES-RESULTS-RECORD 
     . 
+4

哇。整個班級會在這裏發佈問題嗎?你是最近幾天的第三名。結束閱讀,你的同事失敗的布拉沃。你需要END-IF來處理所有IF。你不需要在代碼中附加任何句號/句點,而只需要在段落結尾的那些孤單句子。 –

+0

比爾這個問題包括第一個問題的結尾閱讀建議 –

+0

@BruceMartin你的意思是「結束閱讀」是一個贈送? :-) –

回答

2

從更新攝於Finding Highest , Lowest and the Average in a Cobol program

一些更多的問題在2000-執行8000-應該在程序結束

目前:

2000-READ-N-PRINT-MQ. 
    * PERFORM 8010-CHECK-LINES 
     PERFORM 8000-READ-MOVING-QUOTES-FILE 
     IF (MQR-RATING >= 3.5) 
      MOVE WS-MOVING-QUOTES-RECORD TO 
      PRT-MOVING-QUOTES-FILE 
      PERFORM 2001-PRINT-COMP 
      PERFORM 2010-FIND-HI-LO-AVG 
     END-IF 

應該是:

2000-READ-N-PRINT-MQ. 
    * PERFORM 8010-CHECK-LINES 
     IF (MQR-RATING >= 3.5) 
      MOVE WS-MOVING-QUOTES-RECORD TO 
      PRT-MOVING-QUOTES-FILE 
      PERFORM 2001-PRINT-COMP 
      PERFORM 2010-FIND-HI-LO-AVG 
     END-IF 
     PERFORM 8000-READ-MOVING-QUOTES-FILE 

也在2012年 - 爲什麼你要寫作,當然這應該在最後完成(第3000-)。

的2012-,2013-不作任何意義

在2000,2011,2012,你需要做

if value-from-input-file > current-high 
    move input-file-details to current-High-details 
end-if 
if value-from-input-file < current-low 
    move input-file-details to current-Low-details 
end-if 

這樣,你會寫出來的高/低導致3000-

它也是很重要適當地初始化hi/low值???


嘗試要麼

  • 在程序的(+ relavent細節)
  • 開始投入顯示的使用調試器

要麼會告訴你什麼程序流程是

+1

我認爲hi(零)和low(999.99)的初始化是正確的。 WS-NUMBER-OF-RECORDS(一個壞名字,因爲它是一個子集)不是 - 具有初始值4 ... –

+1

2015年的代碼 - 我看不出它將如何編譯。鑑於此,我不知道如何得到正確的結果。 –

+0

@bill你說的是正確的2015- –

相關問題