Lec24 - Lecture 24: Debugging PIC 10A Todd Wittman Sec 4.15...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 24: Debugging PIC 10A Todd Wittman Sec 4.15 Debugging Strategies s The first computer bug on record was an actual bug. A moth got caught in the relay switch of Harvard’s Mark III computer. •Modern bugs aren’t so literal and that makes them harder to track down. •Today we’ll discuss different strategies for tracking down and fixing bugs in your program.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Sec 4.15 : Debugging Strategies s Debugging has 3 basic steps: 1. Recognize that you’ve got bugs. 2. Track down where the bug occurs. 3. Eliminate the bug. s Some basic debugging approaches: s Run the compiler to track down compile errors s Test with reasonable and unreasonable inputs s Inserting trace messages s Assertion statements s Divide and conquer s Stepping through the debugger List the Prime Numbers #include <iostream> int main ( ) { cout << "Enter the upper limit: "; cin << n; for (int i = 1; i <= n; i ++) { if (isPrime(i)) cout << i << "\n"; } return 0; } bool isPrime (int n) { if (n==2) return true; if (n%2==0) return false; int k; while (k*k < n) { if (n%k==0) return false k = k+2; } return true; } s Print all prime numbers <= some upper limit (p.311). s First find the compile errors with the compiler (F7).
Background image of page 2
3 List the Compile Errors s By now, you’ve become very familiar with the compile errors in the Build window. s
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lec24 - Lecture 24: Debugging PIC 10A Todd Wittman Sec 4.15...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online