Advertisement
Guest User

es1_4Appello2016

a guest
Jan 21st, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<list>
  4. using namespace std;
  5.  
  6. class Nome{
  7. private:
  8.     string nome;
  9. public:
  10.     string getNome() const{
  11.         return nome;
  12.     }
  13. };
  14.  
  15. class Numero{
  16. private:
  17.     string numero;
  18. public:
  19.     string getNumero() const{
  20.         return numero;
  21.     }
  22. };
  23.  
  24. class Contatto{
  25. private:
  26.     Nome nom;
  27. public:
  28.     Nome getNome() const{
  29.         return nom;
  30.     }
  31.     virtual Contatto* clone() const =0;
  32.     virtual bool operator==(const Contatto&) const =0;
  33.     virtual ~Contatto() =default;
  34. };
  35.  
  36. class Telefonico: public Contatto{
  37. private:
  38.     Numero num;
  39.     int numSMS;
  40.     bool whatsapp;
  41. public:
  42.     Numero getNum() const{
  43.         return num;
  44.     }
  45.     Telefonico* clone() const{
  46.         return new Telefonico(*this);
  47.     }
  48.     bool operator==(const Contatto& c) const{
  49.         const Telefonico* pt=dynamic_cast<const Telefonico*>(&c);
  50.         if(pt && pt->getNum().getNumero()==num.getNumero())
  51.             return true;
  52.         return false;
  53.     }
  54.     int getNumSMS() const{
  55.         return numSMS;
  56.     }
  57.     bool hasWhatsapp() const{
  58.         return whatsapp;
  59.     }
  60. };
  61.  
  62. class Skype: public Contatto{
  63. private:
  64.     string username;
  65.     bool videochiamate;
  66. public:
  67.     string getUsername() const{
  68.         return username;
  69.     }
  70.     Skype* clone() const{
  71.         return new Skype(*this);
  72.     }
  73.     bool operator==(const Contatto& c) const{
  74.         const Skype* ps=dynamic_cast<const Skype*>(&c);
  75.         return ps && ps->getUsername()==username;
  76.     }
  77.     bool canVideochiamare() const{
  78.         return videochiamate;
  79.     }
  80. };
  81.  
  82. class Rubrica{
  83. private:
  84.     class Entry{
  85.     public:
  86.         Contatto* c;
  87.         int numTot;
  88.         Entry(Contatto* cont, int num=0): c(cont->clone()), numTot(num){}
  89.         Entry(const Entry& e):c(e.c->clone()), numTot(e.numTot){}
  90.         Entry& operator=(const Entry& e){
  91.             if(this!=&e){
  92.                 delete c;
  93.                 c=e.c->clone();
  94.                 numTot=e.numTot;
  95.             }
  96.             return *this;
  97.         }
  98.         ~Entry(){
  99.             if(c) delete c;
  100.         }
  101.     };
  102.     vector<Entry> v;
  103. public:
  104.     void insert(Contatto* c, int n){
  105.         for(unsigned int i=0;i<v.size();++i){
  106.             if(*c==*v[i].c){
  107.                 ++v[i].numTot;
  108.                 return;
  109.             }
  110.         }
  111.         v.push_back(*new Entry(c,n));
  112.     }
  113.     list<Telefonico> tel(const Nome& name, int s) const{
  114.         list<Telefonico> res;
  115.         for(unsigned int i=0;i<v.size();++i){
  116.             Telefonico* pt=dynamic_cast<Telefonico*>(v[i].c);
  117.             if(pt && pt->getNome().getNome()==name.getNome() && pt->getNumSMS()>=s)
  118.                 res.push_back(*pt);
  119.         }
  120.         return res;
  121.     }
  122.     int whatsCall() const{
  123.         int res=0;
  124.         for(unsigned int i=0;i<v.size();++i){
  125.             Telefonico* pt=dynamic_cast<Telefonico*>(v[i].c);
  126.             Skype* ps=dynamic_cast<Skype*>(v[i].c);
  127.             if((pt && pt->hasWhatsapp()) || (ps && ps->canVideochiamare()))
  128.                 ++res;
  129.         }
  130.         return res;
  131.     }
  132. };
  133.  
  134. int main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement