Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<list>
- using namespace std;
- class Nome{
- private:
- string nome;
- public:
- string getNome() const{
- return nome;
- }
- };
- class Numero{
- private:
- string numero;
- public:
- string getNumero() const{
- return numero;
- }
- };
- class Contatto{
- private:
- Nome nom;
- public:
- Nome getNome() const{
- return nom;
- }
- virtual Contatto* clone() const =0;
- virtual bool operator==(const Contatto&) const =0;
- virtual ~Contatto() =default;
- };
- class Telefonico: public Contatto{
- private:
- Numero num;
- int numSMS;
- bool whatsapp;
- public:
- Numero getNum() const{
- return num;
- }
- Telefonico* clone() const{
- return new Telefonico(*this);
- }
- bool operator==(const Contatto& c) const{
- const Telefonico* pt=dynamic_cast<const Telefonico*>(&c);
- if(pt && pt->getNum().getNumero()==num.getNumero())
- return true;
- return false;
- }
- int getNumSMS() const{
- return numSMS;
- }
- bool hasWhatsapp() const{
- return whatsapp;
- }
- };
- class Skype: public Contatto{
- private:
- string username;
- bool videochiamate;
- public:
- string getUsername() const{
- return username;
- }
- Skype* clone() const{
- return new Skype(*this);
- }
- bool operator==(const Contatto& c) const{
- const Skype* ps=dynamic_cast<const Skype*>(&c);
- return ps && ps->getUsername()==username;
- }
- bool canVideochiamare() const{
- return videochiamate;
- }
- };
- class Rubrica{
- private:
- class Entry{
- public:
- Contatto* c;
- int numTot;
- Entry(Contatto* cont, int num=0): c(cont->clone()), numTot(num){}
- Entry(const Entry& e):c(e.c->clone()), numTot(e.numTot){}
- Entry& operator=(const Entry& e){
- if(this!=&e){
- delete c;
- c=e.c->clone();
- numTot=e.numTot;
- }
- return *this;
- }
- ~Entry(){
- if(c) delete c;
- }
- };
- vector<Entry> v;
- public:
- void insert(Contatto* c, int n){
- for(unsigned int i=0;i<v.size();++i){
- if(*c==*v[i].c){
- ++v[i].numTot;
- return;
- }
- }
- v.push_back(*new Entry(c,n));
- }
- list<Telefonico> tel(const Nome& name, int s) const{
- list<Telefonico> res;
- for(unsigned int i=0;i<v.size();++i){
- Telefonico* pt=dynamic_cast<Telefonico*>(v[i].c);
- if(pt && pt->getNome().getNome()==name.getNome() && pt->getNumSMS()>=s)
- res.push_back(*pt);
- }
- return res;
- }
- int whatsCall() const{
- int res=0;
- for(unsigned int i=0;i<v.size();++i){
- Telefonico* pt=dynamic_cast<Telefonico*>(v[i].c);
- Skype* ps=dynamic_cast<Skype*>(v[i].c);
- if((pt && pt->hasWhatsapp()) || (ps && ps->canVideochiamare()))
- ++res;
- }
- return res;
- }
- };
- int main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement