Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Similar documents
Chapter void Functions. Overview. Functions for All Subtasks. void-functions. Using a void-function. void-function Definition

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Call- by- Reference Func0ons Procedural Abstrac0ons Numerical Conversions CS 16: Solving Problems with Computers I Lecture #9

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

CS 11 C track: lecture 1

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Python Programming: An Introduction to Computer Science

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

. Written in factored form it is easy to see that the roots are 2, 2, i,

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Python Programming: An Introduction to Computer Science

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms

Computers and Scientific Thinking

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

Ones Assignment Method for Solving Traveling Salesman Problem

Definitions. Error. A wrong decision made during software development

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

CMPT 125 Assignment 2 Solutions

From last week. Lecture 5. Outline. Principles of programming languages

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

1.8 What Comes Next? What Comes Later?

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

C++ Basics - 3 Rahul

The VSS CCD photometry spreadsheet

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

IMP: Superposer Integrated Morphometrics Package Superposition Tool

Floristic Quality Assessment (FQA) Calculator for Colorado User s Guide

Algorithm. Counting Sort Analysis of Algorithms

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

Parabolic Path to a Best Best-Fit Line:

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

SD vs. SD + One of the most important uses of sample statistics is to estimate the corresponding population parameters.

EVALUATION OF TRIGONOMETRIC FUNCTIONS

Performance Plus Software Parameter Definitions

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

Term Project Report. This component works to detect gesture from the patient as a sign of emergency message and send it to the emergency manager.

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only

9 x and g(x) = 4. x. Find (x) 3.6. I. Combining Functions. A. From Equations. Example: Let f(x) = and its domain. Example: Let f(x) = and g(x) = x x 4

Customer Portal Quick Reference User Guide

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

Programmer-Defined Functions

NTH, GEOMETRIC, AND TELESCOPING TEST

Creating Test Harnesses and Starter Applications

ENGI 4421 Probability and Statistics Faculty of Engineering and Applied Science Problem Set 1 Descriptive Statistics

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

CIS 121. Introduction to Trees

UNIT 4 Section 8 Estimating Population Parameters using Confidence Intervals

Analysis of Algorithms

The Magma Database file formats

Behavioral Modeling in Verilog

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Lecture 1: Introduction and Strassen s Algorithm

Evaluation scheme for Tracking in AMI

The isoperimetric problem on the hypercube

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Big-O Analysis. Asymptotics

Lecture 18. Optimization in n dimensions

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows:

EM375 STATISTICS AND MEASUREMENT UNCERTAINTY LEAST SQUARES LINEAR REGRESSION ANALYSIS

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

Fundamentals of Media Processing. Shin'ichi Satoh Kazuya Kodama Hiroshi Mo Duy-Dinh Le

Math 3201 Notes Chapter 4: Rational Expressions & Equations

Weston Anniversary Fund

Creating Exact Bezier Representations of CST Shapes. David D. Marshall. California Polytechnic State University, San Luis Obispo, CA , USA

OCR Statistics 1. Working with data. Section 3: Measures of spread

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004

How do we evaluate algorithms?

One advantage that SONAR has over any other music-sequencing product I ve worked

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions

CSCI 123 Introduction to Programming Concepts in C++

Package RcppRoll. December 22, 2014

Lecture 6. Lecturer: Ronitt Rubinfeld Scribes: Chen Ziv, Eliav Buchnik, Ophir Arie, Jonathan Gradstein

FURTHER INTEGRATION TECHNIQUES (TRIG, LOG, EXP FUNCTIONS)

Transcription:

Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig 5.5 Geeral Debuggig Techiques Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-3

5.1 void Fuctios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

void-fuctios I top-dow desig, a subtask might produce No value (just iput or output for example) Oe value More tha oe value We have see how to implemet fuctios that retur oe value A void-fuctio implemets a subtask that returs o value or more tha oe value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-5

void-fuctio Defiitio Two mai differeces betwee void-fuctio defiitios ad the defiitios of fuctios that retur oe value Keyword void replaces the type of the value retured void meas that o value is retured by the fuctio The retur statemet does ot iclude ad expressio Example: void show_results(double f_degrees, double c_degrees) { usig amespace std; cout << f_degrees << degrees Fahreheit is euivalet to << edl << c_degrees << degrees Celsius. << edl; retur; } Display 5.1 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-6

Usig a void-fuctio void-fuctio calls are executable statemets They do ot eed to be part of aother statemet They ed with a semi-colo Example: show_results(32.5, 0.3); NOT: cout << show_results(32.5, 0.3); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-7

void-fuctio Calls Mechaism is early the same as the fuctio calls we have see Argumet values are substituted for the formal parameters It is fairly commo to have o parameters i void-fuctios I this case there will be o argumets i the fuctio call Statemets i fuctio body are executed Optioal retur statemet eds the fuctio Retur statemet does ot iclude a value to retur Retur statemet is implicit if it is ot icluded Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-8

Example: Covertig Temperatures The fuctios just developed ca be used i a program to covert Fahreheit temperatures to Celcius usig the formula C = (5/9) (F 32) Do you see the iteger divisio problem? Display 5.2 (1) Display 5.2 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-9

void-fuctios Why Use a Retur? Is a retur-statemet ever eeded i a void-fuctio sice o value is retured? Yes! What if a brach of a if-else statemet requires that the fuctio eds to avoid producig more output, or creatig a mathematical error? void-fuctio i Display 5.3, avoids divisio by zero with a retur statemet Display 5.3 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-10

The Mai Fuctio The mai fuctio i a program is used like a void fuctio do you have to ed the program with a retur-statemet? Because the mai fuctio is defied to retur a value of type it, the retur is eeded C++ stadard says the retur 0 ca be omitted, but may compilers still require it Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-11

Sectio 5.1 Coclusio Ca you Describe the differeces betwee voidfuctios ad fuctios that retur oe value? Tell what happes if you forget the returstatemeti a void-fuctio? Distiguish betwee fuctios that are used as expressios ad those used as statemets? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-12

5.2 Call-By-Referece Parameters Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Call-by-Referece Parameters Call-by-value is ot adequate whe we eed a sub-task to obtai iput values Call-by-value meas that the formal parameters receive the values of the argumets To obtai iput values, we eed to chage the variables that are argumets to the fuctio Recall that we have chaged the values of formal parameters i a fuctio body, but we have ot chaged the argumets foud i the fuctio call Call-by-referece parameters allow us to chage the variable used i the fuctio call Argumets for call-by-referece parameters must be variables, ot umbers Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-14

Call-by-Referece Example void get_iput(double& f_variable) { usig amespace std; cout << Covert a Fahreheit temperature << to Celsius.\ << Eter a temperature i Fahreheit: ; ci >> f_variable; } & symbol (ampersad) idetifies f_variable as a call-by-referece parameter Used i both declaratio ad defiitio! Display 5.4 (1) Display 5.4 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-15

Call-By-Referece Details Call-by-referece works almost as if the argumet variable is substituted for the formal parameter, ot the argumet s value I reality, the memory locatio of the argumet variable is give to the formal parameter Whatever is doe to a formal parameter i the fuctio body, is actually doe to the value at the memory locatio of the argumet variable Display 5.5 (1) Display 5.5 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-16

Call Comparisos Call By Referece vs Value Call-by-referece The fuctio call: f(age); Memory Name Locatio Cotets Call-by-value The fuctio call: f(age); age 1001 34 iitial 1002 A hours 1003 23.5 1004 void f(it& ref_par); void f(it var_par); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-17

Example: swap_values void swap(it& variable1, it& variable2) { it temp = variable1; variable1 = variable2; variable2 = temp; } If called with swap(first_um, secod_um); first_um is substituted for variable1 i the parameter list secod_um is substituted for variable2 i the parameter list temp is assiged the value of variable1 (first_um) sice the ext lie will loose the value i first_um variable1 (first_um) is assiged the value i variable2 (secod_um) variable2 (secod_um) is assiged the origial value of variable1 (first_um) which was stored i temp Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-18

Mixed Parameter Lists Call-by-value ad call-by-referece parameters ca be mixed i the same fuctio Example: void good_stuff(it& par1, it par2, double& par3); par1 ad par3 are call-by-referece formal parameters Chages i par1 ad par3 chage the argumet variable par2 is a call-by-value formal parameter Chages i par2 do ot chage the argumet variable Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-19

Choosig Parameter Types How do you decide whether a call-by-referece or call-by-value formal parameter is eeded? Does the fuctio eed to chage the value of the variable used as a argumet? Yes? Use a call-by-referece formal parameter No? Use a call-by-value formal parameter Display 5.6 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-20

Iadvertet Local Variables If a fuctio is to chage the value of a variable the correspodig formal parameter must be a call-by-referece parameter with a ampersad (&) attached Forgettig the ampersad (&) creates a call-by-value parameter The value of the variable will ot be chaged The formal parameter is a local variable that has o effect outside the fuctio Hard error to fid it looks right! Display 5.7 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-21

Sectio 5.2 Coclusio Ca you Write a void-fuctio defiitio for a fuctio called zero_both that has two referece parameters, both of which are variables of type it, ad sets the values of both variables to 0. Write a fuctio that returs a value ad has a call-by-referece parameter? Write a fuctio with both call-by-value ad call-by-referece parameters Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-22

5.3 Usig Procedural Abstractio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Usig Procedural Abstractio Fuctios should be desiged so they ca be used as black boxes To use a fuctio, the declaratio ad commet should be sufficiet Programmer should ot eed to kow the details of the fuctio to use it Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-24

Fuctios Callig Fuctios A fuctio body may cotai a call to aother fuctio The called fuctio declaratio must still appear before it is called Fuctios caot be defied i the body of aother fuctio Example: void order(it& 1, it& 2) { if (1 > 2) swap_values(1, 2); } swap_values called if 1 ad 2 are ot i ascedig order After the call to order, 1 ad 2 are i ascedig order Display 5.8 (1) Display 5.8 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-25

Pre ad Postcoditios Precoditio States what is assumed to be true whe the fuctio is called Fuctio should ot be used uless the precoditio holds Postcoditio Describes the effect of the fuctio call Tells what will be true after the fuctio is executed (whe the precoditio holds) If the fuctio returs a value, that value is described Chages to call-by-referece parameters are described Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-26

swap_values revisited Usig precoditios ad postcoditios the declaratio of swap_values becomes: void swap_values(it& 1, it& 2); //Precoditio: variable1 ad variable 2 have // bee give values // Postcoditio: The values of variable1 ad // variable2 have bee // iterchaged Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-27

Fuctio celsius Precoditios ad postcoditios make the declaratio for celsius: double celsius(double fareheit); //Precoditio: fahreheit is a temperature // expressed i degrees Fahreheit //Postcoditio: Returs the equivalet temperature // expressed i degrees Celsius Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-28

Why use precoditios ad postcoditios? Precoditios ad postcoditios should be the first step i desigig a fuctio specify what a fuctio should do Always specify what a fuctio should do before desigig how the fuctio will do it Miimize desig errors Miimize time wasted writig code that does t match the task at had Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-29

Case Study Supermarket Pricig Problem defiitio Determie retail price of a item give suitable iput 5% markup if item should sell i a week 10% markup if item expected to take more tha a week Iput 5% for up to 7 days, chages to 10% at 8 days The wholesale price ad the estimate of days util item sells Output The retail price of the item Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-30

Supermarket Pricig: Problem Aalysis Three mai subtasks Iput the data Compute the retail price of the item Output the results Each task ca be implemeted with a fuctio Notice the use of call-by-value ad call-by-referece parameters i the followig fuctio declaratios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-31

Supermarket Pricig: Fuctio get_iput void get_iput(double& cost, it& turover); //Precoditio: User is ready to eter values // correctly. //Postcoditio: The value of cost has bee set to // the wholesale cost of oe item. // The value of turover has bee // set to the expected umber of // days util the item is sold. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-32

Supermarket Pricig: Fuctio price double price(double cost, it turover); //Precoditio: cost is the wholesale cost of oe // item. turover is the expected // umber of days util the item is // sold. //Postcoditio: returs the retail price of the item Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-33

Supermarket Pricig: Fuctio give_output void give_output(double cost, it turover, double price); //Precoditio: cost is the wholesale cost of oe item; // turover is the expected time util sale // of the item; price is the retail price of // the item. //Postcoditio: The values of cost, turover, ad price // bee writte to the scree. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-34

Supermarket Pricig: The mai fuctio With the fuctios declared, we ca write the mai fuctio: it mai() { double wholesale_cost, retail_price; it shelf_time; get_iput(wholesale_cost, shelf_time); retail_price = price(wholesale_cost, shelf_time); give_output(wholesale_cost, shelf_time, retail_price); retur 0; } Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-35

Supermarket Pricig: Algorithm Desig -- price Implemetatios of get_iput ad give_output are straightforward, so we cocetrate o the price fuctio pseudocode for the price fuctio If turover <= 7 days the retur (cost + 5% of cost); else retur (cost + 10% of cost); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-36

Supermarket Pricig: Costats for The price Fuctio The umeric values i the pseudocode will be represeted by costats Cost double LOW_MARKUP = 0.05; // 5% Cost double HIGH_MARKUP = 0.10; // 10% Cost it THRESHOLD = 7; // At 8 days use //HIGH_MARKUP Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-37

Supermarket Pricig: Codig The price Fuctio The body of the price fuctio { if (turover <= THRESHOLD) retur ( cost + (LOW_MARKUP * cost) ) ; else retur ( cost + ( HIGH_MARKUP * cost) ) ; } Display 5.9 (1) See the complete program i Display 5.9 (2) Display 5.9 (3) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-38

Supermarket Pricig : Program Testig Testig strategies Use data that tests both the high ad low markup cases Test boudary coditios, where the program is expected to chage behavior or make a choice I fuctio price, 7 days is a boudary coditio Test for exactly 7 days as well as oe day more ad oe day less Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-39

Sectio 5.3 Coclusio Ca you Defie a fuctio i the body of aother fuctio? Call oe fuctio from the body of aother fuctio? Give precoditios ad postcoditios for the predefied fuctio sqrt? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-40

5.4 Testig ad Debuggig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Testig ad Debuggig Fuctios Each fuctio should be tested as a separate uit Testig idividual fuctios facilitates fidig mistakes Driver programs allow testig of idividual fuctios Oce a fuctio is tested, it ca be used i the driver program to test other fuctios Fuctio get_iput is tested i the driver program of ad Display 5.10 (1) Display 5.10 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-42

Stubs Whe a fuctio beig tested calls other fuctios that are ot yet tested, use a stub A stub is a simplified versio of a fuctio Stubs are usually provide values for testig rather tha perform the iteded calculatio Stubs should be so simple that you have cofidece they will perform correctly Fuctio price is used as a stub to test the rest of the supermarket pricig program i ad Display 5.11 (1) Display 5.11 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-43

Rule for Testig Fuctios Fudametal Rule for Testig Fuctios Test every fuctio i a program i which every other fuctio i that program has already bee fully tested ad debugged. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-44

Sectio 5.4 Coclusio Ca you Describe the fudametal rule for testig fuctios? Describe a driver program? Write a driver program to test a fuctio? Describe ad use a stub? Write a stub? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-45

5.5 Geeral Debuggig Techiques Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Geeral Debuggig Techiques Stubs, drivers, test cases as described i the previous sectio Keep a ope mid Do t assume the bug is i a particular locatio Do t radomly chage code without uderstadig what you are doig util the program works This strategy may work for the first few small programs you write but is doomed to failure for ay programs of moderate complexity Show the program to someoe else Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-47

Geeral Debuggig Techiques Check for commo errors, e.g. Local vs. Referece Parameter = istead of == Localize the error This temperature coversio program has a bug Display 5.12 Narrow dow bug usig cout statemets Display 5.13 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 1-48

Geeral Debuggig Techiques Use a debugger Tool typically itegrated with a developmet eviromet that allows you to stop ad step through a program lie-by-lie while ispectig variables The assert macro Ca be used to test pre or post coditios #iclude <cassert> assert(boolea expressio) If the boolea is false the the program will abort Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-49

Assert Example Deomiator should ot be zero i Newto s Method Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-50

Sectio 5.5 Coclusio Ca you Recogize commo errors? Use the assert macro? Debug a program usig cout statemets to localize the error? Debug a program usig a debugger? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-51

Chapter 5 -- Ed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-52

Display 5.1 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-53

Display 5.2 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-54

Display 5.2 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-55

Display 5.3 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-56

Display 5.4 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-57

Display 5.4 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-58

Display 5.5 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-59

Display 5.5 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-60

Display 5.6 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-61

Display 5.7 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-62

Display 5.8 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-63

Display 5.8 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-64

Display 5.9 (1/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-65

Display 5.9 (2/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-66

Display 5.9 (3/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-67

Display 5.10 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-68

Display 5.10 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-69

Display 5.11 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-70

Display 5.11 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-71

Display 5.12 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-72

Display 5.13 (1 of 2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-73

Display 5.13 (2 of 2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 5-74