& Timothy Budd
Chapter 21 – Polymorphism
Your email address:
Your student ID number:
Once this form has been customized for your
institution, you can use this button to send your lab work. Be sure to read the instructions before starting your work.
To gain experience with
describing the information contained within a
the concept of a polymorphic variable and its
relationship to class hierarchies
the interaction between polymorphism and memory
how to distinguish between virtual and
the concept of downcasting
designing and using software frameworks
Submit all code for the shape class in the space below.
Submit all code for the house class in the space below.
P2. Moveable Cars
In this problem, you will create
two additional classes called Moveable and Car. The purpose of the Moveable
class is to serve as a base class for any object that may be drawn to the
screen at locations other than its initial position. This class has a virtual
member function named move() for updating the relative
shift of any derived object’s location. Do not implement the move() function within this class. The default constructor
should set Moveable’s protected member
variables to zero. The variables have been made protected in order to allow you
some freedom in your programming.
Derive the Car class from both
Moveable and Shape. In order to draw a car, use only four line segments. The
class definitions are provided below. The car’s inherited draw() function should draw the car object to the screen, as
was done for the house class, taking into account any stored shifts within the
Moveable class. The car constructor takes two arguments to initialize
Shape’s private variables.
Implement the inherited move() function for this class. The move()
function should increment the protected Moveable variables by the amount
specified in the function’s arguments. Therefore, if the first call to
move sets the shifts to (3,1), then the next call to
the move() function, with the arguments (-3, -1), should reset the shifts to
move(double ixShift, double iyShift)
class Car : public Shape, public
Car(double iXPos, double iYPos);
virtual void move(double ixShift,
virtual void draw();
P3. Shape Drawing
Write a small program that
creates a vector of Shape* objects. The Shape pointers should point to both
House and Car objects. Iterate through the vector and draw each object to the
screen by invoking the draw() function.
Provide your answer in the space
R4. Software Reuse
What topics covered within this programming example facilitate software
Provide your answers in the space below.
Do not forget to send your answers when you are