Assignment 9, due Oct 29

Part of the homework for 22C:60, Fall 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always write your name legibly as it appears on your University ID and on the class list!

Homework

  1. Background: In your job as master of graphical computations, you have discovered that you need to manipulate a number of data points, but that in different contexts, you need different representations. You therefore determine that you will use an abstract or polymorphic class, point, with subclasses for cartesian points and polar points. Each object of any subclass of point, will begin with a pointer to the class descriptor for that subclass, where that class descriptor contains pointers to the methods for that class. The remainder of the object has a format that depends on the particular subclass.

    Given that p is some kind of point, p.setx(i) and p.sety(i) p.getx(i) and p.gety(i) access the x and y coordinates of p. These will be fast if p is a cartesian point, but slow if it is a polar points.

    Similarly, p.setr(i) and p.settheta(i) p.getr(i) and p.gettheta(i) access the r and theta coordinates of p. These will be fast if p is a polar point, but slow if it is a cartesian point.

    Note that the implementation of the cartesian point class would go in the file cartesianpoint.a and that the class descriptor for each class is a constant and therefore, the descriptor data structure for cartesian points can be part of cartesianpoint.a.

    a) Give an appropriate header file, point.h, that defines the SMAL interface to any object of the polymorphic class point. (0.5 points)

    b) Using your answer to part a) as a framework, and given that the local variable P in the current subroutine points to a point, write un-optimized SMAL Hawk code to set the x coordinate of that point to 55. (0.5 points)

    c) Give appropriate SMAL code for the class descriptor shared by all cartesian points that should be part of cartesianpoint.a. (0.5 points)

    d) Using your anwers above as a framework, give appropriate SMAL code to define the structure of a cartesian point object as seen by an outsider, appropriate to include in cartesianpoint.h, the public interface to cartesian points. (0.5 points)

    e) Using your anwers above as a framework, give appropriate SMAL code to define the complete structure of a cartesian point object as seen by an the implementation of the cartesian point subclass, appropriate to include in cartesianpoint.a. (0.5 points)

    f) Using your answers above) as a framework, write SMAL Hawk code for the setx method that would be part of cartesianpoint.a. (Writing settheta would be hard because of the need for trigonometry, but this one requires no computation. (0.5 points)