


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



(10 respondents)
How do you know how many bits make up a piece of data? (1 student) The number of bits is a function of its type. The Type’First and Type’Last, tell you the range of values that the data type contains. From that, you should be able to compute the number of bits used.
Does Question’Last give the last used position in the string array or just the last position possible? If it gives just the last position possible what is the point of having both Question’last and Question’Length? (1 student)
Attributes for array types T’first gives first index value for array type T T’last gives last index value for array type T T’length gives number if components in array type T T’range gives the index interval for array type T
Where T is the name of a constrained array type. Instead of a type name, the name of an object of an array type can be used:
A’first gives first index value for array A A’last gives last index value for array A A’length gives number of components in array A A’range gives the index interval for array A
First and Last are used to find the first and last index numbers in an array, they can for example be used to make a loop run through all the index values for an array.
for I in Question'First .. Question'Last loop null; end loop;
A more elegant solution is to use Range. The loop parameter will run through all the index values for the array.
for I in Question'range loop null; end loop;
The attribute Length is used to find the number of components in an array.
Put ("Number of elements in the array are: "); Put(Question'Last);
The result of the operation is dependent on how you implement the insertion operation. In the example shown above, the insertion operation may generate a run-time error because the size of array X is of static size 6 and including 4 new elements to an array of size 6 that already has 3 elements. An alternative implementation of the insertion function may just ignore X 3 , resulting in the final array appearing as shown in figure above.
with Ada.Text_Io; use Ada.Text_Io;
procedure Cp_Class_2 is Quest1 : String(1..17) := "I had to wake up "; Quest2 : String(1..16) := "at 8:00am today!"; begin Put(Quest1&Quest2); Put(); end; Except that unfortunate “Put();” which generates a compilation error (missing operand), this piece of code looks perfectly fine to me!
The Array types we have studied so far has been constrained arrays, that is, the index constraints are specified in the type declaration.
In Ada we can also declare unconstrained array types. That means, when the array is declared, the index type is specified but there is no need to state limits for the index, instead the symbol < > is used.
Boolean is the type of the returned value. The function will return true if the position of the element in wide character set is between 0 .. 255 (which is the positions present in the character set)