CS 509, Advanced Programming II

Spring 2001 - Test 3


  1. There are two types of comments in C++:

    1. A comment begins with the characters "//" and ends just after the first newline after the "//" characters.

    2. A comment begins with the characters "/*" and ends just after the first occurrence of the characters "*/" following the "/*" characters.

    Write an algorithm that searches a string for the first occurrence of either type of C++ comment.


    a comment fsm


  2. Give an example of how physical state differs from logical state.


    The logical state represents entities used to describe the interface to a class (or a library, or whatever), while the physical state represents the entities used to implement the interface. For example, given a stack class implemented with an array, the physical state includes the array and (possible) a index indicating the top of stack. Neither the array or the index would appear as part of the logical state.


  3. Explain the importance of class invariants.


    Class invariants describe properties of the physical state that are always true. They are important because they define the principle link between the physical state and the logical state.


  4. Explain why backwards reasoning is useful in debugging.


    When starting a debugging task, the only thing that's known is the symptoms of the problem. Successful debugging requires that the symptoms be followed backward to the cause of the problem, which can then be fixed.



This page last modified on 2 March 2001.