Introduction to Computing Dr. Nadeem A Khan. Lecture 17.

Slides:



Advertisements
Similar presentations
Chapter 4 Ch 1 – Introduction to Computers and Java Flow of Control Loops 1.
Advertisements

VARIABLES AND DEBUGGING Beginning Programming. Assignment Statements  Used to hold values in a variable  Calculates a result and stores it in a variable.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
True BASIC Ch. 9 Practice Questions. What are the 4 errors? DIM arr(4) FOR X = 1 TO 4 READ arr(X) LET arr(X) = arr(X) * X PRINT What is the new Y INPUT.
1 CS 106, Winter 2009 Class 11, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Chapter 4 General Procedures
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
Introduction to Computing Dr. Nadeem A Khan. Lecture 23.
Introduction to Computing Dr. Nadeem A Khan. Lecture 22.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
Introduction to Computing Dr. Nadeem A Khan. Lecture 27.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to VB prepared by Dr. I A Moneim Reference Book Schneider.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Introduction to Computing Dr. Nadeem A Khan. Lecture 19.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Introduction to Computing Dr. Nadeem A Khan. Lecture 28.
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.
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Introduction to Computing Dr. Nadeem A Khan. Lecture 18.
Section Schneider zThis section introduces nice ways to produce input & display output: yInput boxes yMessage boxes.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Introduction to Computing Dr. Nadeem A Khan. Lecture 5.
For…Next : Nested Loop X= 0 For i = 0 To 4 For j = 0 To i-1 X=X+(i+j-1) Next j Next i How many times the inner loop is executed? What is x at the end of.
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
Hello World 2 What does all that mean?.
Chapter 2: Creating ActiveX Code Components By นภดล กมลวิลาศเสถียร Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual.
E0001 Computers in Engineering Procedures: subprograms and functions.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
1 E0001 Computers in Engineering Built in Functions.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Image task, Set and Lighting Year 11 Revision. Look at the images you have been given: Write 1 comment about the costume Write 3 descriptive words about.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
Count and add list of numbers From user input and from file.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
4 examples with counters 4 examples with number lines
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
General Procedures Chapter 4. Different Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular Design (not.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
Find a Picture of Your Book Cover w/ Title of Book and Author’s Name ABC Book By (Your Name/Your Hour)
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Computer Science and an introduction to Pascal
Chapter 6 - Visual Basic Schneider
INTERMEDIATE ALGEBRA CLASS NOTES
Sub Procedures and Functions
Controls, Properties, and Procedures
The structure of programming
Work Breakdown Structure Tasks and Sub-Tasks
CS-401 Computer Architecture and Assembly Language Programming
Algorithms Lecture #42 Dr. Sohail Aslam.
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 17

Subprograms /Subroutines

Subprograms (Contd.) ► General Format Sub SubprogrammeName (list of parameters) statements End Sub

Subprograms (Contd.) ► Example 1 Sub ExplainPurpose ( ) Rem Explain the task performed by the program Picture1.Print “This program displays sentences” Picture1.Print “identifying pairs of numbers and their sums.” End Sub

Subprograms (Contd.) ► Example 2 Sub Add ( num1 As Single, num2 As Single ) Rem Display numbers and their sum Picture1.Print “Sum of”; num1;”and”; num2; ”is”; num1+num2 End Sub

Subprograms (Contd.) ► Examples: Sub ExplainPurpose ( ) Rem Explain the task performed by the program Picture1.Print “This program displays sentences” Picture1.Print “identifying pair of numbers and their sums.” End Sub Sub Add ( num1 As Single, num2 As Single ) Rem Display numbers and their sum ► Picture1.Print “Sum of”; num1; “and”; num2; “is”; num1+num2 End Sub

Subprograms (Contd.) ► Using subprograms in a Program Sub Command1_Click( ) Rem Display the sum of several pairs of numbers Picture1.Cls Call ExplainPurpose Picture1.Print Call Add(2, 3) Call Add(4, 6) Call Add(7, 8) End Sub

Subprograms (Contd.) ► The Program’s result This program displays sentences identifying pair of numbers and their sums. Sum of 2 and 3 is 5 Sum of 4 and 6 is 10 Sum of 7 and 8 is 15

Subprograms (Contd.) ► Using subprograms in a Program Sub Command1_Click( ) Dim x As Single, y As Single, z As Single Picture1.Cls Let x = 2 Let y = 3 Call Add(x,y) Call Add(x+2, 2 * y) Let z = 7 Call Add(z, z+1) End Sub

Subprograms (Contd.) ► The Program’s result This program displays sentences identifying pair of numbers and their sums. Sum of 2 and 3 is 5 Sum of 4 and 6 is 10 Sum of 7 and 8 is 15

Subprograms (Contd.) ► Writing subprograms for a Program Sub Command_Click( ) Dim x As Single, y As Single, z As Single Picture1.Cls Call ComputeWage(“Aslam”, 5, 100) Call ComputeWage(“Saleem”, 6, 90) End Sub Result: Wage of Aslam is Rs. 500 Wage of Saleem is Rs. 540

Subprograms (Contd.) ► The Subprogram ComputeWage: Sub ComputeWage(Name As String, hourlyRate As Single, hours As Single) Rem Compute and displays employees wage Dim wage As Single wage = hourlyRate*hours Picture1. Print Name;” wage is”; wage End Sub

Note: ► Read: Schneider (Section 4.1) ► Read Comments in Section 4.1 ► Do practice problems 4.1 ► Attempt questions of Exercise 4.1