097.复杂记录类型的使用及其赋值过程中的兼容问题

本文介绍了一个使用Ada语言的编程示例,定义了多种数据类型,包括SQUARE、LINEAR_TYPE和STUFF等,并展示了如何初始化和操作这些类型的实例。通过矩阵和线性数组的创建与赋值,演示了Ada中记录和数组的使用。
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure Discrim1 is

   type SQUARE is array(INTEGER range <>,
                        INTEGER range <>) of INTEGER;

   type LINEAR_TYPE is array(INTEGER range <>) of POSITIVE;

   type STUFF(List_Size : POSITIVE) is
      record
         Matrix   : SQUARE(1..List_Size, 1..List_Size);
         Elements : INTEGER := List_Size * List_Size;
         Linear   : LINEAR_TYPE(1..List_Size);
         Number   : INTEGER := List_Size;
      end record;

   type ANOTHER_STUFF is new STUFF;

   subtype STUFF_5 is STUFF(5);

   Data_Store  : STUFF(5);
   Big_Store   : STUFF(12);
   Extra_Store : ANOTHER_STUFF(5);
   More_Store  : STUFF(5);
   Five_Store  : STUFF_5;
   Name_Store  : STUFF(List_Size => 5);

begin

   for Index1 in Data_Store.Matrix'RANGE(1) loop
      Data_Store.Linear(Index1) := Index1;
      for Index2 in Data_Store.Matrix'RANGE(2) loop
         Data_Store.Matrix(Index1, Index2) := Index1 * Index2;
      end loop;
   end loop;

   Five_Store := Data_Store;
   More_Store := Five_Store;

   Put("The number of elements in More_Store.Matrix is");
   Put(More_Store.Elements, 5);
   New_Line;

end Discrim1;

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值