mud15 - Lecture C15: Matrices Response to 'Muddiest Part of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture C15: Matrices Response to 'Muddiest Part of the Lecture Cards' (38 respondents) 1. Still don’t understand ’Length, ‘Range operators on Arrays. How do the two concepts scale for multi-dimensional arrays? (5 students) For One-Dimensional arrays, ± Array_Name’Length: gives the number of elements that can be stored in the array (number of values that the index of the array can take). ± Array_Name’Range: specifies the range Array_Name’First . . Array_Name’Last for the single dimension. Note: Array_Name’Length = Array_Name’Last – Array_Name’First + 1 For multi-dimensional arrays, ± Array_Name’Length(N): denotes the number of values of the N-th index range (zero for a null range); ± Array_Name’Range(N): specifies the range Array_Name’First(N) . . Array_Name’Last(N) for dimension-N. 2. Questions on the Concept Questions (3 students) with Ada.Text_Io; with Ada.Float_Text_Io ; with Ada.Integer_Text_IO; procedure Three_Dimension_Array is type Float_Array is array (Integer range <>, Integer range <>, Integer range <>) of Float; function Display( Value : in Float_Array ) return Float is Sum : Float := 0.0 ; N : integer; begin N := Value'Length( 1 ) * Value'Length( 2 )*Value'length( 3 ); -- Ada.Text_Io.Put(Integer'Image(N)); Ada.Text_Io.New_Line; Ada.Integer_Text_Io.Put(Value'Length( 1 ) ); Ada.Text_Io.New_Line; Ada.Integer_Text_Io.Put(Value'Length( 2 ) ); Ada.Text_Io.New_Line; Ada.Integer_Text_Io.Put(Value'Length( 3 ) ); Ada.Text_Io.New_Line;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
for I in Value' range ( 1 ) loop for J in Value' range ( 2 ) loop for K in Value' range ( 3 ) loop Sum := Sum + Value(I,J,K); Ada.Float_Text_Io.Put(Value (I,J,K)); Ada.Text_IO.Put( " , " ); end loop ; Ada.Text_IO.New_Line; end loop ; Ada.Text_IO.New_Line; end loop ; return (Sum /float(N)); end Display; A : Float_Array := ((( 1.2 , 2.3 ), ( 3.4 , 4.5 ), ( 5.6 , 7.8 )), (( 1.2 , 2.3 ), ( 3.4 , 4.5 ), ( 5.6 , 7.8 ))); begin Ada.Float_Text_Io.Put (Display(A)); Ada.Text_Io.New_Line; end Three_Dimension_Array; Note: Value here is the name of the array . It does not refer to type’Value.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

mud15 - Lecture C15: Matrices Response to 'Muddiest Part of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online