Presentation on theme: "ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping."— Presentation transcript:
ITEC 320 Lecture 3 In-class coding / Arrays
Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping
Arrays Outline Exercise Arrays
In-class coding 3 characters then a number Output first, X number of middle, and the last. If last character is U make uppercase Format –First NumMiddle Middle Last
Arrays First –Determine how big your array will be Second –Create a specific type for your array Third –Declare the array Size: constant Natural :=10; type Int_Array is array (1.. Size) of Integer; numbers: Int_Array;
Arrays Basic ideas arrayName(position) := value; Looping –for i in arrayName'range loop
Arrays Program Array usage
Arrays Types What makes up a type?
Arrays Types Possible set of values Operations on those values Integers –Numbers in a particular range (based on memory) –Operations (+,-,*,/,mod,rem, :=…)
Arrays Java How do types work in java? What compilation errors happen? What happens at run-time when things go wrong?
Arrays Sub-types What do you think of when you hear the word subtype? What are some ADA subtypes that we have seen before? What do you think happens when the rules of a subtype are broken? –Constraint Error
Arrays Definition Subset of the values of a type with the same operations (usually) Natural –Ignores everything < 0 in the Integer type Syntax What would you do to create the subtype NaturallyTenOrLess? subtype Natural is Integer range 1.. Integer’last
Arrays Example with ada.integer_text_io; use ada.integer_text_io; procedure foo is i: Integer; n1, n2: Natural begin get(i); n1 := i; -- fails if... get(n2); -- fails if... n1 := n1 - n2; -- fails if... i := n2; -- fails if... end foo;
Arrays Conversio n with ada.integer_text_io; use ada.integer_text_io; procedure foo is i: Integer; n1: Natural; p1: Positive; begin get(p1); -- fails if... n1 := p1; -- fails if... get(n1); -- fails if... p1 := n1; -- fails if... i := p1; n1 := i; end foo;
Arrays Java byte, short, int, long What are their relationships? Widening, is it implicit? Narrowing, is it implicit?