Name: Sample Solution UMBC Username: answer@umbc.edu 1. In your design, how is the grid of the race course represented? What are the advantages of this representation? In my design, the race course grid is represented as a two dimensional array of type int. The 2D array is declared using the maximum size of the race course given by the constants MaxRows and MaxCols. (Two additional rows and columns are added to the array to allow me to store the "walls" of the race course.) The main advantage of this representation is its simplicity --- it does not need to use the vector class or allocate memory dynamically. Cars in the race course are stored as the car number, walls are represented as -1 and a blank space is stored as a 0. ----------------------------------------------------------------------- 2. In your design, where is the position of a car stored? in the Car object? or in the RaceCourse object? or both? In my design, the RaceCourse object stores the location of each car --- in an array of Positions. ----------------------------------------------------------------------- 3. In your design, where is the fuel level of a car stored? How is it updated after a car moves? The fuel level is stored in the Car object. The "Zoom" functions must update the fuel level after it determines from the RaceCourse object how far it is allowed to move in the specified direction. ----------------------------------------------------------------------- 4. Suppose the main program asks Car #1 to ZoomDown(). How does Car #1 know how far to move? Presumably a RaceCourse method must be invoked. What is the syntax of such an invocation from a Car member function? The Car object calls a RaceCourse member function called MoveMe. The prototype of MoveMe is: unsigned int MoveMe(unsigned int CarIndex, unsigned int max, int xinc, int yinc) ; So, MoveMe() knows which car wants to be moved, the maximum number of steps to move, and the direction to move (given by xinc and yinc). MoveMe() consults the 2D grid stored in the RaceCourse object to determine the number of steps that the car can move before running into something or exceeding the maximum number of steps. This number is the return value from MoveMe(). The invocation of MoveMe() from ZoomLeft() has the syntax: fuelUsed = Rptr->MoveMe(index, FuelLevel, 0, -1) ; where Rptr is the pointer to the RaceCourse. ----------------------------------------------------------------------- 5. In your design, how is the STALEMATE race status determined? In my design, I take advantage of the fact that the race course's status can only change from the STARTED to something else. The change from WAITING to STARTED must be done by StartRace(). If the race ever enters FINISHED or STALEMATE, it can never change to something else. So my GetRaceStatus() function checks if the previous status (stored in the data member Status) is STARTED. If so, it checks every car's fuel level. If they are all zero, then STALEMATE is stored in Status and returned.