//Checa os dados de um usuario, com o objetivo de exclui-lo (ver funcaos 'soliciar_excluir_......') bool Excluir_user::excluir_user (const string nome, const string matricula, const int nivel) { int posicao; Checar_user user; posicao = user.checar_user (nome, matricula, nivel); if (posicao == -1) { return false; } else { Registro registro (nivel); registro.setPos ((long int) posicao); registro.alterar_status_registro (0); return true; } }
//Checa os dados de um Aluno (nao precisa da senha do aluno nem da turma) bool Checar_user::checar_user (const string nome, const string matricula, const char *nome_arquivo) { char *n_suporte = 0; char *mat_suporte = 0; char lixo[11]; int status; //Indica se o registro ainda esta disponivel ou se ja foi deletado (checa o arquivo de vetor de bits) long int posicao = 0; FILE *arquivo = fopen (nome_arquivo, "r"); //O arquivo falhou if ( arquivo == 0) { return false; } //O arquivo abriu else { n_suporte = (char *) malloc (21*sizeof (char)); mat_suporte = (char *) malloc (10*sizeof (char)); n_suporte[20] = '\0'; mat_suporte[9] = '\0'; do { //Lendo o nome fscanf (arquivo, "%20c", n_suporte); fscanf (arquivo, "%c", &lixo[0]); string n (n_suporte); //Lendo a matrícula fscanf (arquivo, "%9c", mat_suporte); fscanf (arquivo, "%c", &lixo[0]); string mat (mat_suporte); //Pulando a senha fscanf (arquivo, "%11c", lixo); //Pulando a turma fscanf (arquivo, "%c", &lixo[0]); //Verificando o status do registro Registro registro (3); registro.setPos (posicao); status = registro.getStatus (); if (n == nome && mat == matricula && status == 1) { return true; cout << "Nome: " << nome << " Matricula: " << matricula; } if (!feof (arquivo)) { fscanf (arquivo, "%c", &lixo[0]); // '+' } posicao++; } while ( !feof (arquivo) ); return false; } }
//Busca a posicao do registro de um usuario long int Checar_user::checar_user (const string nome, const string matricula, const int nivel) { char lixo[22]; char *n_suporte = 0; char *mat_suporte = 0; int status; //Indica se o registro ainda esta disponivel ou se ja foi deletado (checa o arquivo de vetor de bits) long int posicao = 0; FILE *arquivo = 0; switch (nivel) { //Master case 1: arquivo = fopen ("dados/Master.txt", "r"); //O arquivo falhou if ( arquivo == 0 ) { return -1; } //O arquivo abriu else { n_suporte = (char *) malloc (21*sizeof (char)); mat_suporte = (char *) malloc (10*sizeof (char)); n_suporte[20] = '\0'; mat_suporte[9] = '\0'; do { //Lendo o nome fscanf (arquivo, "%20c", n_suporte); fscanf (arquivo, "%c", &lixo[0]); string n (n_suporte); //Lendo a matrícula fscanf (arquivo, "%9c", mat_suporte); string mat (mat_suporte); //Avancando os dados desnecessarios fscanf (arquivo, "%11c", lixo); //Verificando o status do registro Registro registro (1); registro.setPos (posicao); status = registro.getStatus (); if (n == nome && mat == matricula && status == 1) { return posicao; } if (!feof (arquivo)) { fscanf (arquivo, "%c", &lixo[0]); // '+' } posicao++; } while ( !feof (arquivo) ); return -1; } break; //Professor case 2: arquivo = fopen ("dados/Professor.txt", "r"); //O arquivo falhou if ( arquivo == 0 ) { return -1; } //O arquivo abriu else { n_suporte = (char *) malloc (21*sizeof (char)); mat_suporte = (char *) malloc (10*sizeof (char)); n_suporte[20] = '\0'; mat_suporte[9] = '\0'; do { //Lendo o nome fscanf (arquivo, "%20c", n_suporte); fscanf (arquivo, "%c", &lixo[0]); string n (n_suporte); //Lendo a matrícula fscanf (arquivo, "%9c", mat_suporte); string mat (mat_suporte); //Avancando os dados desnecessarios fscanf (arquivo, "%22c", lixo); //Verificando o status do registro Registro registro (2); registro.setPos (posicao); status = registro.getStatus (); if (n == nome && mat == matricula && status == 1) { return posicao; } if (!feof (arquivo)) { fscanf (arquivo, "%c", &lixo[0]); // '+' } posicao++; } while ( !feof (arquivo) ); return -1; } break; //Aluno case 3: arquivo = fopen ("dados/Aluno.txt", "r"); //O arquivo falhou if ( arquivo == 0 ) { return -1; } //O arquivo abriu else { n_suporte = (char *) malloc (21*sizeof (char)); mat_suporte = (char *) malloc (10*sizeof (char)); n_suporte[20] = '\0'; mat_suporte[9] = '\0'; do { //Lendo o nome fscanf (arquivo, "%20c", n_suporte); fscanf (arquivo, "%c", &lixo[0]); string n (n_suporte); //Lendo a matrícula fscanf (arquivo, "%9c", mat_suporte); string mat (mat_suporte); //Avancando os dados desnecessarios fscanf (arquivo, "%13c", lixo); //Verificando o status do registro Registro registro (3); registro.setPos (posicao); status = registro.getStatus (); if (n == nome && mat == matricula && status == 1) { return posicao; } if (!feof (arquivo)) { fscanf (arquivo, "%c", &lixo[0]); // '+' } posicao++; } while ( !feof (arquivo) ); return -1; } break; } }
//Checa os dados de um Professor bool Checar_user::checar_user (const string nome, const string matricula, const string senha, const string disciplina, const char *nome_arquivo) { char c; char *n_suporte = 0; char *mat_suporte = 0; char *s_suporte = 0; char *disci_suporte = 0; int status; //Indica se o registro ainda esta disponivel ou se ja foi deletado (checa o arquivo de vetor de bits) long int posicao = 0; FILE *arquivo = fopen (nome_arquivo, "r"); //O arquivo falhou if ( arquivo == 0) { return false; } //O arquivo abriu else { n_suporte = (char *) malloc (21*sizeof (char)); mat_suporte = (char *) malloc (10*sizeof (char)); s_suporte = (char *) malloc (11*sizeof (char)); disci_suporte = (char *) malloc (11*sizeof (char)); n_suporte[20] = '\0'; mat_suporte[9] = '\0'; s_suporte[10] = '\0'; disci_suporte[10] = '\0'; do { //Lendo o nome fscanf (arquivo, "%20c", n_suporte); fscanf (arquivo, "%c", &c); string n (n_suporte); //Lendo a matrícula fscanf (arquivo, "%9c", mat_suporte); fscanf (arquivo, "%c", &c); string mat (mat_suporte); //Lendo a senha fscanf (arquivo, "%10c", s_suporte); fscanf (arquivo, "%c", &c); string s (s_suporte); //Lendo a disciplina fscanf (arquivo, "%10c", disci_suporte); string disci (disci_suporte); //Verificando o status do registro Registro registro (2); registro.setPos (posicao); status = registro.getStatus (); if (n == nome && s == senha && mat == matricula && disci == disciplina && status == 1) { return true; } if (!feof (arquivo)) { fscanf (arquivo, "%c", &c); // '+' } posicao++; } while ( !feof (arquivo) ); return false; } }