Guest User

Untitled

a guest
May 17th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cstring>
  4. #include "class utente.cpp"
  5. using namespace std;
  6.  
  7. class Sito
  8. {
  9. private: Utente listaUtenti [100];
  10. private: int dim;
  11.  
  12. private: int idProg;
  13.  
  14. public: Sito()
  15. {
  16. dim =0;
  17.  
  18. idProg=1;
  19. }
  20.  
  21. public: void inserisciUtente ()
  22. {
  23. if(dim<100)
  24. {
  25. char tempNome [50];
  26. char tempCognome[50];
  27. char tempPassword[20];
  28. cout<<"Inserisci nome: ";
  29. fflush stdin;
  30. gets(tempNome);
  31.  
  32. cout<<"Inserisci cognome: ";
  33. fflush stdin;
  34. gets(tempCognome);
  35.  
  36. cout<<"Inserisci password: ";
  37. fflush stdin;
  38. gets(tempPassword);
  39.  
  40. listaUtenti[dim]=Utente(idProg,tempPassword,tempNome,tempCognome);
  41.  
  42. dim++;
  43. idProg++;
  44. } else cout<<"ERRORE: vettore pieno ";
  45.  
  46. }
  47.  
  48. //return indice dell'elelemnto identificato altrimenti -1
  49. public: int identificaUtente ()
  50. {
  51. int tempUserId;
  52. char tempPassword [20];
  53.  
  54. cout<<"Inserisci userId: ";
  55. cin>>tempUserId;
  56.  
  57. cout<<"Inserisci password: ";
  58. fflush stdin;
  59. gets(tempPassword);
  60.  
  61. for (int i=0; i<dim;i++)
  62. {
  63. if (strcmp(tempPassword, listaUtenti[i].getPassword())==0 && tempUserId==listaUtenti[i].getUserId())
  64. {
  65. listaUtenti[i].visualizzaUtente();
  66. return i;
  67. }
  68. }
  69. return -1;
  70. }
  71.  
  72. public: void eliminaUtente ()
  73. {
  74. int indice=identificaUtente ();
  75.  
  76. if (indice==-1)
  77. cout<<"ERRORE: utente non trovato";
  78. else
  79. {
  80. listaUtenti[indice].~Utente();
  81.  
  82. for (int i=indice; i<dim-1; i++)
  83. listaUtenti[i]=listaUtenti[i+1]; //quello che voglio eliminare = elemento successivo
  84.  
  85. dim--;
  86. }
  87. }
  88.  
  89. public: void visualizzaUtenti()
  90. {
  91. for (int i=0; i<dim; i++)
  92. {
  93. cout<<"_____________________"<<endl;
  94. listaUtenti[i].visualizzaUtente();
  95. }
  96.  
  97. cout<<endl<<endl;
  98. system("pause");
  99. }
  100.  
  101. };
Add Comment
Please, Sign In to add comment