Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Section H.2. Breakpoints and the Continue Command

H.2. Breakpoints and the Continue Command

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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint