pabloliva87

Ej4C++

Feb 13th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. /** The interfaces of the talkers */
  8. class salute_interface {        /* Abstract Class */
  9.     public:
  10.     virtual void mucho_gusto () = 0;
  11.     virtual void bien_y_vos () = 0;
  12.     virtual void begin_chatter () = 0;
  13. };
  14.  
  15. class respond_interface {       /* Abstract Class */
  16.     public:
  17.     virtual void hola () = 0;
  18.     virtual void como_estas () = 0;
  19. };
  20.  
  21. /** The concrete talkers */
  22. class first_talker : public salute_interface {
  23.     private:
  24.     respond_interface * interlocutor;
  25.     bool has_greeted;
  26.     public:
  27.     void mucho_gusto () {
  28.         has_greeted = true;
  29.         cout << "Mucho gusto \n" ;
  30.         interlocutor -> como_estas ();
  31.     };
  32.     void bien_y_vos () {
  33.         if (has_greeted){
  34.             cout << "Bien, y vos? \n" ;
  35.         }
  36.     };
  37.     void begin_chatter () {
  38.         interlocutor -> hola ();
  39.     };
  40.     void initialize (respond_interface * talker) {
  41.         has_greeted = false;
  42.         interlocutor = talker;
  43.     };
  44. };
  45.  
  46. class second_talker : public respond_interface {
  47.     private:
  48.     salute_interface * interlocutor;
  49.     bool has_been_greeted;
  50.     public:
  51.     void hola () {
  52.         has_been_greeted = true;
  53.         cout << "Hola \n" ;
  54.         interlocutor -> mucho_gusto ();
  55.     };
  56.     void como_estas () {
  57.         if (has_been_greeted) {
  58.             cout << "Como estas? \n" ;
  59.             interlocutor -> bien_y_vos ();
  60.         }
  61.     };
  62.     void initialize (salute_interface * talker) {
  63.         has_been_greeted = false;
  64.         interlocutor = talker;
  65.     };
  66. };
  67.  
  68. int main (void) {
  69.  
  70.     first_talker * ft;
  71.     second_talker * st;
  72.    
  73.     ft = new (first_talker);
  74.     st = new (second_talker);
  75.    
  76.     ft -> initialize (st);
  77.     st -> initialize (ft);
  78.    
  79.     ft -> begin_chatter ();
  80.    
  81.     delete (ft);
  82.     delete (st);
  83.    
  84.     return 0;
  85.    
  86. }
Add Comment
Please, Sign In to add comment