Midterm Exam, Thursday, August 20th
This is a closed-book, closed-notes exam, 65 minutes in length. "PS" refers to our phone system, "OO" to object-oriented.
1. For simplicity, assume we have two phones, each with a connector, and directly connected to one another by a pair of wires. Since wires are such simple objects, it is possible to include a wire object directly into a connector, rather than using a pointer to a wire. That is, instead of
class Connector {
public:
static int next_id;
int id;
Wire *in;
Wire *out;
Connector();
};
We could have this, without pointers to Wire objects:
class Connector {
public:
static int next_id;
int id;
Wire in;
Wire out;
Connector();
};
Describe the complications that the second formulation might produce and why the first is a better approach.
2. Write three descriptions of the following line of code from switch.cp:
The three descriptions should be:
3. What does Meyer mean by the statement, "Real systems have no top." In your answer, discuss top-down design and the process of refinement (elaboration). Of course you may want to relate this to the phone system design and function.
4. In the PS, no instance of the class Keywords is ever created. How is this class used and how does it contribute to the modularization of the design?
5. If we added pay phones to our system, changes would have to be made in both the phones and the switches. Does this illustrate a design error on our part or not? Explain.
6. In the phone and switch, states are manipulated by altering slot values. What differences in the design would arise if each distinct state were a distinct object? Would internal boolean slots in State objects still be useful? Could parameter names such as "FFTFF" be useful? Could a member function of a State object for testing state identity, e.g.,
state_is(State *s);
be designed to use only pointer identity?