Astro 503, Spring 2006 Homework #7: Due Tuesday, Feb 28 1. Turn your complex-number class (from Homework #3) into a template so that it can have float, double, or integer-valued real and imaginary parts with appropriate instantiations. Then write a short driver program which demonstrates the ability to produce all three of these types and use them to perform some arithmetic. 2. (from Eckel) Create a base class containing a clone( ) function that returns a pointer to a copy of the current object. Derive two subclasses that override clone( ) to return copies of their specific types. In main( ), create and upcast objects of your two derived types, then call clone( ) for each and verify that the cloned copies are the correct subtypes. Experiment with your clone() function so that you return the base type, then try returning the exact derived type. Can you think of situations in which the latter approach is necessary? 3. Update the Table class that you made for homework 6 so that: a) The output value type of the table is a template parameter which defaults to double, e.g. the class defintion looks like template class Table { public: V operator()(double x) const; .... }; We will presume that the class V is capable of being interpolated, i.e. it can be multiplied by a double and can be added. b) The tabulated data is stored in a vector tv; container, using the standard-library vector<> template. (Note that TableEntry will have to be a template too.) c) Sort the table entries into ascending order of arguments after you read them from the data file, so that the file entries can be in arbitrary order. Use the sort() template that is available in #include : template void sort(RanIt first, RanIt last, Pr pred); You will have to write a predicate class for comparison of TableEntry* objects. The Standard Library sort() algorithm is documented in Josuttis and on http://www.dinkumware.com/manuals/reader.aspx?b=p/&h=algorith.html#sort 4. Our next project: a sky ephemeris program. We will produce this as a group, but you should come to Tuesday's class prepared to discuss the following issues. The first question for any software project is: what do we want it to do? I would like to be able to read in catalogs of astronomical objects, such as galaxies, stars, the Sun, the Moon, and planets. The objects are described in different ways: galaxies have fixed celestial coordinates; stars have proper motion and parallax; the orbits of Earth and the planets are specified by their ecliptic orbital elements; and the Moon has geocentric orbital elements. The brightnesses of these objects have different descriptions too. I would like to be able to know the RA, Dec, and apparent magnitude at which any of these objects can be seen at a chosen observing time. I would like to be able to list all the objects that will be within a certain (circular) patch of sky at a chosen time. (If we were working with a graphics library, this would be followed by drawing a view of the sky). I would like to be able to plot the airmass vs time of a given object as seen from a chosen Earth observatory on a chosen night. Likewise I would like to know when the evening and morning twilights will be on that night. This lets me decide what time of night that target will be observable with my telescope. These are the "use cases" for our software project. Your assignment for Tuesday is: create a list of the C++ classes you believe would be necessary to complete these tasks. Which ones are derived from or composed of others? What are the public methods required of each class? We will then merge our ideas to come up with a software design. Then we'll split up the programming responsibilities, each of us getting different classes to write.