Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We begin our study of the debugger by investigating breakpoints, which are markers that can be set at any executable line of code. When program execution reaches a breakpoint, execution pauses, allowing you to examine the values of variables to help determine whether a logic error exists. For example, you can examine the value of a variable that stores the result of a calculation to determine whether the calculation was performed correctly. Note that attempting to set a breakpoint at a line of code that is not executable (such as a comment) will actually set the breakpoint at the next executable line of code in that function.
To illustrate the features of the debugger, we use the program listed in Fig. H.3, which creates and manipulates an object of class Account (Figs. H.1âH.2). Execution begins in main (lines 10â27 of Fig. H.3). Line 12 creates an Account object with an initial balance of $50.00. Accountâs constructor (lines 9â21 of Fig. H.2) accepts one argument, which specifies the Accountâs initial balance. Line 15 of Fig. H.3 outputs the initial account balance using Account member function getBalance. Line 17 declares a local variable withdrawalAmount, which stores a withdrawal amount read from the user. Line 19 prompts the user for the withdrawal amount, and line 20 inputs the amount into withdrawalAmount. Line 23 subtracts the withdrawal from the Accountâs balance using its debit member function. Finally, line 26 displays the new balance.