Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include "class utente.cpp"
- using namespace std;
- class Sito
- {
- private: Utente listaUtenti [100];
- private: int dim;
- private: int idProg;
- public: Sito()
- {
- dim =0;
- idProg=1;
- }
- public: void inserisciUtente ()
- {
- if(dim<100)
- {
- char tempNome [50];
- char tempCognome[50];
- char tempPassword[20];
- cout<<"Inserisci nome: ";
- fflush stdin;
- gets(tempNome);
- cout<<"Inserisci cognome: ";
- fflush stdin;
- gets(tempCognome);
- cout<<"Inserisci password: ";
- fflush stdin;
- gets(tempPassword);
- listaUtenti[dim]=Utente(idProg,tempPassword,tempNome,tempCognome);
- dim++;
- idProg++;
- } else cout<<"ERRORE: vettore pieno ";
- }
- //return indice dell'elelemnto identificato altrimenti -1
- public: int identificaUtente ()
- {
- int tempUserId;
- char tempPassword [20];
- cout<<"Inserisci userId: ";
- cin>>tempUserId;
- cout<<"Inserisci password: ";
- fflush stdin;
- gets(tempPassword);
- for (int i=0; i<dim;i++)
- {
- if (strcmp(tempPassword, listaUtenti[i].getPassword())==0 && tempUserId==listaUtenti[i].getUserId())
- {
- listaUtenti[i].visualizzaUtente();
- return i;
- }
- }
- return -1;
- }
- public: void eliminaUtente ()
- {
- int indice=identificaUtente ();
- if (indice==-1)
- cout<<"ERRORE: utente non trovato";
- else
- {
- listaUtenti[indice].~Utente();
- for (int i=indice; i<dim-1; i++)
- listaUtenti[i]=listaUtenti[i+1]; //quello che voglio eliminare = elemento successivo
- dim--;
- }
- }
- public: void visualizzaUtenti()
- {
- for (int i=0; i<dim; i++)
- {
- cout<<"_____________________"<<endl;
- listaUtenti[i].visualizzaUtente();
- }
- cout<<endl<<endl;
- system("pause");
- }
- };
Add Comment
Please, Sign In to add comment