chapter2 - CHAPTER 2 Program Correctness and Efciency...

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

CHAPTER 2 Program Correctness and Efficiency
Image of page 1

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

Chapter Objectives To understand the differences between the three categories of program errors To understand what it means to throw an exception and how to throw an exception in a function To understand the effect of an uncaught exception and why you should catch exceptions To learn how to catch and process exceptions To understand different testing
Image of page 2
Chapter Objectives (cont.) To learn how to write special functions to test other functions and classes To become familiar with debugging techniques and debugger programs To be introduced to the process of program verification, and the use of assertions and loop invariants To understand the meaning of big- O notation and how it is used to analyze an algorithm's efficiency
Image of page 3

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

Section 2.1 Program Defects and "Bugs"
Image of page 4
Program Defects and "Bugs" Defects that occur in software products after delivery can produce undesirable and sometimes disastrous results Testing is used to show that a program is correct, but it is difficult to determine how much testing needs to be done testing can never demonstrate the complete absence of defects complete testing in some environments (missile control software, nuclear power plant controls) is very difficult
Image of page 5

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

Program Defects and "Bugs" (cont.) The term "bug" is used to refer to a software defect, but many professionals feel that the term "bug" trivializes defects that can have serious consequences Debugging is a commonly used term for removing defects A debugger is a testing tool that helps find defects It is much easier to eliminate defects by careful design than through testing You may encounter three kinds of defects or errors Syntax errors Run-time errors or exceptions Logic errors
Image of page 6
Syntax Errors Syntax errors are mistakes in using the grammar (syntax) of the C++ language The C++ compiler will detect most syntax errors during compilation Some common syntax errors: Omitting or misplacing braces that bracket compound statements Invoking a member function that is not defined for the object to which it is applied Not declaring a variable before using it Providing multiple declarations of a variable Not assigning a value to a local variable before referencing it Not returning a value from a function whose result type is not void
Image of page 7

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

Syntax Errors (cont.) Unfortunately, the compiler may not detect syntax errors that are the result of typographical errors Typographical errors, such as using = when you intended to use == , may be valid syntax, but will not produce the intended result (In the case of = instead of == , the result is assignment instead of comparison) Because a syntactically correct program can contain errors, careful review and testing are essential
Image of page 8
Run-time Errors Run-time errors occur during program execution A run-time error occurs when the computer or the C++ run-time library detects an operation that it knows to be incorrect
Image of page 9

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

Image of page 10
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '08
  • GIRAUD
  • Cont

{[ 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