Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. // Sistema de Cadastro de Agenda Telefone, campos: nome e telefone
  7. typedef struct c {
  8.     string nome;
  9.     string telefone;
  10. } Cadastro;
  11.  
  12. class Agenda {
  13. private:
  14.     Cadastro dados[50];
  15.     int ult;
  16. public:
  17.     Agenda(); // construtor da classe
  18.     void Cadastrar();
  19.     void Cadastrar(string v_nome, string v_telefone);
  20.     void Listar();
  21. };
  22.  
  23. Agenda::Agenda()
  24. {  // contrutor
  25.     ult = 0;
  26. }
  27.  
  28. void Agenda::Cadastrar()
  29. { // metodo para cadastrar na agenda
  30.     cout << "\nNome: ";
  31.     cin >> dados[ult].nome;
  32.     cout << "\nTelefone: ";
  33.     cin >> dados[ult].telefone;
  34.  
  35.     ult++;
  36. }
  37. void Agenda::Cadastrar(string v_nome, string v_telefone)
  38. {
  39.   dados[ult].nome = v_nome;
  40.   dados[ult].telefone = v_telefone;
  41.   ult++;
  42. }
  43.  
  44. void Agenda::Listar()
  45. {  // listar todos os dados
  46.     for (int i = 0; i < ult; i++)
  47.     {
  48.         cout << "\n---------------------";
  49.         cout << "\nNome.....: " << dados[i].nome;
  50.         cout << "\nTelefone.: " << dados[i].telefone;
  51.     }
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     Agenda a; // instancio a classe
  58.  
  59.     int resp = 0;
  60.  
  61.     while ( resp == 0)
  62.     {
  63.      //   a.Cadastrar();
  64.         string t_nome, t_telefone;
  65.        
  66.         cout << "\n================================";
  67.         cout << "\n Digite o nome para cadastro: ";
  68.         cin >> t_nome;
  69.         cout << "\n Digite o telefone para cadastro: ";
  70.         cin >> t_telefone;
  71.  
  72.         a.Cadastrar(t_nome, t_telefone);
  73.  
  74.         cout << "\n\n";
  75.         cout << "Deseja cadastrar novo nome? 0-sim 1-nao ";
  76.         cin >> resp;
  77.     }
  78.  
  79.  
  80.  
  81.     cout << "\n\n";
  82.     a.Listar();
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement