Procedures. This is a common situation -- there is some functionality that computers should have that the do not the solution is to write a procedure

Similar documents
What Have You Learned About Programming So Far? Expressions

Anatomy of a Function. Pick a Name. Parameters. Definition. Chapter 20: Thinking Big: Programming Functions

Functions and Procedures. Functions. Built In Functions. Built In Functions in VB FIT 100 FIT 100

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Application Note. PowerStar 5/6 - LabView VI Integration

Hands-on Lab 1: LabVIEW NI-DAQ Basics 1

20. VB Programming Fundamentals Variables and Procedures

Introduction to Programming. January Examination Paper. Time: 3 hours

FIT 100. o best you can do is start at the beginning: linear search. o It s a bit like 20 questions, but MUCH more specific.

Encapsulation in Java

Object Oriented Programming 2012

Returns & if/else. Parameters and Objects

VISUAL BASIC II CC111 INTRODUCTION TO COMPUTERS

AP Computer Science. if/else, return values. Copyright 2010 by Pearson Education

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

Iteration -- Once Is Not Enough

Void Functions Call-By-Reference Parameters Using Procedural Abstraction Testing and Debugging General Debugging Techniques

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Window (further define the behaviour of objects)

Introduction to Computer Science and Object-Oriented Programming

STAAR Category 3 Grade 7 Mathematics TEKS 7.8A/7.9A. Student Activity 1. Problem 1: The height of a prism is the distance between the two.

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Lab 2: Introduction to mydaq and LabView

A GREATER GOODS BRAND

A GREATER GOODS BRAND

How to Do Word Problems. Study of Integers

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures.

17. Introduction to Visual Basic Programming

COMP-202: Foundations of Programming

Level 3 Computing Year 2 Lecturer: Phil Smith

LSP 121. LSP 121 Math and Tech Literacy II. Topics. More VBA. More VBA. Variables

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

3. Java - Language Constructs I

3rd Grade Mathematics

CSE 1223: Introduction to Computer Programming in Java Chapter 6 Arrays

Advanced Algebra I Simplifying Expressions

COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts

For Test #1 study these problems, the examples in your notes, and the homework.

Geometry: Notes

COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9

WM-25 USER S MANUAL. Manufacturer s Declaration of Conformity

CS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications

Reasoning Through Applications

CSE 123 Introduction to Computing

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

6.2 Volumes by Disks, Washers, and Cross-Sections

COMP2421 COMPUTER ORGANZATION. Lab 3

Using Weighted Least Squares to Model Data Accurately. Linear algebra has applications across many, if not all, mathematical topics.

The Next Step. Mathematics Applications for Adults. Book Measurement

Ch02. True/False Indicate whether the statement is true or false.

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

Rationalize the Denominator: Get the root the denom. Multiply by more roots to cancel. w/ and w/

CS1004: Intro to CS in Java, Spring 2005

Chapter 3 Problem Solving and the Computer

Extending the Unit Converter

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

LAB 2.1 INTRODUCTION TO C PROGRAMMING

download instant at Introduction to C++

Chapter 3 Practice Test

Stratford upon Avon School Mathematics Homework Booklet

Using BasicX Block Data Objects with PlaySound

Defining Your Own Classes

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Object Oriented Programming with Visual Basic.Net

Exploring Python Basics

Babaria Institute of Technology Computer Science and Engineering Department Practical List of Object Oriented Programming with C

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

CS Spring 2018 Homework #5

COMP 110 Prasun Dewan 1

Exploring Python Basics

Surface Area and Volume

NO CALCULATOR ON ANYTHING EXCEPT WHERE NOTED

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Function Call Example

END-TERM EXAMINATION

Homework Problem Set Sample Solutions

FOURTH GRADE Mathematics Standards for the Archdiocese of Detroit

9 Find the area of the figure. Round to the. 11 Find the area of the figure. Round to the

Outline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014

Sub Programs. To Solve a Problem, First Make It Simpler

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

25 Questions EOG Review #1 EOG REVIEW

Understanding Addition and Subtraction Strategies Unit

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe).

Lab Sheet 4.doc. Visual Basic. Lab Sheet 4: Non Object-Oriented Programming Practice

function < name > ( < parameter list > ) { < statements >

Functions. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

CMPT 120 Introduction To Computing Science And Programming I. Pseudocode. Summer 2012 Instructor: Hassan Khosravi

HCA Tech Note 103. Expressions. Example: Conversion

ST512. Fall Quarter, Exam 1. Directions: Answer questions as directed. Please show work. For true/false questions, circle either true or false.

An-Najah National University Faculty of Engineering Electrical Engineering Department Programmable Logic Controller. Chapter 11 Math instruction

Assignment 3: Distance COP3330 Fall 2017

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Area of Triangles and Trapezoids

Full file at

Variable and Data Type I

WARM SERIES USER MANUAL 1.2

Building Java Programs

Transcription:

Procedures Procedures are familiar in everyday life -- they are a standard process for achieving some objective. Procedures in computers are similar: They are a standard process of computing some result. Procedures encapsulate computation. Scenario... You are reading email from a friend in another country who complains that the temperature is 38 o The temp is Celsius, but what is it in Fahrenheit? Why doesn t your computer have a temperature converter? This is a common situation -- there is some functionality that computers should have that the do not the solution is to write a procedure Application vs Procedure: The application is the entire facility (GUI + computation). The procedure is just the computation

Procedures Structure Procedures encapsulate, i.e. package up, a computation to be used anywhere, anytime Parts of a procedure specification Name -- term used to refer to the computation, e.g. convertc2f Definition -- the program steps to compute the result, e.g. Parameters -- the names of the input data and output results e.g. tempinc As Integer, tempinf As Integer Declaration -- the packaging of the name, definition and parameters Procedure Declaration Example: Body Mass Index The body mass index is defined as 4.89 times weight in lbs divided by height in feet squared (kg/m 2 ) What is the body mass index procedure? Name -- Definition -- Parameters -- Declaration -- Hint: Use height in inches rather than feet and inches

Example: Body Mass Index The body mass index is defined as 4.89 times weight in lbs divided by height in feet squared (kg/m 2 ) What is the body mass index procedure? Name -- findbmi Definition -- 4.89 * weightlbs / ((heightin / 12) ^ 2) Parameters -- weightlbs, heightin, bodymass Declaration -- Private Sub findbmi(weightlbs As Integer, heightin As Integer, _ bodymass As Double) bodymass = 4.89 * weightlbs / ((heightin / 12) ^ 2) Calling A Procedure The procedure declaration only specifies how a procedure works -- must be given once The procedure call says when, where and with what values the procedure will be performed (executed) -- given many places wherever affect is needed Call convertc2f(38, degreesf) is a VB procedure call specifying the procedure to be executed (convertc2f) and the values to be used (38 is the C temperature input and degreesf is the variable for the result The call says: Just do it!

Parameter Correspondence The parameters name the input values and the output results to the procedure The number of parameters in the declaration must match the number of parameters in the call, and they correspond one-to-one The parameters are referred to by separate names Formal parameters are parameters of the declaration Actual parameters are parameters of the call Call convertc2f(38, degreesf) Calling the Body Mass Procedure How do we compute the body mass for PJ who weighs 149 lbs and is 5 7 tall? Private Sub findbmi(weightlbs As Integer, heightin As Integer, _ bodymass As Double) bodymass = 4.89 * weightlbs / ((heightin / 12) ^ 2)

Calling the Body Mass Procedure How do we compute the body mass for PJ who weighs 149 lbs and is 5 7 tall? Call findbmi (149, 67, pjbmi) Private Sub findbmi(weightlbs As Integer, heightin As Integer, _ bodymass As Double) bodymass = 4.89 * weightlbs / ((heightin / 12) ^ 2) What Happens... A procedure call makes it happen Substitution Rule: The procedure call operates as if the definition replaced the call and the actual parameters replace the formal parameters Code of a VB program Call convertc2f(38, degreesf)... degreesf = 9 * 38 / 5 + 32

Adding BMI to Weight Guesser Option Explicit Dim guess As Integer Dim increment As Integer Private Sub cmdmore_click() guess = guess + increment lbllbs.caption = guess + increment Private Sub cmdless_click() increment = increment \ 10 lbllbs.caption = guess + increment If increment = 0 Then cmdmore.visible = False cmdless.visible = False lblis.visible = False lblthan.visible = False lblyour.visible = True End If Private Sub Form_Load() guess = -100 increment = 100 Summary Procedure declarations encapsulate name, parameters and definition Procedure calls cause the procedure to be executed Parameters much match in number and order The Substitution Rule defines how procedures work