pascal记录例题

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:44:29
本人一pascal初学者,也是自学的。现在学到记录这儿了,本人愚笨。教材有的只是看不懂,介绍的也不太清楚。不知道那位高手赐教于我,给我个记录的例题让我明白下。当然要简单点的,也务必介绍清楚点。谢

1.记录的定义:
type 类型标识符=record
字段名1:类型1;
字段名2:类型2;
...
字段名n:类型n;
end;
如:
type
studata=record
num:string[6];
name:string[8];
sex:boolean;
s:array[1..5] of real;
end;
var
student:studata;
students:array[1..10] of studata;
2.记录的运用:
(1)对记录中和个域的引用,要写出记录名和域名,如:student.num
(2)开域语句:with。
with 记录名 do 语句;

with 记录名1,记录名2,... do 语句;
注意:
1. 在do后面语句中使用的记录的域时,只要简单地写出域名就可以了, 域名前的记录变量和"."均可省略。
2. 在关键字with后面,语句可以是一个简单语句,了可以是一个复合语句。
3. 虽然在with后可以有多个记录变量名,但一般在with后只使用一个记录变量名。

输入10 个人的生日
program shengri(input,output);
type date=record
year:1980..1999;
month:1..12;
day:1..31;
var
a:array[1..10] of date; i:integer;
begin
for i:=1 to 10 do
with a[i] do
readln(year,month,day);end;
end.