Pascal Programming Local Identifiers, Functions, Modularity and Data Flow.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
User Defined Functions
1) Scope a] Ada scope rules b] C scope rules 2) Parameter passing a] Ada parameter modes b) Parameter passing mechanisms COMP205 IMPERATIVE LANGUAGES 13.
Programming Languages and Paradigms
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
Chapter 10 Introduction to Arrays
An Introduction to Programming with C++ Fifth Edition
Functions Most useful programs are much larger than the programs that we have considered so far. To make large programs manageable, programmers modularize.
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Programming Languages
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Chapter 6: User-Defined Functions
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
SE: CHAPTER 7 Writing The Program
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Programming Languages and Paradigms Imperative Programming.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Prog. techniques. Standard prog. techniques Complex programs can be broken down into simpler parts called “Modules” These come in 2 types,“Procedures”
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Procedural programming in Java Methods, parameters and return values.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Pascal Programming Arrays and String Type.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
By Mr. Muhammad Pervez Akhtar
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 6: Functions.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Oracle9i Developer: PL/SQL Programming Chapter 5 Functions.
CHAPTER 8 Scope, Lifetime, and More on Functions.
JavaScript Modularity. Goals By the end of this lecture, you should … Understand why programmers use modularity. Understand how to create a function in.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS0004: Introduction to Programming
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Pascal Programming Arrays and String Type.
User-Defined Functions
Pascal Subprogram Procedure Function Build in Function (e.g. Sin(x))
UNIT V Run Time Environments.
CS 432: Compiler Construction Lecture 11
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
Scope of Identifier The Scope of an identifier (or named constant) means the region of program where it is legal to use that.
Top-Down Design with Functions
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Scope Rules.
Introducing Modularity
Presentation transcript:

Pascal Programming Local Identifiers, Functions, Modularity and Data Flow

Pascal Programming n Problem: In our procedure we want to exchange black for white. A simple exchange will not work. n So, we need Temporary for storage. n We may have used Temporary in other procedures. So, what do we do?

Pascal Programming n We declare Temporary within our procedure. n The declaration... Inside the procedure and before begin (Sound familiar?) n The declaration terminates when the procedure finishes its work.

Pascal Programming n e g: –procedure ChangeColor; {Changes one color for another} –var Temporary, Black, White : integer; –begin Temporary := Black Black := White White :=Temporary....

Pascal Programming n Variables that affect the entire program -- Global Variables n Variables that affect the procedure ONLY Local Variables n A variable of the same name may have two different uses. The local variable controls.

Pascal Programming n Local rule... Any declaration allowed in a Pascal program is allowed in a Pascal procedure. n Local identifiers make the procedure self-contained and self-sufficient. n A variable declared in a procedure... –Is local to that procedure –its meaning confined to the procedure –you need only know it when writing or using that procedure

Pascal Programming n Block...parameter list, declaration set and body of statements under their influence. n All identifiers in the block are said to be local to the block n Scope...the area of influence of an identifier--may be global or local.

Pascal Programming n Functions may be... –Predefined...sqrt, trunc and round –Programmer defined n A function call is an expression...not a statement like a procedure. n Functions return value(s). n Functions can act like procedures... But that will create unintended side-effects. Use a function for its intended purpose... creating and delivering value.

Pascal Programming n e g: n function Cube (X: integer): integer; n {returns cube of X} n begin {cube}; –Cube :=X*X*X; n end {cube};

Pascal Programming n The declaration... n Starts with the reserved word function. n Includes the type for the function in the heading. n In the body... n The function name must be on the left side of an assignment statement.

Pascal Programming n Data flow... n When we break a problem into component parts, we need to trace the data through each of the elements or sub-tasks. n We use a data flow diagram for this. n This structured diagram clarifies the role and relationship of each sub-task.

Pascal Programming Get Data Determine balance after down payment Determine monthly interest Determine length of loan Create amortization table

Pascal Programming n Data Flow Analysis... n will allow you to track the movement of data. n will help you decide whether a sub-task should be a function or a procedure. n will help a programmer test the soundness of the program.

Pascal Programming n Summary... n Local variables hold data within a procedure... Not outside of it. n Parameters should establish the interaction of a procedure with the larger program. n A formal value parameter is equal to the value held at the time of the call. Continue...

Pascal programming n When an actual variable parameter does not change a value when expected... Check the var in the parameter list. n When a sub-task requires computation of a value... Use a function. n Eliminate side-effects in functions by not making them into procedures. n Data flow analysis helps determine parameters and their type.