(c)opyright Brent M. Dingle 2001

Slides:



Advertisements
Similar presentations
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Advertisements

Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
©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.
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
Mini-Pascal Compiling Mini-Pascal (MPC) language
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
FOR DOWNTO Suppose you want to write a FOR-DO loop where the control variable is decreased with each repetition of the loop. Pascal provides the reserved.
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.
CPSC Pascal Brent M. Dingle Texas A&M University Chapter 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Homework #5 New York University Computer Science Department Data Structures Fall 2008 Eugene Weinstein.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part D (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part B (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Pascal Programming Today Chapter 11 1 Chapter 11.
Top Down Design Brent M. Dingle Texas A&M University Chapter 4 – Section 1 (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Fall 2001(c)opyright Brent M. Dingle 2001 Simple Sorting Brent M. Dingle Texas A&M University Chapter 10 – Section 1 (and some from Mastering Turbo Pascal.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
A Simple Program CPSC Pascal Brent M. Dingle Texas A&M University 2001, 2002.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part C (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Fall 2001(c)opyright Brent M. Dingle 2001 Multidimensional Arrays Brent M. Dingle Texas A&M University Chapter 10 – Section 2, part B (and some from Mastering.
Fall 2001(c)opyright Brent M. Dingle 2001 Abstract Data Types (ADTs) Brent M. Dingle Texas A&M University Chapter 8 – Sections 2 and 3 (and some from Mastering.
HCR 220 Week 4 DQ 1 And DQ 2 Week 4 DQ 1 Suppose you were helping a new office file clerk who was curious about the coding process. How would you explain.
Chapter 2 – part b Brent M. Dingle Texas A&M University
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Pascal Programming Arrays and String Type.
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Python
CPSC Pascal Brent M. Dingle Texas A&M University Chapter 3
The CONST definition CONST Pi = , City = ‘New York’;
Computer Programming BCT 1113
Arrays: Checkboxes and Textareas
Brent M. Dingle Texas A&M University Chapter 6, Sections 1 and 2
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
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,
CPSC Pascal Brent M. Dingle Texas A&M University 2001, 2002
Chapter 7 Arrays.
(c)opyright Brent M. Dingle 2001
Chapter 12: Text Processing
Chapter 12: Text Processing
CMPE 152: Compiler Design September 18 Class Meeting
Brent M. Dingle Texas A&M University Chapter 12 – section 1
Turbo Pascal Units (TPU)
Procedures Brent M. Dingle Texas A&M University
Chapter 16 Pointers and Arrays
Arrays.
Arrays In this section of notes you will be introduced to a homogeneous composite type, one-dimensional arrays One-dimensional arrays in Pascal.
CIS16 Application Development and Programming using Visual Basic.net
Simple Branches and Loops
Building Java Programs
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
C++ Array 1.
To Start: 15 Points Evaluate: * 6 – 2 3(6 +2) – 2 3{6 +(3 * 4)}
Dry Run Fix it Write a program
Text Features 7th Grade Literature.
Complex Array Structures
Brent M. Dingle Texas A&M Directory Structure
Brent M. Dingle Texas A&M University Chapter 5 – Section 1
Presentation transcript:

(c)opyright Brent M. Dingle 2001 Strings Brent M. Dingle Texas A&M University Chapter 9 – Section 3 (and some from Mastering Turbo Pascal 5.5, 3rd Edition by Tom Swan) Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 Strings We have actually been using strings for some time now. So you should be familiar with how they work. A couple things you might not have discovered yet: How to index into a string How to pass a string of declared size to a procedure or function. Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 Indexing into a string Suppose we had the following: VAR name : string[30]; : name := ‘Lilly Flower’; Now how might we determine what the first letter of name is? (say we were doing something alphabetically with names) Any guesses? Fall 2001 (c)opyright Brent M. Dingle 2001

Indexing into a string (cont) As it turns out strings are ‘special’ arrays in Pascal. So we can do some neat tricks with them by treating them as arrays. So the first character of name can be found by: Writeln(name[1]); Notice this means strings start their indexing at ONE. What do you think the value of name[5] is? Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 Name[k] values For reference: name[1] = ‘L’ name[2] = ‘i’ name[3] = ‘l’ name[4] = ‘l’ name[5] = ‘y’ name[6] = ‘ ‘ that’s a space character name[7] = ‘F’ name[8] = ‘l’ : : name[12] = ‘r’ Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 Strings to procedures As you undoubtedly have discovered from the homework, the procedure declaration: procedure GetName(var name : string[40]); Fails to compile. Previously the only fix was to just say: procedure GetName(var name : string); Fall 2001 (c)opyright Brent M. Dingle 2001

Strings to procs (cont) However, now we have learned that we can use TYPEs. So declare the type: TYPE string40 = string[40]; And use the declaration: procedure GetName(var name : string40); Fall 2001 (c)opyright Brent M. Dingle 2001

String and array passing Notice similar difficulties occur when we try to pass arrays: procedure La(var grades : array [1..5] of real); Does NOT work. But with items declared as below: TYPE GRADE_ARY = array [1..5] of real; : procedure La(var grades : GRADE_ARY); It does work and all is happy time. Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 String Functions Some useful string functions in Turbo Pascal (know them, use them, lov… well, just know and use them =) concat(str1, str2, …, str[n]); pos(find_me, in_this); delete(from_me, start_pos, num_chars); insert(new_str, into_me, start_pos); length(of_me); copy(from_me, start_pos, num_chars); upcase(str); These are all explained well enough in the book. Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 Challenge Create a program that will read text from a file and replace all the occurrences of the words ‘he’ and ‘she’ with the word ‘it’. The output should be a NEW text file with the changes made. Fall 2001 (c)opyright Brent M. Dingle 2001

Suggested Probs (no grade) page 364 19 Programming pages 369 – 372 22 – do it first without arrays, then with them, then up the number of integers to 50 (instead of just 10). 23 – see if you can use an enumerated data type to index into your 5 element array. 26, 29, 31 Fall 2001 (c)opyright Brent M. Dingle 2001

(c)opyright Brent M. Dingle 2001 End Strings Chapter 9.3 And thus ends Chapter 9 Fall 2001 (c)opyright Brent M. Dingle 2001