Computer Science Procedures 1-11-2018.

Slides:



Advertisements
Similar presentations
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Advertisements

Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Example 2.
Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create.
Method exercises Without IF. Setup Create one new project to hold all of these. In that project, create an empty class called WorkIt to hold all of your.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Introduction to Pascal The Basics of Program writing.
CPS120: Introduction to Computer Science Lecture 14 Functions.
David Stotts Computer Science Department UNC Chapel Hill.
1 The Evaluator. 2 Compiler vs. Interpreter Command Processing Unit The Computer Program in Low Level Machine Language Program in High Level Language.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Programming, an introduction to Pascal
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
CS0004: Introduction to Programming
Lesson #6 Modular Programming and Functions.
Lesson #6 Modular Programming and Functions.
FIGURE 4-10 Function Return Statements
Lesson #6 Modular Programming and Functions.
Chapter 6 Sub Procedures
FIGURE 4-10 Function Return Statements
Java Enter your code from FRQ to Shell
Functions, Part 2 of 2 Topics Functions That Return a Value
How can you model playing rock-paper-scissors?
Computer Science 2 Review the Bubble Sort
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
A function with one argument
Computer Science 2 Getting an unknown # of …. Into an array.
Pascal Subprogram Procedure Function Build in Function (e.g. Sin(x))
Computer Science
Introduction to Programming
Selection Statements.
FIGURE 4-10 Function Return Statements
Procedures Brent M. Dingle Texas A&M University
Lecture 13 - Assignment and the environments model Chapter 3
6.001 SICP Environment model
Computer Science 1 Warm-up: True/False Dry Run
Computer Science
Lesson #6 Modular Programming and Functions.
Computer Science 1 Online time for Graphics Program Random review
Computer Science II Second With files.
Computer Science 2 Take out a piece of paper for the following dry runs. Label It Recursive Dry Runs 4/12/2018. It will be turned in when completed
Computer Science Procedures Day 2.
Computer Science Procedures Day 2.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Computer Science
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
Single-Result Functions & Modularity
Computer Science
FIGURE 4-10 Function Return Statements
How can you model playing rock-paper-scissors?
Introduction to Programming
Computer Science 1 while
Dry Run Fix it Write a program
Programming Concepts and Database
Computer Science And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and.
CPS125.
Programming Techniques
Presentation transcript:

Computer Science Procedures 1-11-2018

Learning Objectives Review procedures Practice reading programs that have procedures. Going through the Dry Runs from the Worksheet Practice writing a code using procedures with Bubble Diagrams.

Matching. Number you paper 1 - 8 The part of code that defines the procedure name and the parameters. The information in the call statement that is sent to the procedure. A variable defined inside a procedure. A sub program. Variables defined in the main body The line of code in the main body that will start the procedure. A parameter that can change the value of its corresponding argument. A parameter that cannot change the value of its corresponding argument. Procedures Call statements Headers Variable parameters Value parameters Arguments Local Variables Global Variables

begin {Of the main body} a:=2; b:=3; c:=4; writeln(a,b,c); Write the Global Variable names at the bottom For each procedure, write the parameters and local variables. Write boxes under the value parameters, and arrows under the variable parameters. Dry run the program program confusion1; //Dry Run var a,b,c:integer; procedure first(a,b:integer; var e:integer); c:integer; begin c:=a+b; writeln(a,b,c); e:=c+a; end; procedure second(var c:integer; b:integer); a:integer; a:=c+b; begin {Of the main body} a:=2; b:=3; c:=4; writeln(a,b,c); first(c,b,a); second(a,b); end.

procedure d(var a,b:integer; f:integer); c:integer; begin c:=a+b; program confusion2; var a,b,c:integer; procedure d(var a,b:integer; f:integer); c:integer; begin c:=a+b; writeln(a,b,c, f); f:=c+a; end; procedure e(c:integer; var b:integer); a:integer; a:=c+b; writeln(a,b,c); Write the Global Variable names at the bottom For each procedure, write the parameters and local variables. Write boxes under the value parameters, and arrows under the variable parameters. Dry run the program begin {Of the main body} a:=3; b:=21; c:=16; writeln(a,b,c); d(c,b,a); e(a,b); end.

procedure a(var b,c:integer); var d:integer; begin d:=b+c; c:=b + 10; Program Confusion3; procedure a(var b,c:integer); var d:integer; begin d:=b+c; c:=b + 10; writeln(b,c,d); end; procedure e(var f:integer; g:integer); f:= 2*g; writeln(f,g); a(g,f); Write the Global Variable names at the bottom For each procedure, write the parameters and local variables. Write boxes under the value parameters, and arrows under the variable parameters. Dry run the program var x,y,z:integer; begin x:=4; y:=6; z:=8; writeln(x,y,z); a(x,y); e(y,z); end.

Programming with Procedures: Bubble Diagrams Input: In the main body. Two integer values Process: Write a procedure that will be sent two integer scores and return in the scores in order. So if they are already in order, or have the same value they are not switched, if they are not in the same order, then they are switched. Output: In the main body. The numbers in order.   2) Input: In the main body, two positive integers Process/Output: Write a procedure that sent two integers and shows (writeln) the result of the first integer raised to the second integer’s power. Example: Sent, 2 and 3 it will show 2^3 = 8 3) Write a procedure that is sent nothing, but the procedure will get an unknown number of positive scores and return the average and the range of scores entered. (Note, return and average and range of -1 if no scores are entered in the procedure.) 10, 20, 12, 15, 18, 5, 4 Will return 84/7 = 12 for the average And 20 – 4 = 16 for the range