Chapter 10: Void Functions

Slides:



Advertisements
Similar presentations
User Defined Functions
Advertisements

Sub and Function Procedures
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
1.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
Chapter 6: User-Defined Functions I
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 6: User-Defined Functions I
Chapter 7: Sub and Function Procedures
Introduction to Programming with C++ Fourth Edition
Functions A function is a snippet of code that performs a specific task or tasks. You use a multitude of functions daily when you do such things as store.
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
An Introduction to Programming with C++1 Void Functions Tutorial 5.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
TK1924 Program Design & Problem Solving Session 2011/2012
Chapter 9: Value-Returning Functions
Chapter 6: User-Defined Functions I
Chapter 7: User-Defined Functions II
Value-Returning Functions
Chapter 10: Void Functions
Functions Chapter 6-Part 2.
Chapter 3: Using Methods, Classes, and Objects
Function There are two types of Function User Defined Function
Pointers and Pointer-Based Strings
User-Defined Functions
C++ for Engineers and Scientists Second Edition
User Defined Functions
Introduction to Visual Programming
Chapter 8: More on the Repetition Structure
FUNCTION CSC128.
Chapter 7: User-Defined Functions II
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Pointers and Pointer-Based Strings
Unit-1 Introduction to Java
Presentation transcript:

Chapter 10: Void Functions Introduction to Programming with C++ Fourth Edition

Objectives Create and invoke a function that does not return a value Pass information, by reference, to a function Introduction to Programming with C++, Fourth Edition

More About Functions Programmers use functions for two reasons: To avoid duplicating code in different parts of a program To allow large and complex programs to be broken into small and manageable tasks Introduction to Programming with C++, Fourth Edition

Creating Void Functions Void function - a function that does not return a value after completing its assigned task You might want to use a void function in a program simply to display information: Example: title and column headings at the top of each page in a report Introduction to Programming with C++, Fourth Edition

Creating Void Functions (continued) Introduction to Programming with C++, Fourth Edition

Creating Void Functions (continued) Differences between the syntax of a value-returning function and that of a void function: The function header in a void function begins with the keyword void, rather than with a data type The keyword void indicates that the function does not return a value The function body in a void function does not contain a return expression; statement Introduction to Programming with C++, Fourth Edition

Passing Variables Most programming languages allow you to pass to the receiving function either: The variable’s value (pass by value) Its address (pass by reference) Introduction to Programming with C++, Fourth Edition

Passing Variables by Value Introduction to Programming with C++, Fourth Edition

Passing Variables by Reference Passing a variable’s address (passing by reference) gives the receiving function access to the variable being passed You pass a variable by reference when you want the receiving function to change the contents of the variable Introduction to Programming with C++, Fourth Edition

Passing Variables by Reference (continued) To pass a variable by reference to a C++ function: Include an ampersand (&), called the address-of operator, before the name of the corresponding formal parameter in the function header Introduction to Programming with C++, Fourth Edition

Passing Variables by Reference (continued) Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference (continued) Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference (continued) salary and raiseRate: passed by value because the receiving function needs to know the values stored in the variables, but does not need to change the values raise and newSalary: passed by reference, because it is the receiving function’s responsibility to calculate the raise and new salary amounts and then store the results in these memory locations Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference (continued) Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference (continued) Introduction to Programming with C++, Fourth Edition

Passing Variables by Value and by Reference (continued) Introduction to Programming with C++, Fourth Edition

Summary Void function - a function that does not return a value after completing its assigned task Pass information by reference to a function Function can change the variable that is passed in Introduction to Programming with C++, Fourth Edition