Advertisement
toffanetto_

Pedro

Nov 18th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3. #include<iostream>
  4. #include<iterator>
  5. using namespace std;
  6. class Contato
  7. {
  8. private:
  9. std::string nome;
  10. std::string tel;
  11. std::string email;
  12.  
  13. public:
  14. Contato(const std::string &nome, const std::string &tel, const std::string &email);
  15.  
  16. std::string getNome();
  17.  
  18. void setNome(const std::string &nome);
  19.  
  20. std::string getTel();
  21.  
  22. void setTel(const std::string &tel);
  23.  
  24. std::string getEmail();
  25.  
  26. void setEmail(const std::string &email);
  27.  
  28. std::string toString();
  29. friend ostream& operator<<(ostream &out, Contato &c) {
  30. out << "Nome: "<< c.nome << endl
  31. << "Telefone: "<< c.tel << endl
  32. << "E-mail: " << c.email << endl;
  33. return out;
  34. }
  35.  
  36. };
  37. class Agenda
  38. {
  39. public:
  40. std::vector<Contato*> Contatos = std::vector<Contato*>();
  41.  
  42. Agenda();
  43.  
  44. std::vector<Contato*> getContatos();
  45.  
  46. void setContatos(std::vector<Contato*> &Contatos);
  47.  
  48. void addCont(Contato *c);
  49. Contato *mostra(string nome);
  50. void removeCont(string nome);
  51.  
  52.  
  53. void mostraLista();
  54. };
  55. Contato::Contato(const std::string &nome, const std::string &tel, const std::string &email)
  56. {
  57. this->nome = nome;
  58. this->tel = tel;
  59. this->email = email;
  60. }
  61.  
  62. std::string Contato::getNome()
  63. {
  64. return nome;
  65. }
  66.  
  67. void Contato::setNome(const std::string &nome)
  68. {
  69. this->nome = nome;
  70. }
  71.  
  72. std::string Contato::getTel()
  73. {
  74. return tel;
  75. }
  76.  
  77. void Contato::setTel(const std::string &tel)
  78. {
  79. this->tel = tel;
  80. }
  81.  
  82. std::string Contato::getEmail()
  83. {
  84. return email;
  85. }
  86.  
  87. void Contato::setEmail(const std::string &email)
  88. {
  89. this->email = email;
  90. }
  91.  
  92. std::string Contato::toString()
  93. {
  94. return "Nome: " + nome + "\n" + "Tel=" + tel + "\n" + "E-mail=" + email;
  95. }
  96.  
  97. Agenda::Agenda(){}
  98.  
  99. void Agenda::setContatos(std::vector<Contato*> &Contatos)
  100. {
  101. this->Contatos = Contatos;
  102. }
  103.  
  104. void Agenda::addCont(Contato *c)
  105. {
  106. Contatos.push_back(c);
  107. }
  108.  
  109. Contato *Agenda::mostra(string nome)
  110. {
  111. auto it = Contatos.begin();
  112. while (it != Contatos.end())
  113. {
  114. if ((*it)->getNome() == nome)
  115. {
  116. return *it;
  117. }
  118. it++;
  119. }
  120. return nullptr;
  121.  
  122. }
  123.  
  124. void Agenda::removeCont(string nome)
  125. {
  126. for (int i = 0; i < Contatos.size(); i++)
  127. {
  128. Contato *aux = Contatos[i];
  129. if (aux->getNome() == nome)
  130. {
  131. Contatos.erase(Contatos.begin() + i);
  132. }
  133. }
  134. }
  135.  
  136. void Agenda::mostraLista()
  137. {
  138. auto it = Contatos.begin();
  139. while (it != Contatos.end())
  140. {
  141. std::cout << (*it)->getNome() << std::endl;
  142. it++;
  143. }
  144. }
  145.  
  146. int main(int argc, char **argv)
  147. {
  148. Contato *c1 = new Contato("Pedro","213165","c.@");
  149. Contato *c2 = new Contato("c","b","c.@$%");
  150. Contato *c3 = new Contato("v","b","c");
  151. Contato *c4 = new Contato("n","b","c");
  152. Contato *c5 = new Contato("VOCE SAIU","b","c");
  153. string s= "Pedro";
  154. Agenda *a = new Agenda();
  155. a->addCont(c5);
  156. a->addCont(c4);
  157. a->addCont(c3);
  158. a->addCont(c2);
  159. a->addCont(c1);
  160. a->mostraLista();
  161. a->removeCont(s);
  162. std::cout << "***********************************************************\n***************************************\n" << std::endl;
  163. a->mostraLista();
  164.  
  165. delete a;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement