B065: PROGRAMMING Sub Procedures I. Starter  Identify the separate tasks to be performed in the programming task below (break it down into numbered sections).

Slides:



Advertisements
Similar presentations
Unit 6 Assignment 2 Chris Boardley.
Advertisements

Programming Logic and Design Fourth Edition, Introductory
1.
Computer Science 1620 Loops.
Algorithms. Software Development Method 1.Specify the problem requirements 2.Analyze the problem 3.Design the algorithm to solve the problem 4.Implement.
Example 2.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Algorithms. Software Development Method 1.Specify the problem requirements 2.Analyze the problem 3.Design the algorithm to solve the problem 4.Implement.
CS 201 Functions Debzani Deb.
Understanding the Mainline Logical Flow Through a Program (continued)
Starter  Identify the separate tasks to be performed in the programming task below (break it down into numbered sections).  A program is needed to prompt.
Program Design Divide and Conquer –Divide the program into separate tasks Functional Decomposition Top-Down Design –Divide an overall problem into discrete.
Code Regions and XML Comments. Code Regions The code editor automatically puts little minus signs next to the header line for each Sub or Function. You.
Introduction to Methods
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Chapter 6: Functions.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Apply Sub Procedures/Methods and User Defined Functions
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
1 Shawlands Academy Higher Computing Software Development Unit.
1 Subroutines and Functions Chapter 6 in Deitel, Deitel and Nieto.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
CS0004: Introduction to Programming Subprocedures and Modular Design.
E0001 Computers in Engineering Procedures: subprograms and functions.
LO To practice our methods of division. 11- Nov-14 Write a comment or make a statement about this prompt.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
I Power Higher Computing Software Development The Software Development Process.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
PROGRAMMING ITERATION 2. Starter  Put the following code in order (write down the line numbers).  The program should display the numbers 1-24 on screen.
Section 10.1 Confidence Intervals
22/11/ Selection If selection construct.
Sanjay Johal. Introduction(1.1) In this PowerPoint I will be explaining :  The purpose of the code for each of the two given programs, e.g. to carry.
The Software Development Process
1 CS161 Introduction to Computer Science Topic #9.
ITM © Port, Kazman 1 ITM 352 How to Think Like a Programmer.
COPYRIGHT 2010: Dr. David Scanlan, CSUS OBJECTIVES: How to write classes How to create an object from a class using the "New" keyword. How to communicate.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
Top-down approach / Stepwise Refinement & Procedures & Functions.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
04/02/ Procedures Top-down approach / Stepwise Refinement & Sub Procedures.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Algorithms and Pseudocode
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
JavaScript 101 Lesson 6: Introduction to Functions.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Algorithms and Flowcharts
JavaScript/ App Lab Programming:
COMPUTATIONAL CONSTRUCTS
MODULAR PROGRAMMING Many programs are too large to be developed by one person. programs are routinely developed by teams of programmers The linker program.
Understand the Programming Process
Chapter 4 void Functions
PROGRAMMING Sub Procedures I.
Unit 6 Assignment 2 Chris Boardley.
Understand the Programming Process
3.1 Iteration Loops For … To … Next 18/01/2019.
10.3 Procedures Function Procedures 07/06/2019.
Presentation transcript:

B065: PROGRAMMING Sub Procedures I

Starter  Identify the separate tasks to be performed in the programming task below (break it down into numbered sections).  A program is needed to prompt a user for their name and monthly wage. From this it should then calculate their yearly salary and yearly pension deductions (8% of their yearly salary). This summary should be written to file and displayed on screen.  TASKS: 1.Obtain Name and Monthly Wage 2.Calculate Salary and Deductions. 3.Write name, monthly wage, salary and deductions to file 4.Display name, monthly wage, salary and deductions on screen

Objectives Understand the importance of modular programming. Know the role of procedures within programming. Understand the concept of parameters; ByRef and ByVal Use procedures within your programming.

Modular Programming Going back to our previous sessions on Algorithms we noted that you could break things down into smaller chunks, or sub-tasks to make things easier to follow or make the problem easier to understand. This is the same case in the actual programming of an algorithm. As you add more code, your program gets longer and longer. Changing one part of a long program which is all line after line, could have devastating effects, causing the whole program to stop functioning If you wanted to re-do things over and over again. – E.g. calculate an average, display it on screen, every time a different set of numbers was entered (at different times – so a loop is no good). – Normally, you would need the same code every time you wanted to do this – This causes excessive amounts of the same code to be needed, repeatedly.

Why Go Modular Big problems are generally easier to solve if we break them up into smaller problems, for two reasons: – smaller problems are inherently easier than the larger problem of which they are a part; – a team of people can work on the smaller problems, each member concentrating on one, or just a few, of them. A procedure is the code equivalent of a solution to one of the smaller problems Code can be re-used over and over again Allows you to focus on what needs to be done, rather than how to do it. Procedures make a program easy to understand and easier to maintain.

What is a procedure? Every program you have written so far is one! A procedure, then, is a small part of a program, which has its own name, performs a specific job (usually a single task, or a small group of related tasks), and is executed when it is "asked for". Sub Main – is the one you have written everything in so far. You will have noticed your code has gradually become longer and longer – this is not good! Everything in one sub is BAD.

Declaring a Procedure Sub Name() statement(s) End Sub The word Sub is essential, and must appear exactly like that. Name is any legal VB identifier and should be chosen carefully to indicate what the procedure does. The parentheses () are also obligatory - you cannot omit them. Statement(s) represents the actual code that you write to perform the required task. End Sub (two separate words) is also essential. New Procedures can go above or below your existing Sub Main.

Writing a Procedure You should always ensure that the first thing in the code for any procedure you write is a comment which explains what the procedure does In the example here, we have declared a procedure called AverageCalc. It calculates the average and displays it on screen. Notice how it is just doing ONE job – that is calculating the average and displaying it.

Using a Procedure Call Name will result in the code for the procedure Name being executed. In Visual Studio 2008 call is not needed but it does make good sense to use it. We can call the procedure from anywhere (within our Main procedure or within other procedures). For example: Let’s look as Sub Example 1

Tasks Have a go at the classroom exercise worksheet on procedures on the intranet.

Objectives Review Understand the importance of modular programming. Know the role of procedures within programming. Understand the concept of parameters; ByRef and ByVal Use procedures within your programming.

Plenary What is meant by modular programming? Why is it important to break down a program into smaller parts – what are the benefits? What is a procedure? How do you declare them? How do you use them?