Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping.

Similar presentations


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:

1 ITEC 320 Lecture 3 In-class coding / Arrays

2 Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping

3 Arrays Outline Exercise Arrays

4 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

5 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;

6 Arrays Basic ideas arrayName(position) := value; Looping –for i in arrayName'range loop

7 Arrays Program Array usage

8 Arrays Types What makes up a type?

9 Arrays Types Possible set of values Operations on those values Integers –Numbers in a particular range (based on memory) –Operations (+,-,*,/,mod,rem, :=…)

10 Arrays Java How do types work in java? What compilation errors happen? What happens at run-time when things go wrong?

11 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

12 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

13 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;

14 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;

15 Arrays Java byte, short, int, long What are their relationships? Widening, is it implicit? Narrowing, is it implicit?

16 Arrays Review In-class coding Arrays Types


Download ppt "ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping."

Similar presentations


Ads by Google