如何在Cobol中添加一串星号? [英] How to add a string of asterisks in Cobol?
问题描述
问题:
如果库存总量少于50,则在末尾添加两个星号(**)书面行通知库存管理器需要更多库存。如果库存总数少于10,请在行末添加五个星号(*****),以使库存经理知道迫切需要更多库存。
If the inventory total is less than 50, add a string of two asterisks (**) at the end of the written row to notify the inventory manager that more inventory is needed. If the inventory total is less than 10, add a string of five asterisks (*****) at the end of the row to let the inventory manager know the need for more inventory is urgent.
我将如何在Cobol中制作一个星号字符串?
How would I make a string of asterisks in Cobol?
推荐答案
我如何在Cobol中制作一个星号字符串?
How would I make a string of asterisks in Cobol?
有两种方法。
第一个控制目标位置的字符数,并且在移动之前初始化数据项时效果最佳。第二个控件控制源代码中的字符数,并且在不需要初始化目的地或将其用作 STRING
语句的一部分时,效果最佳。
The first controls the number of characters at the destination and works best when the data item is initialized before the move. The second controls the number of characters at the source and works best when initialization of the destination is of no concern or when used as part of a STRING
statement.
move all "*" to data-name-1 (1:number-of-asterisks)
例如:
program-id. aster.
data division.
working-storage section.
1 n pic 99.
1 asterisk-line pic x(10) value space.
procedure division.
begin.
perform varying n from 10 by -1 until n < 1
move all "*" to asterisk-line (1:n)
display asterisk-line
move space to asterisk-line
end-perform
stop run
.
输出:
**********
*********
********
*******
******
*****
****
***
**
*
注意,该程序在显示星号后移动空格以清除目标位置。这是为了防止在下面的行上显示太多星号。
Notice that the program moves spaces to clear the destination after displaying the asterisks. This is prevent too many asterisks from showing on the following lines.
move asterisks (1:number-of-asterisks) to data-name-1
例如:
program-id. aster2.
data division.
working-storage section.
1 n pic 99.
1 asterisks pic x(10) value all "*".
1 asterisk-line pic x(10) value space.
procedure division.
begin.
perform varying n from 10 by -1 until n < 1
move asterisks (1:n) to asterisk-line
display asterisk-line
end-perform
stop run
.
输出与上面相同。
注意,在移动星号之前,无需移动空格
(或初始化)目的地。
Notice there is no need to move spaces
(or initialize) the destination before moving the asterisks.
这篇关于如何在Cobol中添加一串星号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!