Pascal Programming Arrays and String Type.

Slides:



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

Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
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:
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Chapter 10 Arrays. Topics Declaring and instantiating arrays Array element access Arrays of objects Arrays as method parameters Arrays as return values.
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
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
Pascal Programming Pascal Units, Abstract Data, Ordinals, Arrays.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
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.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Foundation Studies Course M.Montebello Arrays Foundation Studies Course.
Pascal Programming Arrays and String Type.
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?
Chapter 9 Introduction to Arrays Fundamentals of Java.
Pointers and Arrays Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Arrays Chapter 7.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
Sections 10.1 – 10.4 Introduction to Arrays
Definition of the Programming Language CPRL
Test 2 Review Outline.
EGR 2261 Unit 9 One-dimensional Arrays
Arrays Low level collections.
Computer Programming BCT 1113
© 2016 Pearson Education, Ltd. All rights reserved.
Array, Strings and Vectors
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,
Foundations of Programming: Arrays
Chapter 7 Part 1 Edited by JJ Shepherd
JavaScript: Functions.
Arrays, For loop While loop Do while loop
Visual Basic .NET BASICS
7 Arrays.
Elements of Programming Languages
Chapter 8 Arrays Objectives
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Arrays in Java What, why and how Copyright Curt Hill.
Object Oriented Programming in java
Javascript Arrays.
Can we solve this problem?
MSIS 655 Advanced Business Applications Programming
Multidimensional Arrays
Arrays ICS2O.
7 Arrays.
Chapter 8 Arrays Objectives
Arrays in Java.
Suggested self-checks: Section 7.11 #1-11
Can we solve this problem?
Chapter 9: Pointers and String
Data Structures Goal: organize data Criteria: facilitate efficient
Can we solve this problem?
Consider Write a program that prompts a user to enter the number of students and then, their names and grades. The program will then outputs the average.
Arrays and Pointers CSE 2031 Fall May 2019.
Arrays and Pointers CSE 2031 Fall July 2019.
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.