Pascal Subprogram Procedure Function Build in Function (e.g. Sin(x))

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 5 ( ) of Programming Languages by Ravi Sethi
James Tam Breaking Problems Down This section of notes shows you how to break down a large problem into smaller modules that are easier to implement and.
J. Michael Moore Scope & Testing Modules CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 2.
J. Michael Moore Modules: Getting information out CPSC 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
Chapter 9: Subprogram Control
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Chapter 41 Sub Procedures, Part II (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
J. Michael Moore Scope & Testing Modules CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Pointers In this section of notes you will learn about another type of variable that stores addresses rather than data.
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Block-Structured Procedural Languages Lecture 11: Dolores Zage.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Lecture 16 Pass by value vs. pass by reference (Still) Appearances are often deceiving Aesop, Fables.
CPS120: Introduction to Computer Science Decision Making in Programs.
Files Input and Output Program Payroll_Calculator; Uses Crt, Printer; Const A_Payrate = 100.0; B_Payrate = 50.0; Var SS_personnel : string[9]; First_Name,
Introduction to Pascal The Basics of Program writing.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
Pascal Programming Local Identifiers, Functions, Modularity and Data Flow.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
Pascal Programming Pointers and Dynamic Variables.
Pascal Programming Today Chapter 11 1 Chapter 11.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
User-Defined Functions (cont’d) - Reference Parameters.
5 th and 4 th ed: Chapters 9, 10, 11 SY306 Web and Databases for Cyber Operations SlideSet #7: JavaScript Functions and Arrays.
FOR LOOP STRUCTURE For := to do eg. for I := 1 to 100 do begin writeln(‘This is a loop’); end;
Definition of the Programming Language CPRL
Run-Time Environments Chapter 7
Implementing Subprograms
Chapter 6: User-Defined Functions I
The CONST definition CONST Pi = , City = ‘New York’;
Procedures and Modular Programming
FIGURE 4-10 Function Return Statements
CMPE 152: Compiler Design October 2 Class Meeting
Computer Science Procedures
Functions, Part 2 of 2 Topics Functions That Return a Value
6 Chapter Functions.
Brent M. Dingle Texas A&M University Chapter 12 – section 1
Functions, Part 2 of 3 Topics Functions That Return a Value
A function with one argument
Procedures Brent M. Dingle Texas A&M University
Chapter 6: User-Defined Functions I
CS 432: Compiler Construction Lecture 11
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
CMPE 152: Compiler Design March 7 Class Meeting
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 42 Topics Functions That Return a Value
Brent M. Dingle Texas A&M University Chapter 5 – Section 1
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Pascal Subprogram Procedure Function Build in Function (e.g. Sin(x)) Self-defined Function (out of syllabus)

A Pascal Program program Scope; var Num1, Num2, Sum : integer; begin Sum := Num1 + Num2; writeln( 'The sum is ', Sum ) end. What is the sample output ?

Using Procedure procedure FindSum; program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum; writeln( 'The sum is ', Sum ) end. What is “FindSum” ? procedure FindSum; begin Sum := Num1 + Num2 end;

Global Variables procedure FindSum; begin Sum := Num1 + Num2 end; How it works ? program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum; writeln( 'The sum is ', Sum ) end. procedure FindSum; begin Sum := Num1 + Num2 end;

Local Variables procedure FindSum; program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum; writeln( 'The sum is ', Sum ) end. Which is the local variable? procedure FindSum; var Sum : integer; begin Sum := Num1 + Num2 end;

Parameter Passing procedure FindSum( A, B:integer; program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum( Num1,Num2,Sum ); writeln( 'The sum is ', Sum ) end. procedure FindSum( A, B:integer; var C:integer); begin C := A + B end;

Formal & Actual Parameters program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum( Num1,Num2,Sum ); writeln( 'The sum is ', Sum ) end. How the data flows in and flows out? procedure FindSum( A, B:integer; var C:integer); begin C := A + B end;

Formal & Actual Parameters program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum( Num1,Num2,Sum ); writeln( 'The sum is ', Sum ) end. procedure FindSum( A, B:integer; var C:integer); begin C := A + B end; Formal vs. actual parameter

Formal & Actual Parameters If I forget to type var… program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum( Num1,Num2,Sum ); writeln( 'The sum is ', Sum ) end. procedure FindSum( A, B:integer; var C:integer); begin C := A + B end;

Value & Variable Parameters program Scope; var Num1, Num2, Sum : integer; begin Num1 := 10; Num2 := 15; FindSum( Num1,Num2,Sum ); writeln( 'The sum is ', Sum ) end. Value vs Variable parameter procedure FindSum( A, B:integer; var C:integer); begin C := A + B end;

General format of a procedure procedure heading procedure < name of procedure > (formal parameter list:data type) ; local declarations part const < constant definitions > ; type < type definitions > ; var < variable declarations > ; statement part begin < statements >; end;

Beware of …. check that a procedure must be declared and placed in the proper position of a program remember that a procedure must be ended with the reserved word END and a semicolon. match the type and order of the actual parameters to the corresponding formal parameters make sure that an actual parameter is a variable when corresponding to a variable parameter.

Further Reading and Exercises Further reading on web at home http://www.courseware.ust.hk/english/pascal_main/pascalfunction.html Homework Text book p.145, exercise 1-4 Think more, ask more, practice more,.. You would become an expert…