#include<iostream>
using namespace std;
class Game
{
public:
virtual void initialize() = 0;
virtual void startPlay() = 0;
virtual void endPlay() = 0;
void play()
{
initialize();
startPlay();
endPlay();
}
};
class Cricket : public Game
{
public:
void endPlay()
{
cout<<"Cricket Game Finished!\n";
}
void initialize()
{
cout<<"Cricket Game Initialized! Start playing.\n";
}
void startPlay()
{
cout<<"Cricket Game Started. Enjoy the game!\n";
}
};
class Football : public Game
{
public:
void endPlay()
{
cout<<"Football Game Finished!\n";
}
void initialize()
{
cout<<"Football Game Initialized! Start playing.\n";
}
void startPlay()
{
cout<<"Football Game Started. Enjoy the game!\n";
}
};
int main()
{
Game *game = new Cricket();
game->play();
cout<<endl;
game = new Football();
game->play();
}
|