pascal中数组集合怎么定义?
答案:3 悬赏:0 手机版
解决时间 2021-02-05 07:51
- 提问者网友:暗中人
- 2021-02-04 17:47
在pascal中,如何定义数组集合?为什么我的老是‘illegal type declaration of set elements'?可否给个定义样例?
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-02-04 19:17
type set_name_1 = set of 1..10;type set_name_2 = set of char;基类型最大不超过255,你要求的10000可能没法实现. 以下是HELP中剪的结果:---------------------------------------------------------------------------1. set (reserved word)
Syntax:
set of type Remarks:
The base type of a set must be an ordinal type
with no more than 256 possible values.The ordinal values of the upper and lower
bounds of the base type must be between 0 and
255.A set constructor, which denotes a set-type
value, is formed by writing expressions within
brackets. Each expression denotes a value of
the set.The notation [ ] denotes the empty set, which
is compatible with all set types. Example:
{ Set types }
type
Day = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
CharSet = set of Char;
Digits = set of 0..9;
Days = set of Day; { Set constructors } ['0'..'9', 'A'..'Z', 'a'..'z', '_']
[1, 5, I + 1 .. J - 1]
[Mon..Fri] See Also:
Set-type constants2. Set-type constants
The declaration of a set-type constant
specifies the value of the set using a
constant expression. Examples:
type
Digits = set of 0..9;
Letters = set of 'A'..'Z';
const
EvenDigits: Digits = [0, 2, 4, 6, 8];
Vowels: Letters = ['A', 'E', 'I', 'O', 'U', 'Y'];
HexDigits: set of '0'..'z' = ['0'..'9', 'A'..'F', 'a'...f'];
Syntax:
set of type Remarks:
The base type of a set must be an ordinal type
with no more than 256 possible values.The ordinal values of the upper and lower
bounds of the base type must be between 0 and
255.A set constructor, which denotes a set-type
value, is formed by writing expressions within
brackets. Each expression denotes a value of
the set.The notation [ ] denotes the empty set, which
is compatible with all set types. Example:
{ Set types }
type
Day = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
CharSet = set of Char;
Digits = set of 0..9;
Days = set of Day; { Set constructors } ['0'..'9', 'A'..'Z', 'a'..'z', '_']
[1, 5, I + 1 .. J - 1]
[Mon..Fri] See Also:
Set-type constants2. Set-type constants
The declaration of a set-type constant
specifies the value of the set using a
constant expression. Examples:
type
Digits = set of 0..9;
Letters = set of 'A'..'Z';
const
EvenDigits: Digits = [0, 2, 4, 6, 8];
Vowels: Letters = ['A', 'E', 'I', 'O', 'U', 'Y'];
HexDigits: set of '0'..'z' = ['0'..'9', 'A'..'F', 'a'...f'];
全部回答
- 1楼网友:duile
- 2021-02-04 21:17
集合是由具有某些共同特征的元素构成的一个整体。在pascal中,一个集合是由具有同一有序类型的一组数据元素所组成,这一有序类型称为该集合的基类型。
你说的数据集合是什么意思?
- 2楼网友:孤老序
- 2021-02-04 20:22
const是常量,而数组是表示一串变量,
lz是不是想问在type类型中定义数组?
我的意思是,你是不是在子程序的参数中要用到数组,而类似
procedure a(var s:array[1..100]of integer);
这样的定义不合法?
我有时也遇到这样的情况,后来问同学,教了一种方法:
在开头定义一个类型type:
type arr=array[1..1024]of longint; //注意是等号
之后在子程序或主程序中定义 1..1024 的数组时,就可以这么用:
主程序:
var a,b:arr;
子程序:
procedure example(a,b:arr); //过程
function example2(a,b:arr); //函数
希望能有所帮助,也许这些你已经学过了……
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯