You have been asked to develop a flight simulator that will have elaborate graphical outputs. Explain why polymorphic programming could be especially effective for a problem of this nature.
What will be an ideal response?
A flight simulator most likely will involve displaying a number of different types of aircraft and objects on the screen. Suppose a programmer creates an abstract base class named FlightSimulatorObject with a pure virtual function draw. Derived classes could be created to represent the various on-screen elements, such as Airplanes, Helicopters, Towers and Runsways. Each derived class would define draw so that it displays an appropriate image for that element. Polymorphism would allow the programmer to display all the on-screen elements in the flight simulator in a generic manner (i.e., the program could invoke function draw off base class FlightSimulatorObject pointers or references to derived-class objects). The flight simulator code responsible for displaying the elements on the screen would not need to worry about the details of drawing each type of element or about incorporating new types of onscreen elements. Each derived class would handle the drawing details, and only the code that creates new objects would need to be modified to accommodate new types.
You might also like to view...
The indented statements that follow a ________ statement form a function body.
Fill in the blank(s) with the appropriate word(s).
Print the member values of element three of array b, using the variable ptr and the struc- ture pointer operator to refer to the members.
What will be an ideal response?
The comparison operator is often used with another kind of operator, the conditional operator.
Answer the following statement true (T) or false (F)
MC An object is .
a) a programming encapsulation that mimics real life objects b) a group of programmed code that is not necessarily related c) the hardware and software of the computer d) a set code that is difficult to update, but never needs changing