tutorial03.pptx - CSCI 1120 Introduction to Computing Using...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI 1120 Introduction to Computing Using C++ Tutorial 3 LI, Le SHB 1013 [email protected] 1
Image of page 1

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

View Full Document Right Arrow Icon
Outline Why debugging? General debug procedure Debug with IDE (Visual Studio 2015) 2
Image of page 2
Syntax error… Your program won’t even compile… Missing semicolon ; Unbalanced parenthesis () {} Missing include statements… (#include <xyz>) Logical error Your program can be compiled, but does not work a s expected… What’s going on? Types of Error 3
Image of page 3

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

View Full Document Right Arrow Icon
1. Locate the bug What we are going to talk about… 2. Fix it! This part is up to you… I have written a "buggy" program, what should I do? 4
Image of page 4
Debugging is a methodical process of finding a nd reducing the number of bugs , or defects , in a computer program or a piece of electronic h ardware, thus making it behave as expected . Debugging 5
Image of page 5

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

View Full Document Right Arrow Icon
Make sure it is indented!!! Before Debugging Your Program 6
Image of page 6
Indent code according to program structure Inner structure => indent deeper Spaces : usually multiple of 2 / 4 Tabs: e.g. Visual Studio Use the same type of indentation throughout the whole program Don’t mix spaces and tabs Indentation int main() { int x = 0; while (x != -1) { cin >> x; if ((x % 2) == 0) { cout << x; } } return 0; } 7
Image of page 7

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

View Full Document Right Arrow Icon
Indentation is Important There is an error in both code below Which one is easier to spot? int main() { int x; cin >> x; while (x > 0) { if ((x % 2) == 0){ cout << x; x--; } } int main() { int x; cin >> x; while (x > 0) { if ((x % 2) == 0){ cout << x; x--; } } Easier to recognize Unbalanced parenthesis 8
Image of page 8
Auto Correction in VS Express 2015 VS Express 2015 can auto correct indentation EDIT -> Advanced -> Format Document 9
Image of page 9

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

View Full Document Right Arrow Icon
Auto Correction in VS Express 2015 VS Express 2015 can auto correct indentation EDIT -> Advanced -> Format Document 10
Image of page 10
Outline Why debugging?
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern