Pascal Programming Arrays and String Type.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to C Programming
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 10 Introduction to Arrays
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Programming with Collections Collections in Java Using Arrays Week 9.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Chapter 10 Arrays. Topics Declaring and instantiating arrays Array element access Arrays of objects Arrays as method parameters Arrays as return values.
1 Arrays In many cases we need a group of nearly identical variables. Example: make one variable for the grade of each student in the class This results.
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
1 Lecture 9  Arrays  Declaration  Initialization  Applications  Pointers  Declaration  The & and * operators  NULL pointer  Initialization  Readings:
Chapter 9: Arrays and Strings
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
Chapter 9 Introduction to Arrays
Arrays.
Pascal Programming Pascal Units, Abstract Data, Ordinals, Arrays.
CS0007: Introduction to Computer Programming Introduction to Arrays.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
A First Book of ANSI C Fourth Edition
Fall 2001(c)opyright Brent M. Dingle 2001 Arrays Brent M. Dingle Texas A&M University Chapter 9 – Sections 1 and 2 (and some from Mastering Turbo Pascal.
Chapter 8 Arrays and Strings
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Pascal Programming Records, Stacks & Queues. Pascal Programming Record data types—a complex type that combines different data types into a single record.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Foundation Studies Course M.Montebello Arrays Foundation Studies Course.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Computer Programming for Engineers
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
 2005 Pearson Education, Inc. All rights reserved Arrays.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to programming in java Lecture 21 Arrays – Part 1.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Windows Programming Lecture 03. Pointers and Arrays.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Pascal Programming Arrays and String Type.
EGR 2261 Unit 9 One-dimensional Arrays
Computer Programming BCT 1113
Complex data types Complex data types: a data type made of a complex of smaller pieces. Pascal has four very commonly used complex data types: strings,
Chapter 7 Part 1 Edited by JJ Shepherd
Arrays, For loop While loop Do while loop
Object Oriented Programming in java
Javascript Arrays.
Presentation transcript:

Pascal Programming Arrays and String Type

Pascal Programming The Array What if you had a list of 100 values you wanted to store. That would require 100 variables—an unwieldy solution. Instead, Pascal provides an array. The array consists of a two-part name. Part 1 stays constant and part 2 changes. continue . . .

Pascal programming Array declaration and syntax . . . type var SmallArray = array[1 .. 5] of integer; var Score: SmallArray The type after the of is the component type All five variables have this type. The variables are called indexed variables. continue . . .

Pascal Programming Inside the square brackets –array [ 1 .. 5]– is the index or index expression or subscript. The value of an indexed variable becomes an element or value of the array. Score := 1 The array is declared just like other types. type array [index_type] of component type The index_type can be an ordinal or subrange. Component_type may be any Pascal type.

Pascal Programming Once an array type has been declared . . . a particular array is declared just like other variables. In summary . . . An array variable creates the locations An array value occurs in each used location. An element of the array will be any value in it. The array index identifies locations and values in an array. An indexed variable identifies names the location.

Pascal Programming An array illustrates the structured type. Up to now, we have used simple types except string. Pascal programmers may created compound types called structured type. In Turbo Pascal, the size of the array must be declared. Thus, we must declare the largest anticipated size for the array. Partially filled arrays present problems. We solve the problem with a variable Last that marks the last location filled with a value.

Pascal Programming A move through the array can be accomplished with a for loop. This is called sequential access. The alternative is random access. When data is read in in sequence the array fills from beginning to end. Random access allows data to be placed at an indexed location.

Pascal Programming Turbo Strings A string may be thought of as an array of char. Var Caption : string [20]; Caption := ‘Seize the day’ We read into array[11] p . . . The meaning changes. continue . . .

Pascal Programming Procedures and functions can use type string. . . But the string needs to be declared as a type. Then, the string type performs like an array. String[20] is a definition but . . . String20 =string [20] is a declaration of type. Functions, delivering a value, cannot return to an array be it can to a string type.

Pascal Programming Turbo Pascal provides a variety of predefined functions and procedures to manipulate string type. Included are . . . Length returns the length of a subset of string. Pos identifies the position of a value. Upcase returns an upper case char. Delete eliminates defined values. Copy copies a subset of string.