问题描述
我正在用COBOL进行编程,并试图将此客户端文件放入数组中。我在理解这个问题时遇到了麻烦。我知道该数组可能基于预订类型,因为有4种不同的选择。任何帮助,将不胜感激。
I am programming in COBOL and trying to put this client file in an array. I'm having trouble understanding this problem. I know that the array would probably be based on the bookingtype because there are 4 different options. Any help would be appreciated.
这是到目前为止我定义数组的方式:
This is how I have the array defined so far:
01 Booking-Table.
05 BookingType OCCURS 4 TIMES PIC 9.
这是客户端文件。
推荐答案
I guess 解决方案是将成本存储在一个数组中。要计算平均值,数组将需要包含费用+编号,并且预订类型为 index 。
棘手部分可能是每种类型的最大金额(9999.99)*此类型的最大客户数量(全部,并且客户编号暗含这三个给定的职位都是数字:1000 [包括零在内,所有都可能具有相同的类型])。
I guess the solution is about storing the costs in an array. To calculate the average the array would need to have cost + number with the booking type being the index used.The "tricky" part may be the maximum of amount per type (9999.99) * maximum customers with this type (all and as the client number implies the 3 given positions are numeric: 1000 [including the zero, all could have the same type]).
类似
REPLACE ==MaxBookingType== BY ==4==.
01 Totals-Table.
05 Type-Total OCCURS MaxBookingType TIMES.
10 type-amount pic 9(8)V99 COMP.
10 type-customers pic 9(4) COMP.
现在从头到尾循环遍历文件,请检查 BookingType> ; = 1 AND< = MaxBookingType
(我总是怀疑数据永远不会改变,而且总是正确的),然后
Now loop through the file from start to end, do check that BookingType >= 1 AND <= MaxBookingType
(I'm always skeptic that "data never changes and is always correct) and then
ADD 1 TO type-customers(BookingType)
ADD trip-cost TO type-amount (BookingType)
,在文件结束后,使用PERFORM VARYING计算所有4个条目的平均值。
and after end of file calculate the average for all 4 entries using a PERFORM VARYING.
使用数组的主要好处这是您可以通过更改 MaxBookingType
的值来将程序更新为20种预订类型,并且添加了一张支票,告诉您什么是不良
The main benefit of using an "array" here is that you can update the program to have 20 booking types just by changing the value for MaxBookingType
- and as you've added a check which tells you what "bad" number is seen in there you can adjust it quite fast.
我不确定您的编译器是否/如何允许自定义数字常量,如果可以的话:使用它而不是强制编译器检查所有出现的文本 MaxBookingType。
I'm not sure if/how your compiler does allow self-defined numeric constants, if there's a way: use this instead of forcing the compiler to check for all occurrences of the text "MaxBookingType".
这篇关于COBOL程序员-如何使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!