Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

Copyright © 2002 W. A. Tucker1 Chapter 3 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 1 - An Introduction to Computers and Problem Solving
1.
Chapter 4 General Procedures
Programming Basics Aims of Programming: –The aim of programming is to write programs to accomplish complex tasks Programming method: –functional decompositional.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 4 (cont) Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
CS 201 Functions Debzani Deb.
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
Chapter 6: User-Defined Functions I
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Programming Fundamentals (750113) Ch1. Problem Solving
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
BPC.1 Basic Programming Concepts
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
Apply Sub Procedures/Methods and User Defined Functions
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Chapter 5 - VB 2008 by Schneider1 Chapter 5 - General Procedures 5.1 Sub Procedures, Part I 5.2 Sub Procedures, Part II 5.3 Function Procedures 5.4 Modular.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Why to Create a Procedure
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Invitation to Computer Science, Java Version, Second Edition.
CS0004: Introduction to Programming Subprocedures and Modular Design.
Chapter 11 An Introduction to Visual Basic 2008 Why Windows and Why Visual Basic How You Develop a Visual Basic Application The Different Versions of Visual.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 2.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
CPS120: Introduction to Computer Science Functions.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Section 4 - Functions. All of the programs that we have studied so far have consisted of a single function, main(). However, having more than one function.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
1 5.4 Modular Design Top-Down Design Structured Programming Advantages of Structured Programming.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Top-down approach / Stepwise Refinement & Procedures & Functions.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
JavaScript 101 Lesson 6: Introduction to Functions.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
COMPUTATIONAL CONSTRUCTS
Chapter 4 - Visual Basic Schneider
Problem Solving Techniques
Programming Fundamentals (750113) Ch1. Problem Solving
CS285 Introduction - Visual Basic
Unit 6 - Subroutines.
Software Development Chapter 1.
CPS125.
Top-Down Design with Functions
Introducing Modularity
Presentation transcript:

Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)

Modular, Top-Down or Structured Program Design §Break the problem to be solved into discrete tasks: Ex:Read input Perform calculations Display output §Create a user-defined (general) procedure (or function) for each of the tasks.

Frequently asked questions about procedures in Visual Basic programs (I) §Don’t we already have procedures? l Yes: we have event procedures that are built into Visual Basic to respond to users’ interactions with the program; but we’re talking about something different here. §Where do we put the procedures we’re learning about here? l We call them from within event procedures l We create them with the Add Procedure tool

Why use procedures in Visual Basic? §Event procedures that have a lot of work to perform can become complex and difficult to understand & debug §From Section 4.4, (p. 189+): Large problems usually require large programs. §Stepwise refinement is the practice of breaking a complex problem into smaller subproblems & writing procedures to solve each subproblem

How to use procedures in Visual Basic §First, design the GUI for the program. * the driving force for GUI design is what will produce the nicest, friendliest user interface §Next, identify the event procedures that arise from the GUI. §Now, treat each event procedure as a big problem that can be broken down into smaller ones (subproblems).

Advantages of Top-down, Modular or Structured Design §Easier to write l can focus on one piece of the problem in the writing (algorithm development) phase in the testing phase l can share the work with others who work independently on different pieces of the problem l can repeatedly use the same piece of code ctd

Advantages of Top-down, Modular or Structured Design §Easier to debug l A module can be tested & debugged by itself, with no other piece of the program accomplished through the use of driver programs l A program can be tested & debugged with the introduction of each new module stub programming is used to stand in for missing procedures ctd

Advantages of Top-down, Modular or Structured Design §Easier to understand l a set of smaller subprograms is more manageable than one monolithic mass of code - both for the programmer & for others looking at the code §Easier to maintain l a set of smaller subprograms is more manageable than one monolithic mass of code - both for the original programmer & later ones

Components of Structured Programs §Modules (Procedures) l Sequences l Decisions l Iterations

Frequently asked questions about procedures in Visual Basic programs (II) §How do I get started? l design the form (GUI) all objects have been created & named l identify the work to be performed by each event procedure use general descriptions, not precise code l focus on one event procedure at a time ctd

Frequently asked questions about procedures in Visual Basic programs (III) §How do I create a procedure? l Write an event procedure with a call to a procedure. l With the code window active, select Add Procedure from the Tools menu l Type in the name of your procedure l Click on the circles next to Sub & Private l Click on OK

Procedure syntax - the Procedure Header Private Sub procedure_name (parameter_list) You choose this May be empty () or consist of several input & output parameters – we’ll see… End Sub

Procedure syntax - relating the Procedure Call & Header §From event procedure: Call mysub (argument_list) §Procedure header: Private Sub mysub (parameter_list)

Argument & parameter lists §Enable data values to be passed to and from a procedure §# arguments = # parameters §types of arguments must match types of parameters

Example: A procedure with no parameters (and, therefore, no arguments): l Within event procedure: Call MySub l In procedure definition: Private Sub Mysub () l Ex. 1, p. 143

First example of a procedure with parameters Call Firstsub (15,”abc”) ……. Private Sub Firstsub (a As Single, chstr As String) §This example involves INPUT parameters l their purpose is to supply values to procedure The arguments here are constants

More about INPUT parameters §Their corresponding arguments may be either constants or variables, or expressions involving constants and/or variables. Ex. 2, p input parameters Ex. 3, p input parameters/ several calls See page 147 Input parameters do not change value within the procedure