Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1392879
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4337
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: 系统运维

2013-05-29 22:38:45

关于cobol的历史我们不做解释,感兴趣的可以自己看书,由于cobol自己学习的时间比较短,而且以后用到的概率也比较小
因此这里,这做简单的了解,能看懂就Ok,不过需要说明的是由于cobol的语法类似散文,且整个思维都是英语思维,程序整体上的结构还是比较固定的,


点击(此处)折叠或打开

  1. 000100 IDENTIFICATION DIVISION.
  2. 000200 PROGRAM-ID. CMPINT02.
  3. 000300*------------------------------------------------
  4. 000400* Calculates compound interest
  5. 000500*------------------------------------------------
  6. 000600 ENVIRONMENT DIVISION.
  7. 000700 DATA DIVISION.
  8. 000800 WORKING-STORAGE SECTION.
  9. 000900001000 01 YES-NO PIC X.
  10. 001100 01 ENTRY-OK PIC X.
  11. 001200 01 THE-INTEREST PIC 99V9.     --类似变量定义
  12. 001300 01 INTEREST-AS-DECIMAL PIC V999.
  13. 001400 01 THE-PRINCIPAL PIC 9(9)V99.
  14. 001500 01 THE-NEW-VALUE PIC 9(9)V99.
  15. 001600 01 EARNED-INTEREST PIC 9(9)V99.
  16. 001700 01 THE-PERIOD PIC 9999.
  17. 001800 01 NO-OF-PERIODS PIC 999.
  18. 001900
  19. 002000 01 ENTRY-FIELD PIC Z(9).ZZ.
  20. 002100 01 DISPLAY-VALUE PIC ZZZ,ZZZ,ZZ9.99.
  21. 002200
  22. 002300 PROCEDURE DIVISION.
  23. 002400 PROGRAM-BEGIN.
  24. 002500
  25. 002600 MOVE "Y" TO YES-NO.      变量赋值
  26. 002700 PERFORM GET-AND-DISPLAY-RESULT util 循环
  27. 002800 UNTIL YES-NO = "N".
  28. 002900
  29. 003000 PROGRAM-DONE.
  30. 003100 STOP RUN.
  31. 003200
  32. 003300 GET-AND-DISPLAY-RESULT.
  33. 003400 PERFORM GET-THE-PRINCIPAL.      顺序执行,且paragraph 调用
  34. 003500 PERFORM GET-THE-INTEREST.
  35. 003600 PERFORM GET-THE-PERIODS.
  36. 003700 PERFORM CALCULATE-THE-RESULT.
  37. 003800 PERFORM DISPLAY-THE-RESULT.
  38. 003900 PERFORM GO-AGAIN.
  39. 004000
  40. 004100 GET-THE-PRINCIPAL.
  41. 004200 MOVE "N" TO ENTRY-OK.
  42. 004300 PERFORM ENTER-THE-PRINCIPAL
  43. 004400 UNTIL ENTRY-OK = "Y".
  44. 004500
  45. 004600 ENTER-THE-PRINCIPAL.
  46. 004700 DISPLAY "Principal (.01 TO 999999.99)?".
  47. 004800 ACCEPT ENTRY-FIELD.
  48. 004900 MOVE ENTRY-FIELD TO THE-PRINCIPAL.
  49. 005000 IF THE-PRINCIPAL < .01 OR   if 条件判断与逻辑表达式
  50. 005100 THE-PRINCIPAL > 999999.99
  51. 005200 DISPLAY "INVALID ENTRY"
  52. 005300 ELSE
  53. 005400 MOVE "Y" TO ENTRY-OK.005500
  54. 005600 GET-THE-INTEREST.
  55. 005700 MOVE "N" TO ENTRY-OK.
  56. 005800 PERFORM ENTER-THE-INTEREST
  57. 005900 UNTIL ENTRY-OK = "Y".
  58. 006000
  59. 006100 ENTER-THE-INTEREST.
  60. 006200 DISPLAY "Interest (.1% TO 99.9%)?".
  61. 006300 ACCEPT ENTRY-FIELD.
  62. 006400 MOVE ENTRY-FIELD TO THE-INTEREST.
  63. 006500 IF THE-INTEREST < .1 OR
  64. 006600 THE-INTEREST > 99.9
  65. 006700 DISPLAY "INVALID ENTRY"
  66. 006800 ELSE
  67. 006900 MOVE "Y" TO ENTRY-OK
  68. 007000 COMPUTE INTEREST-AS-DECIMAL =
  69. 007100 THE-INTEREST / 100.
  70. 007200
  71. 007300 GET-THE-PERIODS.
  72. 007400 MOVE "N" TO ENTRY-OK.
  73. 007500 PERFORM ENTER-THE-PERIODS
  74. 007600 UNTIL ENTRY-OK = "Y".
  75. 007700
  76. 007800 ENTER-THE-PERIODS.
  77. 007900 DISPLAY "Number of periods (1 TO 999)?".
  78. 008000 ACCEPT ENTRY-FIELD.
  79. 008100 MOVE ENTRY-FIELD TO NO-OF-PERIODS.
  80. 008200 IF NO-OF-PERIODS < 1 OR
  81. 008300 NO-OF-PERIODS > 999
  82. 008400 DISPLAY "INVALID ENTRY"
  83. 008500 ELSE
  84. 008600 MOVE "Y" TO ENTRY-OK.
  85. 008700
  86. 008800 CALCULATE-THE-RESULT.
  87. 008900 PERFORM CALCULATE-ONE-PERIOD
  88. 009000 VARYING THE-PERIOD FROM 1 BY 1
  89. 009100 UNTIL THE-PERIOD > NO-OF-PERIODS.
  90. 009200
  91. 009300 CALCULATE-ONE-PERIOD.
  92. 009400 COMPUTE EARNED-INTEREST ROUNDED =
  93. 009500 THE-PRINCIPAL * INTEREST-AS-DECIMAL.     
  94. 009600 COMPUTE THE-NEW-VALUE =
  95. 009700 THE-PRINCIPAL + EARNED-INTEREST.
  96. 009800 MOVE THE-NEW-VALUE TO THE-PRINCIPAL.
  97. 009900
  98. 010000 GO-AGAIN.010100 DISPLAY "GO AGAIN?".
  99. 010200 ACCEPT YES-NO.
  100. 010300 IF YES-NO = "y"
  101. 010400 MOVE "Y" TO YES-NO.
  102. 010500 IF YES-NO NOT = "Y"
  103. 010600 MOVE "N" TO YES-NO.
  104. 010700
  105. 010800 DISPLAY-THE-RESULT.
  106. 010900 MOVE THE-NEW-VALUE TO DISPLAY-VALUE.
  107. 011000 DISPLAY "RESULTING VALUE IS " DISPLAY-VALUE.


阅读(3239) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~