
Ada语言程序设计基础
本专栏为需要学习Ada语言基础的学生提供一定的帮助,给出不同的实例快速入门ada语言
dos diosas
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
105.关于limited关键字的一个有用的例子
在这里值得注意的是,尽管根据原有的代码实例,定义BOX为一个limited类型的,但是我们知道limited关键字修饰的类型定义的对象,是不允许进行赋值以及其他的比较操作的,所以,原有的教程出现了纰漏,这里进行修正。shape.adspackage Shape is type BOX is -- limited record Length : INTEGER; Width : INTEGER; Height : INTEGER;原创 2020-05-11 16:08:02 · 208 阅读 · 0 评论 -
104.私有类型(Private Type)和有限专用类型(Limited Private Type)
私有类型(Private Type)和有限专用类型(Limited Private Type)的区别在于在程序包外,对私有类型数据只能执行 := 和 = 操作如果嫌私有类型的 := 和 = 这两个默认操作也多余,则使用有限专用类型,也就是说被声明为 limitedprivate类型的话,其私有变量是不能进行 判等,赋值操作的three.ads-- This package uses a data structure composed of three INTEGER-- variables. I原创 2020-05-11 15:27:17 · 1051 阅读 · 0 评论 -
103.利用private保留字进行信息隐藏
three.adspackage Three istype DATA_STRUCTURE is private;function "+"(Data1, Data2 : DATA_STRUCTURE) return DATA_STRUCTURE;function "-"(Data1, Data2 : DATA_STRUCTURE) return DATA_STRUCTURE;function Build_Structure(Val1, Val2, Val3 : INTEGER) return原创 2020-05-11 15:00:56 · 173 阅读 · 0 评论 -
102.重载加法运算符并作用于记录类型上
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Infix is type THREE_INTS is record Length,Height,Width:Integer; end record; Big,Medium,Sum:THREE_INTS; function "+"(Record1,Reco原创 2020-05-11 13:49:29 · 109 阅读 · 0 评论 -
101.记录类型的初始化
procedure Variant1 is type POWER is (GAS,STEAM,DIESEL,NONE); type VEHICLE (Engine:POWER)is record Model_Year:Integer range 1888..1992; Wheels:Integer range 2..18; case Engine is when GAS=>原创 2020-05-11 13:38:04 · 144 阅读 · 0 评论 -
100.记录类型的多重默认参数的设置
with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Discrim4 is type SQUARE is array(INTEGER range <>, INTEGER range <>) of INTEGER; type LINEAR_TYPE is array(INTEGER range <原创 2020-05-11 13:16:01 · 88 阅读 · 0 评论 -
099.函数传参与它的返回值
with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Discrim3 is type SQUARE is array(INTEGER range <>, INTEGER range <>) of INTEGER; type LINEAR_TYPE is array(INTEGER range <原创 2020-05-11 12:53:19 · 148 阅读 · 0 评论 -
098.求解矩阵中各个元素的和
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Discrim2 is type SQUARE is array (Integer range<>,Integer range<>)of Integer; type LINEAR_TYPE is array (Integer range<>)of Positive; t原创 2020-05-11 12:39:53 · 269 阅读 · 0 评论 -
097.复杂记录类型的使用及其赋值过程中的兼容问题
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 <原创 2020-05-11 12:16:46 · 134 阅读 · 0 评论 -
096.Ada中的加减法的重载操作
with Ada.Text_IO,Ada.Integer_Text_IO,Ada.Float_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO,Ada.Float_Text_IO;procedure UnaryOp is type ARY_INT is array(1..6) of INTEGER; Crowd, Group1, Group2 : ARY_INT; function "+"(In_Array1, In_Array2原创 2020-05-10 21:04:32 · 166 阅读 · 0 评论 -
095.重载加法运算符用于两个数组的相加
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure ArrayOp2 is type ARY_INT is array(1..6) of Integer; Crowd,Group1,Group2:ARY_INT; function "+" (In_Array1,In_Array2:ARY_INT)return ARY_INT is Te原创 2020-05-10 20:53:01 · 567 阅读 · 0 评论 -
094.可作用于数组中的运算符
with Ada.Text_IO;use Ada.Text_IO;procedure ArrayOps is type ARY_INT is array(1..6) of Integer; type ARY_BOOL is array(4..7) of Boolean; Do_They_Compare:Boolean; Crowd,Group1,Group2:ARY_INT; Result,Answer1,Answer2:ARY_BOOL; beg原创 2020-05-10 20:27:33 · 215 阅读 · 0 评论 -
093.带有枚举变量索引的数组的示例
with Ada.Text_IO,Ada.Float_Text_IO;use Ada.Text_IO,Ada.Float_Text_IO;procedure EnumAry is type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN); Hours : array(DAY) of FLOAT; -- array(DAY) 代指下标的取法 Total_Hours : FLOAT; Today : DAY;原创 2020-05-10 20:12:55 · 192 阅读 · 0 评论 -
092.动态数组
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Summer is type MY_ARRAY is array (Positive range <>) of Integer; Dummy1:constant MY_ARRAY:=(27,14,13,33); Dummy2:constant MY_ARRAY:=(112=>24,113原创 2020-05-10 19:16:04 · 155 阅读 · 0 评论 -
091.运算符重载,以一个box对象为例
shape.adspackage Shape is type BOX is record Length : INTEGER; Width : INTEGER; Height : INTEGER; end record; function Make_A_Box(In_Length, In_Width, In_Height : INTEGER)原创 2020-05-10 18:50:35 · 220 阅读 · 0 评论 -
090.使用一个辅助数组队员数组进行逆转(函数返回数组的实例)
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Revers is type MY_ARRAY is array(3..10) of Integer; Store_Here:MY_ARRAY:=(3,16,-5,6,12,66,-13,57); Another :MY_ARRAY; function Reverse_Array(Data:原创 2020-05-10 18:41:55 · 132 阅读 · 0 评论 -
089.对函数的递归
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure FuncRecr is START :constant :=-2; STOP :constant :=5; Result:Integer; Data_Value:Integer; function Factorial_Possible(Number:Integer)return Boolea原创 2020-05-10 18:12:28 · 253 阅读 · 0 评论 -
088.对自身的递归调用
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Recurson is Index:Integer; procedure Print_And_Decrement(Value:in Integer)is New_Value:Integer; begin Put("The value of the index is n原创 2020-05-10 17:22:50 · 163 阅读 · 0 评论 -
087.the usage of DYNAMIC DEFAULT PARAMETERS
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Default2 is Index:Integer; Animal_Sum:Integer; function Cow_Constant return Integer is begin return 7; end Cow_Constant; function Pig_Cons原创 2020-05-10 17:12:00 · 109 阅读 · 0 评论 -
086.使用位置参数
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Defaults is Index:Integer; Animal_Sum:Integer; procedure Animals(Total:in out Integer; Cows:in Integer :=0; Pigs:in原创 2020-05-10 16:56:07 · 164 阅读 · 0 评论 -
085.使用Ada内置的异常库
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Exceptions;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Occur is Except_ID : Ada.Exceptions.EXCEPTION_OCCURRENCE; procedure Divide_Loop is Divide_Result : INTEGER; begin for Index in 1原创 2020-05-09 13:46:30 · 283 阅读 · 0 评论 -
084.关于异常的一些附加内容--示例程序
stuff.adspackage Stuff is Funny_Add_Error : exception; procedure Add_One(Number : in out INTEGER); function Subtract_One(Number : INTEGER) return INTEGER;end Stuff;stuff.adbwith Ada.Text_IO;use Ada.Text_IO;package body Stuff is procedu原创 2020-05-09 13:29:02 · 298 阅读 · 0 评论 -
083.发生在声明中的异常及其处理
with Ada.Text_IO;use Ada.Text_IO;procedure Except4 is procedure Try_It is Value :constant :=8; subtype LIMIT_RANGE is Integer range 14..33; Funny :LIMIT_RANGE:=Value; begin Put_Line("We are in the try_it procedure ");原创 2020-05-09 12:58:29 · 133 阅读 · 0 评论 -
082.另一个异常处理的例子
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Except3 is procedure Divide_By_Zero(Count:Integer)is Divide_Result:Integer; begin Put("Count is"); Put(Count,3); Put(" and the answer is原创 2020-05-09 12:37:02 · 117 阅读 · 0 评论 -
081.Ada语言中常见的异常种类及其说明
1. Constraint_Error - 如果某些内容超出其分配范围,将发生这种情况。2. Program_Error - 如果我们试图违反 Ada 控制结构(如在函数底部下降而不返回),就会发生这种情况。3. Storage_Error - 如果我们通过递归调用或存储分配调用耗尽存储空间,就会发生这种情况。4. Tasking_Error - 当尝试违反规则使用某种形式的任务时,将发生这种情况。...原创 2020-05-09 12:24:44 · 326 阅读 · 0 评论 -
080.Ada语言中的自定义异常处理
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Except2 is procedure Divide_Loop(Index : in Integer)is Divide_Result:Integer; begin Put("Index is"); Put(Index,3); Put(" and the answer原创 2020-05-09 12:11:34 · 197 阅读 · 0 评论 -
079.Ada语言中的异常处理
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure Except1 is procedure Divide_Loop is Divide_Result:Integer; begin for Index in 1..8 loop Put("Index is"); Put(Index,3);原创 2020-05-09 09:57:42 · 247 阅读 · 0 评论 -
078.一个计算出生天数的小例子
-- This program will calculate the number of days old you are.-- It is a rather dumb program, but illustrates some interesting-- programming techniques. It checks all input to see that they-- are in the correct range before continuing. Since the numbe原创 2020-05-09 09:43:53 · 170 阅读 · 0 评论 -
077.定义动态字符串,并使用
dynstrng.adbpackage body DynStrng is -- The display procedure overloads the existing -- Put procedures to output a dynamic string. Note -- that the existing Put is used in this new Put.procedure Put(Input_Str原创 2020-05-09 09:37:05 · 254 阅读 · 0 评论 -
076.字符串堆栈的实现及其应用
charstack.adbpackage body CharStack is Maximum_Size : constant := 25; Stack_List : STRING(1..Maximum_Size); -- The stack itself, purposely -- defined very small. Top_Of_Stack : INTEGER := 0; -- This will always point to -- the top原创 2020-05-09 09:17:54 · 352 阅读 · 0 评论 -
075.Ada语言中的非分离式编译
with Ada.Text_IO, Ada.Float_Text_IO;use Ada.Text_IO, Ada.Float_Text_IO;procedure Adder2 is FIRST : constant := 2; LAST : constant := 7; Sum_Of_Values : FLOAT; -- Interface of Package1 package AdderPkg is type M原创 2020-05-08 19:23:07 · 159 阅读 · 0 评论 -
074.Ada语言中的package分离式编译实例
多个子程序封装在一个文件里过于庞大,且分类不清,这时就使用了程序包(package),作为一种分组机制,将子程序归类封装成独立的单元。Ada 的程序包机制主要受 Pascal 及 70 年代时的软件工程技术影响。当时很主要的一项革新就是软件包的概念。软件包使一个大程序分离成了多个单元,使软件维护更加方便,可重用性也更高,是结构化编程思想中必不可少的一部份。 &nb.原创 2020-05-08 19:07:11 · 227 阅读 · 0 评论 -
073.使用package
-- interface of adder packagepackage AdderPkg is type MY_ARRAY is array(Integer range <>)of Float; procedure Add_Em_Up(In_Dat:in MY_ARRAY; Sum :out Float)end AdderPkg;-- implementation of adder packagepackage body原创 2020-05-08 18:27:32 · 132 阅读 · 0 评论 -
072.从控制台输入字符
with Ada.Text_IO;use Ada.Text_IO;procedure CH14_1 is One_Char : CHARACTER;begin Put_Line("Input characters to display, enter Q to stop."); loop -- Read one character at a time a...原创 2020-05-08 12:59:45 · 161 阅读 · 0 评论 -
071.将字符或者文件输出到打印机
with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;procedure PrintOut is Turkey : FILE_TYPE;begin -- First we create the file Create(Tu...原创 2020-05-08 12:51:54 · 132 阅读 · 0 评论 -
070.读取整数时的需要在注意的要点
使用数字输入时还有一个细微的差别,系统不会读取行字符的末尾,因为它不知道如何跨越它。它被卡住试图读取下一个数据点,但从来没有得到它,因为行的末尾阻止它。当检测到行尾时,或在任何其他时间,可以发出函数Skip_Line,该函数告诉函数转到下一行的开头,以访问其下一个输入数据。with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Inte...原创 2020-05-08 12:48:42 · 292 阅读 · 0 评论 -
069.包含空格在内,一次性读取10个字符
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;ProcedureStringIn is My_File:File_Type; My_String :String(1..10); begin Open(My_File,In_File,"C:\Users\...原创 2020-05-08 12:31:56 · 151 阅读 · 0 评论 -
068.文件的读取
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure CharIn is My_File:File_Type; One_Char:Character; begin Open(My_File,In_File,"C:\Users\dosdios...原创 2020-05-08 12:18:54 · 226 阅读 · 0 评论 -
067.向多个文件中写入内容
with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure MultOut is Numbers,Some_Text,More_Text:File_Type; Index:Integer; begin Create(Numbers,Out...原创 2020-05-08 12:07:40 · 186 阅读 · 0 评论 -
066.向文件中写入内容
在默认情况下Put_Line(Turkey,“This is a test of turkey”);指的是向已经声明好了的文件对象输出内容,一般情况下,默认的输出指的是控制台上的输出,但是如果想要将默认的输出修改为对文件的输出,那么只需要 Set_Output(<文件对象>);,于是,在这句话下面出现的所有的put等输出语句的目标就都是文件TEST.txt,要关闭这一设置,只需要在要...原创 2020-05-08 11:48:37 · 332 阅读 · 0 评论