Assignment 5

Object-oriented design

Goals

To understand the principles of object-oriented analysis and design in C++.

Procedure

Your assignment is to explore the capabilities of C++ for capturing real-world relationships between objects in the constructs of the language. There are two objects in the problem:

1. an astronomical telescope, which can be positioned in two axes: azimuth and elevation.

2. a dome which houses the telescope and whose shutter opening must track the telescope, whatever its azimuth angle is. The telescope and dome are controlled by a program that interfaces with the motors that turn them.

1. Use these class declarations:

class dome {
private:
float azimuth; bool shutter;
public:
void move(float a) {
azimuth = a;
}
void open() { shutter = true; } }; class telescope { private: float azimuth, elevation; public: void move(float a, float e) { azimuth = a; elevation = e; } };

2. Relate the two classes in these three ways:

a. by inheritance: the "is-a" relationship;

b. by composition (or containment): the "has-a" relationship;

c. by using the friend declaration

3. In each case, show how the dome can be slaved to the telescope. What this means is that whenever the function to move the telescope is called, the corresponding dome function can be called to follow the telescope's motion. You will have to change the class declarations appropriately.

What to turn in

Three program listings each with the altered classes and a sample main program that creates the objects, as necessary, and calls the telescope's move function.

Grading

Total 30 points. Partial credit will be available for answers that are along the right lines.

Due Date

Friday, November 15th. 5:00pm.