An Introduction to Programming with C++1 Void Functions Tutorial 5.

Slides:



Advertisements
Similar presentations
INTRODUCTORY MICROSOFT ACCESS Lesson 1 – Access Basics
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
1 Excel Lesson 1 Understanding Excel Fundamentals Microsoft Office 2010 Fundamentals Story / Walls.
Excel Understanding Excel Fundamentals Microsoft Office 2010 Fundamentals 1.
Microsoft Office 2007 Excel Web Feature Creating Web Pages Using Excel.
Microsoft Office 2007 Excel Web Feature Creating Web Pages Using Excel.
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Microsoft Office 2007 PowerPoint Web Feature Creating Web Pages Using PowerPoint.
1.
Microsoft Office 2007 Access Chapter 2 Querying a Database.
An Introduction to Programming with C++ Fifth Edition
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
String Variables Visual Basic for Applications 4.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 7: Sub and Function Procedures
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Seven Sub and Function Procedures.
A First Program Using C#
Pasewark & Pasewark Microsoft Office 2003: Introductory 1 INTRODUCTORY MICROSOFT ACCESS Lesson 1 – Access Basics.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Object Variables Visual Basic for Applications 3.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Microsoft Office 2007 PowerPoint Web Feature Creating Web Pages Using PowerPoint.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Chapter 12: How Long Can This Go On?
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Chapter 6: User-Defined Functions
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
OCC Network Drives  H:\  P:\ 
The Object Model Visual Basic for Applications 2.
Working with option button, check box, and list box controls Visual Basic for Applications 13.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Module 9: Using XML Web Services in a C# Application.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
1 After completing this lesson, you will be able to: Get around the Internet with your browser. Connect to the Internet. Print Web pages. Save Web pages.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
JavaScript 101 Lesson 6: Introduction to Functions.
1 Access Lesson 1 Understanding Access Fundamentals Microsoft Office 2010 Fundamentals Story / Walls.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
An Introduction to Programming with C++1 More on the Selection Structure Tutorial 7.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services.
Value-Returning Functions
PowerPoint Web Feature
Chapter 10: Void Functions
Access Lesson 1 Understanding Access Fundamentals
Chapter 9: Value-Returning Functions
Chapter 10: Void Functions
Presentation transcript:

An Introduction to Programming with C++1 Void Functions Tutorial 5

An Introduction to Programming with C++2 Objectives Create and invoke a function that does not return a value Pass information, by reference, to a function Pass a String variable, by value and by reference, to a function

An Introduction to Programming with C++3 Concept Lesson

An Introduction to Programming with C++4 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

An Introduction to Programming with C++5 More About Functions

An Introduction to Programming with C++6 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

An Introduction to Programming with C++7 Creating Void Functions

An Introduction to Programming with C++8 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 Creating Void Functions

An Introduction to Programming with C++9 Passing Variables Most programming languages allow you to pass to the receiving function either: –the variable’s value (pass by value) –or its address (pass by reference)

An Introduction to Programming with C++10 Passing Variables by Value

An Introduction to Programming with C++11 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 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

An Introduction to Programming with C++12 Passing Variables by Reference

An Introduction to Programming with C++13 Passing Variables by Value and by Reference

An Introduction to Programming with C++14 Passing Variables by Value and by Reference

An Introduction to Programming with C++15 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 Passing Variables by Value and by Reference

An Introduction to Programming with C++16 Passing Variables by Value and by Reference

An Introduction to Programming with C++17 Passing Variables by Value and by Reference

An Introduction to Programming with C++18 Passing Variables by Value and by Reference

An Introduction to Programming with C++19 Passing a String Variable to a Function String data type is not a fundamental data type in C++. –It is a data type that is added to the C++ language through the use of a class To pass a String variable by value to a C++ function: –use the syntax String * variablename in the function header, and the syntax String * in the function prototype To pass a String variable by reference to a C++ function: –use the syntax String *& variablename in the function header, and the syntax String *& in the function prototype

An Introduction to Programming with C++20 Passing a String Variable by value and by reference

An Introduction to Programming with C++21 Application Lesson

An Introduction to Programming with C++22 Analyzing, Planning, and Desk- checking

An Introduction to Programming with C++23 Data for first desk-check –Customer name: Joe Smith –Current reading (gallons): 9000 –Previous reading (gallons): 8000 –Rate per gallon: Data for second desk-check –Customer name: Suman Patel –Current reading (gallons): –Previous reading (gallons): 7500 –Rate per gallon: Analyzing, Planning, and Desk-checking

An Introduction to Programming with C++24 Completed Desk-check Tables

An Introduction to Programming with C++25 Coding the main() Function

An Introduction to Programming with C++26 Coding the getInput() Function The main() function will pass to the getInput() function the memory addresses of its name, current, and previous variables The getInput() function will use the following formal parameters to receive the information: –&cust –&cur –&prev

An Introduction to Programming with C++27 Code for the getInput() Function

An Introduction to Programming with C++28 Coding the calculate() Function The main() function will pass to the calculate() function: –the values of three memory locations (current, previous, and RATE) –the addresses of two memory locations (gallons and charge)

An Introduction to Programming with C++29 Code for the calculate() Function

An Introduction to Programming with C++30 Coding the displayBill() Function

An Introduction to Programming with C++31 Completing the Water Bill Program To open the partially completed C++ program: 1.Start Microsoft Visual Studio.NET. If necessary, close the Start Page window 2.Click File on the menu bar, and then click Open Solution. The Open Solution dialog box opens 3.Locate and then open the CppNet\Tut05\T5App Solution folder 4.Click T5App Solution (T5App Solution.sln) in the list of filenames, and then click the Open button 5.If the T5App.cpp source file is not displayed, right-click T5App.cpp in the Solution Explorer window, and then click Open

An Introduction to Programming with C++32 Testing the Program To test the program: 1.Save and then build the solution. Verify that the program generated no warnings 2.Execute the program. When prompted for the customer’s name, type Joe Brown and press Enter 3.When prompted for the current reading, type 9000 and press Enter. When prompted for the previous reading, type 8000 and press Enter

An Introduction to Programming with C++33 Command Prompt Window Showing the Results of the First Test

An Introduction to Programming with C++34 Testing the Program (Cont.) 4.Press Enter to close the Command Prompt window, then close the Output window 5.Execute the program again. Enter Suman Patel as the customer name, as the current reading, and 7500 as the previous reading. The Command Prompt window shows that the gallons used and the water charge are 6,500 and $11.38, respectively, which agree with the results shown earlier in the desk-check tables. 6.Press Enter to close the Command Prompt window, then close the Output window 7.Click File on the menu bar, and then click Close Solution to close the current solution 8.Click File on the menu bar, and then click Exit to exit Visual Studio.NET

An Introduction to Programming with C++35 Summary Create and invoke void functions Pass information by reference to a function –Allows function to change variable that is passed in Pass a String variable by value and by reference to a function