Hello, I got the following code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std ;
// Function Prototypes
void pause(void);
/** defines an abstract class */
class Jukebox {
public:
virtual void play() { cout << "Record unknown\n" ; }
} ;
/** defining subclasses */
class NewAge: public Jukebox {
public:
void play() { cout << "NewAge is playing\n\n" ; }
} ;
class RandB: public Jukebox {
public:
void play() { cout << "R&B is playing\n\n" ; }
} ;
class BlueGrass: public Jukebox {
public:
void play() { cout << "Blue Grass is playing\n\n" ; }
} ;
/** An entry point for program execution */
int main() {
Jukebox *pointer[3] = {new NewAge(), new RandB(), new BlueGrass()} ;
// set seed for the random generator
srand( (unsigned)time(NULL) ) ;
// runs a test
for (int i=0; i < 10; i++) {
int index = rand() % 3 ;
pointer[index]->play() ; // polymorphic funcation call
}
pause();
return 0;
}
I want to write my own set of classes with polymorphism support for a problem involving automobiles and different model of cars, such as, "Ford Mustang" and so on.
Do I just have to substitute "Jukebox", "New Age" etc.? I guess Toyota would be the main class and Yaris the subclass?