COM1204, Summer 1998, Prof. Futrelle

Programming Assignment #1 -- The Simplest Phone System, PS1

This assignment, due Monday, July 13, is to work from the English language description of PS1 below, as well as the discussions in class, to produce your own working version of PS1.

To do this you will need to perform the following tasks:

You should explain how you went about doing the tasks and what the results were. You can use my code-form.cp file as a starting point for your work. You should also use LL extensively and your reading in M, chapters 7 and 8, for general guidance. As I said earlier, try to use a variety of the constructs that are explained early on in LL so you can master them and see their applicability. Please try to go beyond the limited set of constructs that are demonstrated in code-form.cp. Remember to paste in your test printouts at the end of your source file, so it makes one self-contained package.

Once you get the basic system working, as described below, you can do your own variations on the design to your heart's content. But please do all these variations in a separate project (just copy and rename your first one or create a new one and paste in any code you want to reuse).

Description of the system

Overview: Two phones are connected by a single link. The link has two unidirectional channels, A and B. A phone sends a message by composing a packet containing the message, e.g., a string, and places the packet in the appropriate channel of the link. The other phone receives the message by removing the packet from the link. It can then reply, etc. The test functions will construct and attach the phones and link and then "operate" the phones, and print out the status of the different objects at various stages in the process. PS1 will not use class inheritance -- that will come later, e.g., a class node with subclasses phone and switch.

You should include string from the standard library (STL) and use strings exclusively (not the old-style C strings), LL 3.4.2.

Define classes phone, link, and packet.

Define any output functions you want, or use cout << notation.

Common to all classes: It is useful for each object to have an id (an int), which is a unique identifier, assigned in sequence for each new object in a class. This is helpful for development and can be used internally by the system when it is useful to do so. Each class should have its own print function, which only needs to work correctly once everything is hooked up (it can be awkward to print internal slots that have not yet been bound to anything). All the classes typically have constructors with arguments.

A note on static strings: In phone, I included a number of static slots that are strings, such as one called message that has as its value the string "message" (the only one needed for PS1). Then, instead of placing the string "message" in a packet, I place the value of message. The reason this is useful, as I said in class, is that the compiler will catch misspellings of the slot message but not of a string "message" that you might type in. Having these strings everywhere makes everything a lot easier to read during development and testing. In a real system they would probably be replaced by simple one-byte codes.

The phone class:

The link class:

The packet class: