ITEC 320 Lecture 6 More on arrays / Strings. Arrays Review Scope Exceptions Arrays –Dynamic arrays How? Typed and anonymous.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 More Syntax; Working with Objects.
Advertisements

Introduction to Java 2 Programming Lecture 5 Array and Collections.
ITEC 320 Lecture 12 Records. Intro to records Review Look_ahead(char,EOL); –What is this? –What does it allow us to do?
Slide: 1 Copyright © AdaCore Arrays Presented Quentin Ochem university.adacore.com.
ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping.
Copyright  Hannu Laine C++-programming Part 5 Strings.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
Arrays, Slices, and more. Structs  A struct is a collection of fields  The keyword type is used to declare the type of the struct  Syntax: type Vertex.
Chapter 10.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Introduction to Computers and Programming Midterm Review Sana Odeh.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Loops – While, Do, For Repetition Statements Introduction to Arrays
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
1 Arrays Chapter 13 Especially read 13.1 – 13.2 Text introduces vectors, which we will not cover, in 13.3.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
ITEC 320 Procedural Programming Dr. Ray Lecture 1.
C Static Arrays Pepper. What is an array? Memory locations – same type – next to each other (contiguous) – Same name – Indexed by position number of type.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
ITEC 320 Lecture 5 Scope Exceptions. Scope / Exceptions Review Functions Procedures.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
February 11, 2005 More Pointers Dynamic Memory Allocation.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays Part 4.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
ITEC 320 Lecture 10 Packages (2). Review Packages –What parts do they have? –Syntax?
1 Type Checking Type checking ensures that the operands and the operator are of compatible types Generalized to include subprograms and assignments Compatible.
ADT ITEC 320 Lecture 22. ADT Review Generic lists –Ada compilation workout Recursive algorithms –What would a recursive copy look like? Project 4 is up.
Array, Pointer and Reference ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
ITEC 320 Lecture 10 Examples. Review Strings –What types are there? –What are the differences? –What should you use where? Homework –Hardest part –Easiest.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
ITEC 320 Lecture 11 Application Part Deux Look Ahead.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
EE 422C Day 2 Java, Eclipse. Copyright Pearson Education, 2010 Based on slides bu Marty Stepp and Stuart Reges from
1 CS Programming Languages Class 08 September 19, 2000.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CS 31 Discussion, Week 5 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:00-1:00pm (today)
1 Semantic Analysis  Semantic analysis includes  Dynamic Checking (Those checks for which to perform, compiler doesn’t have sufficient information) 
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Introduction to programming in java Lecture 21 Arrays – Part 1.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Computer Organization and Design Pointers, Arrays and Strings in C
Chapter 6 – Data Types CSCE 343.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
Chapter 6: Data Types Lectures # 10.
CSE 303 Concepts and Tools for Software Development
CEV208 Computer Programming
Building Java Programs
CS2011 Introduction to Programming I Arrays (I)
Course Overview PART I: overview material PART II: inside a compiler
Review for Midterm 3.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

ITEC 320 Lecture 6 More on arrays / Strings

Arrays Review Scope Exceptions Arrays –Dynamic arrays How? Typed and anonymous

Arrays Issue Named type required for passing to functions / procedures procedure demo is values1: array (1.. 50) of integer; values2: array (1.. 50) of integer; begin values1 := (2 => 4, 4 => 16, 5 => 25, 3 => 9, others => 0); values2 := (others => 0); end demo; What is values 1? Can’t duplicate when passing to a function.

Arrays Comparison s type Myarray is array (1.. 3) of Integer; a, b: Myarray;... a := (10, 20, 30); b := (others => 0); if a = b then... b := a; if a = b then... Note: types must be the same Checks each element! Assignment works element by element Is this shallow or deep copying?

Arrays Java Behavior –Java references –Ada values int[] a = {10, 20, 30}; int[] b = {0, 0, 0}; if (a == b)... a = b; if (a == b)...

Arrays Attributes 'first 'last 'range 'length Why is it important to know these?

Arrays Slices Portions of the whole What are the advantages / disadvantages? How would you do this in Java? s: String := "Hi Mom!"); put(s(3.. 5) & "?"); s(4) := 'T'; put(s); s(4.. 6) := "Bob"; put(s); s(4.. 4) := "R"; put(s);

Arrays Consideration s Sending a slice to a function / procedure Can it be a constrained array? What happens when you assign slices to each other? Dynamic slice bounds (not hard coded)

Arrays Example declare s: String := "Hi Mom!"; begin put_line(s(4..7) & s(1..2)); and declare s: String := "Hi Mom!"; begin put_line(s(4..7) & s(3..3) & s(1..2)); put_line(s(4..7) & s(3) & s(1..2));

Arrays String’s What do you remember about them? Declaration? Input? Output?

Arrays Code What is the difference between s: String := “Hello World”; And s2: String(1..15);

Arrays Modification s: String := "Hi World"; begin put(s’first); put(s’last); s(4) := 'T'; put_line(s); s(4.. 6) := "Ron"; put_line(s); s := ”Bye world"; put_line(s); Issues: types must match sizes have to match

Arrays Modification(2) Combinations s: String := "Hi Mom!"; u: String(1.. 10); s := u; -- Compile error -- u := s; -- Compile error s := "Hi Bob!"; -- Okay -- s := "Hi Billy-Bob!"; -- Compile error -- s := s & "!"; -- Compile error u = s & "!!!";

Arrays Loops Why access character by character? for i in 1.. s'length loop for i in s'first.. s'last loop for i in s'range loop

Arrays Input Common usage s: String(1..10); len: Natural begin while not end_of_file loop get_line(s, len); put_line(s(1..len)); end loop;

Arrays Java Reference versus value Why do you think ADA is focused on values? String s; String t = "Mama!"; System.out.println(s); s = "today"; s = t;

Arrays Declare Want to resize a String? Use same syntax as arrays get(size); declare s3: String(1..size); begin get_line(s3, size);

Arrays Difference s What is the difference between put(v(1.. len)); put(v);

Arrays Power tools Unbounded strings (Like java) with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Unbounded_Text_IO; use Ada.Strings.Unbounded_Text_IO; procedure showUnbounded is s: Unbounded_String := "first"; begin s := "different"; s := s & "!!"; put_line(s); -- different!! end showUnbounded

Arrays Issues Stack versus heap Assignment with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Unbounded_Text_IO; use Ada.Strings.Unbounded_Text_IO;... s: Unbounded_String := "first"; t: Unbounded_String := s;... s := s & "!!"; put_line(s); -- first!! put_line(t) -- first;

Arrays Strength/We akness Fixed length Unconstrained Unbounded type string is array (Positive range) <> of Character

Arrays Summary Arrays Dynamic Copying