Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct jogador{
- char userName[50];
- char password[50];
- char nome[100];
- int idade;
- int pontuacao;
- char data[50];
- char hora[50];
- } JOGADOR;
- typedef struct administrador{
- char userName[50];
- char password[50];
- } ADMINISTRADOR;
- typedef struct infoEM {
- int numero;
- char enunciado[200];
- char respostaCorreta[200];
- char respostaIncorreta1[200];
- char respostaIncorreta2[200];
- char respostaIncorreta3[200];
- } INFO_EM;
- typedef struct infoVF {
- int numero;
- char enunciado[200];
- char respostaCorreta[200];
- char respostaIncorreta[200];
- } INFO_VF;
- typedef struct infoO {
- int numero;
- char enunciado[200];
- char respostaCorreta[20];
- } INFO_O;
- typedef struct infoT {
- int numero;
- char enunciado[200];
- char respostaCorreta[200];
- } INFO_T;
- typedef struct elemEM {
- INFO_EM infoEM;
- struct elemEM *seguinte;
- struct elemEM *anterior;
- } ELEMENTO_EM;
- typedef struct elemVF {
- INFO_VF infoVF;
- struct elemVF *seguinte;
- struct elemVF *anterior;
- } ELEMENTO_VF;
- typedef struct elemO {
- INFO_O infoO;
- struct elemO *seguinte;
- struct elemO *anterior;
- } ELEMENTO_O;
- typedef struct elemT {
- INFO_T infoT;
- struct elemT *seguinte;
- struct elemT *anterior;
- } ELEMENTO_T;
- void criarAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores){
- registoAdministradores = fopen ("registoAdministradores.dat", "ab");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro <registoAdministradores.dat>. \n \a");
- return;
- }
- printf ("***** CRIACAO DE ADMINISTRADOR ***** \n");
- printf ("************************************ \n");
- printf ("Introduza o username que pretende criar: (NOTA - Maximo de 50 carateres)\n");
- fflush(stdin);
- scanf ("%s", &administrador.userName);
- printf ("Introduza a password do novo username: (NOTA - Maximo de 50 carateres)\n ");
- fflush(stdin);
- scanf ("%s", &administrador.password);
- fwrite (&administrador, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- fclose (registoAdministradores);
- }
- void criarJogador (JOGADOR jogador, FILE *registoJogadores){
- registoJogadores = fopen ("registoJogadores.dat", "ab");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
- return;
- }
- printf ("***** CRIACAO DE JOGADOR ***** \n");
- printf ("****************************** \n");
- printf ("Introduza o username que pretende criar: (NOTA - Maximo de 50 carateres)\n");
- fflush(stdin);
- scanf ("%s", &jogador.userName);
- printf ("Introduza a password do novo username: (NOTA - Maximo de 50 carateres)\n ");
- fflush(stdin);
- scanf ("%s", &jogador.password);
- printf ("Introduza o seu nome: (NOTA - Maximo de 100 carateres) \n");
- fflush(stdin);
- scanf ("%s", &jogador.nome);
- printf ("Introduza a sua idade: \n");
- fflush(stdin);
- scanf ("%i", &jogador.idade);
- fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
- fclose (registoJogadores);
- }
- void listarAdministradores (ADMINISTRADOR administrador, FILE *registoAdministradores){
- ADMINISTRADOR administradorTemp;
- int resultado = 0;
- registoAdministradores = fopen ("registoAdministradores.dat", "rb");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
- return;
- }
- printf ("***** LISTAGEM DE ADMINISTRADORES ***** \n");
- printf ("*************************************** \n");
- while (!feof(registoAdministradores)){
- resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- if (resultado){
- printf ("Username: %s\nPassword: %s\n\n",
- administradorTemp.userName, administradorTemp.password);
- }
- }
- fclose (registoAdministradores);
- }
- void listarJogadores (JOGADOR jogador, FILE *registoJogadores){
- JOGADOR jogadorTemp;
- int resultado = 0;
- registoJogadores = fopen ("registoJogadores.dat", "rb");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n");
- return;
- }
- printf ("***** LISTAGEM DE JOGADORES ***** \n");
- printf ("********************************* \n");
- while (!feof(registoJogadores)){
- resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
- if (resultado){
- printf ("Username: %s\nPassword: %s\nNome: %s\nIdade: %i \n\n",
- jogadorTemp.userName, jogadorTemp.password, jogadorTemp.nome, jogadorTemp.idade);
- }
- }
- fclose (registoJogadores);
- }
- // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
- int existeAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores){
- int resultado = 0;
- ADMINISTRADOR administradorTemp;
- registoAdministradores = fopen ("registoAdministradores.dat", "rb");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
- return 0;
- }
- printf ("***** LOGIN COMO ADMINISTRADOR ***** \n");
- printf ("************************************ \n");
- printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &administrador.userName);
- printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &administrador.password);
- while (!feof(registoAdministradores)){
- resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) == 0){
- return 2;
- }
- if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) != 0){
- return 1;
- }
- }
- fclose (registoAdministradores);
- return 0;
- }
- // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
- int existeJogador (JOGADOR jogador, FILE *registoJogadores){
- int resultado = 0;
- JOGADOR jogadorTemp;
- registoJogadores = fopen ("registoJogadores.dat", "rb");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
- return 0;
- }
- printf ("***** LOGIN COMO JOGADOR ***** \n");
- printf ("****************************** \n");
- printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &jogador.userName);
- printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &jogador.password);
- while (!feof(registoJogadores)){
- resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
- if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) == 0){
- return 2;
- }
- if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) != 0){
- return 1;
- }
- }
- fclose (registoJogadores);
- return 0;
- }
- void acrescentarFimListaEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, INFO_EM newInfoEM){
- ELEMENTO_EM *novoEM = NULL;
- novoEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM));
- if (novoEM == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoEM->infoEM = newInfoEM;
- novoEM->seguinte = NULL;
- novoEM->anterior = NULL;
- if (*iniListaEM == NULL){
- *iniListaEM = novoEM;
- *fimListaEM = novoEM;
- }
- else{
- novoEM->anterior = (*fimListaEM);
- (*fimListaEM)->seguinte = novoEM;
- (*fimListaEM) = novoEM;
- }
- free (novoEM);
- }
- void acrescentarFimListaVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, INFO_VF newInfoVF){
- ELEMENTO_VF *novoVF = NULL;
- novoVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF));
- if (novoVF == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoVF->infoVF = newInfoVF;
- novoVF->seguinte = NULL;
- novoVF->anterior = NULL;
- if (*iniListaVF == NULL){
- *iniListaVF = novoVF;
- *fimListaVF = novoVF;
- }
- else{
- novoVF->anterior = (*fimListaVF);
- (*fimListaVF)->seguinte = novoVF;
- (*fimListaVF) = novoVF;
- }
- free (novoVF);
- }
- void acrescentarFimListaO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, INFO_O newInfoO){
- ELEMENTO_O *novoO = NULL;
- novoO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O));
- if (novoO == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoO->infoO = newInfoO;
- novoO->seguinte = NULL;
- novoO->anterior = NULL;
- if (*iniListaO == NULL){
- *iniListaO = novoO;
- *fimListaO = novoO;
- }
- else{
- novoO->anterior = (*fimListaO);
- (*fimListaO)->seguinte = novoO;
- (*fimListaO) = novoO;
- }
- free (novoO);
- }
- void acrescentarFimListaT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, INFO_T newInfoT){
- ELEMENTO_T *novoT = NULL;
- novoT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T));
- if (novoT == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoT->infoT = newInfoT;
- novoT->seguinte = NULL;
- novoT->anterior = NULL;
- if (*iniListaT == NULL){
- *iniListaT = novoT;
- *fimListaT = novoT;
- }
- else{
- novoT->anterior = (*fimListaT);
- (*fimListaT)->seguinte = novoT;
- (*fimListaT) = novoT;
- }
- free (novoT);
- }
- void listarCrescentePerguntasEM (ELEMENTO_EM *iniListaEM){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("%i. %s \n", auxEM->infoEM.numero, auxEM->infoEM.enunciado);
- printf ("Resposta Correta: %s \n", auxEM->infoEM.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", auxEM->infoEM.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", auxEM->infoEM.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", auxEM->infoEM.respostaIncorreta3);
- }
- }
- void listarCrescentePerguntasVF (ELEMENTO_VF *iniListaVF){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("%i. %s \n", auxVF->infoVF.numero, auxVF->infoVF.enunciado);
- printf ("Resposta Correta: %s \n", auxVF->infoVF.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", auxVF->infoVF.respostaIncorreta);
- }
- }
- void listarCrescentePerguntasO (ELEMENTO_O *iniListaO){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("%i. %s \n", auxO->infoO.numero, auxO->infoO.enunciado);
- printf ("Resposta Correta: %s \n", auxO->infoO.respostaCorreta);
- }
- }
- void listarCrescentePerguntasT (ELEMENTO_T *iniListaT){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("%i. %s \n", auxT->infoT.numero, auxT->infoT.enunciado);
- printf ("Resposta Correta: %s \n", auxT->infoT.respostaCorreta);
- }
- }
- void lerFicheiroBinarioPerguntasEM (FILE *registoDePerguntasEM){
- int resultadoEM = 0;
- INFO_EM infoEMTemp;
- registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
- if (registoDePerguntasEM == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasEM)){
- resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
- if (resultadoEM){
- printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
- printf ("Enunciado: %s \n", infoEMTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
- }
- }
- fclose (registoDePerguntasEM);
- }
- void lerFicheiroBinarioPerguntasVF (FILE *registoDePerguntasVF){
- int resultadoVF = 0;
- INFO_VF infoVFTemp;
- registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
- if (registoDePerguntasVF == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasVF)){
- resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
- if (resultadoVF){
- printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
- printf ("Enunciado: %s \n", infoVFTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
- }
- }
- fclose (registoDePerguntasVF);
- }
- void lerFicheiroBinarioPerguntasO (FILE *registoDePerguntasO){
- int resultadoO = 0;
- INFO_O infoOTemp;
- registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
- if (registoDePerguntasO == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasO)){
- resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
- if (resultadoO){
- printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
- printf ("Enunciado: %s \n", infoOTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
- }
- }
- fclose (registoDePerguntasO);
- }
- void lerFicheiroBinarioPerguntasT (FILE *registoDePerguntasT){
- int resultadoT = 0;
- INFO_T infoTTemp;
- registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
- if (registoDePerguntasT == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasT)){
- resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
- if (resultadoT){
- printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
- printf ("Enunciado: %s \n", infoTTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
- }
- }
- fclose (registoDePerguntasT);
- }
- void acrescentarPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
- ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
- ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT, INFO_EM newInfoEM, INFO_VF newInfoVF,
- INFO_O newInfoO, INFO_T newInfoT, int numTotalEM, int numTotalVF, int numTotalO, int numTotalT){
- int opcao;
- printf ("***** ACRESCIMO DE PERGUNTAS ***** \n");
- printf ("********************************** \n\n");
- do{
- printf ("Que tipo de pergunta pretende acrescentar? \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : printf ("Ira inserir uma pergunta do tipo <Escolha Multipla>. \n");
- registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "ab");
- if (registoDePerguntasEM == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
- return;
- }
- numTotalEM++;
- printf ("Esta pergunta sera o numero %i do tipo <Escolha Multipla>. \n", numTotalEM);
- newInfoEM.numero = numTotalEM;
- printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
- fflush (stdin);
- gets (newInfoEM.enunciado);
- printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoEM.respostaCorreta);
- printf ("Introduza a primeira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta1);
- printf ("Introduza a segunda resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta2);
- printf ("Introduza a terceira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta3);
- fwrite (&newInfoEM, sizeof(INFO_EM), 1, registoDePerguntasEM);
- acrescentarFimListaEM (&iniListaEM, &fimListaEM, newInfoEM);
- fclose (registoDePerguntasEM);
- break;
- case 2 : printf ("Ira inserir uma pergunta do tipo <Verdadeiro ou Falso>. \n");
- registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "ab");
- if (registoDePerguntasVF == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
- return;
- }
- numTotalVF++;
- printf ("Esta pergunta sera o numero %i do tipo <Verdadeiro ou Falso>. \n", numTotalVF);
- newInfoVF.numero = numTotalVF;
- printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
- fflush (stdin);
- gets (newInfoVF.enunciado);
- printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoVF.respostaCorreta);
- printf ("Introduza a primeira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoVF.respostaIncorreta);
- fwrite (&newInfoVF, sizeof(INFO_VF), 1, registoDePerguntasVF);
- acrescentarFimListaVF (&iniListaVF, &fimListaVF, newInfoVF);
- fclose (registoDePerguntasVF);
- break;
- case 3 : printf ("Ira inserir uma pergunta do tipo <Ordenacao>. \n");
- registoDePerguntasO = fopen ("registoDePerguntasO.dat", "ab");
- if (registoDePerguntasO == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
- return;
- }
- numTotalO++;
- printf ("Esta pergunta sera o numero %i do tipo <Ordenacao>. \n", numTotalO);
- newInfoO.numero = numTotalO;
- printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
- fflush (stdin);
- gets (newInfoO.enunciado);
- printf ("Introduza a resposta correta: (NOTA: Maximo de 10 carateres) \n");
- fflush (stdin);
- gets (newInfoO.respostaCorreta);
- fwrite (&newInfoO, sizeof(INFO_O), 1, registoDePerguntasO);
- acrescentarFimListaO (&iniListaO, &fimListaO, newInfoO);
- fclose (registoDePerguntasO);
- break;
- case 4 : printf ("Ira inserir uma pergunta do tipo <Texto>. \n");
- registoDePerguntasT = fopen ("registoDePerguntasT.dat", "ab");
- if (registoDePerguntasT == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
- return;
- }
- numTotalT++;
- newInfoT.numero = numTotalT;
- printf ("Esta pergunta sera o numero %i do tipo <Texto>. \n", numTotalT);
- printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
- fflush (stdin);
- gets (newInfoO.enunciado);
- printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
- fflush (stdin);
- gets (newInfoO.respostaCorreta);
- fwrite (&newInfoT, sizeof(INFO_T), 1, registoDePerguntasT);
- acrescentarFimListaT (&iniListaT, &fimListaT, newInfoT);
- fclose (registoDePerguntasT);
- break;
- }
- } while (opcao != 0);
- }
- void alterarPerguntaEM_Enunciado (ELEMENTO_EM *iniListaEM, char enunciadoEM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.enunciado, enunciadoEM);
- }
- void alterarPerguntaEM_RC (ELEMENTO_EM *iniListaEM, char respostaCorretaEM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaCorreta, respostaCorretaEM);
- }
- void alterarPerguntaEM_RI1 (ELEMENTO_EM *iniListaEM, char respostaIncorreta1EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta1, respostaIncorreta1EM);
- }
- void alterarPerguntaEM_RI2 (ELEMENTO_EM *iniListaEM, char respostaIncorreta2EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta2, respostaIncorreta2EM);
- }
- void alterarPerguntaEM_RI3 (ELEMENTO_EM *iniListaEM, char respostaIncorreta3EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta3, respostaIncorreta3EM);
- }
- void alterarPerguntaVF_Enunciado (ELEMENTO_VF *iniListaVF, char enunciadoVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.enunciado, enunciadoVF);
- }
- void alterarPerguntaVF_RC (ELEMENTO_VF *iniListaVF, char respostaCorretaVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.respostaCorreta, respostaCorretaVF);
- }
- void alterarPerguntaVF_RI (ELEMENTO_VF *iniListaVF, char respostaIncorretaVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.respostaIncorreta, respostaIncorretaVF);
- }
- void alterarPerguntaO_Enunciado (ELEMENTO_O *iniListaO, char enunciadoO []){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxO->infoO.enunciado, enunciadoO);
- }
- void alterarPerguntaO_RC (ELEMENTO_O *iniListaO, char respostaCorretaO []){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxO->infoO.respostaCorreta, respostaCorretaO);
- }
- void alterarPerguntaT_Enunciado (ELEMENTO_T *iniListaT, char enunciadoT []){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxT->infoT.enunciado, enunciadoT);
- }
- void alterarPerguntaT_RC (ELEMENTO_T *iniListaT, char respostaCorretaT []){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxT->infoT.respostaCorreta, respostaCorretaT);
- }
- void alterarPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
- ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
- ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT){
- int opcao = 0;
- int opcaoEM = 0;
- int opcaoVF = 0;
- int opcaoO = 0;
- int opcaoT = 0;
- char enunciadoEM[200];
- char respostaCorretaEM[200];
- char respostaIncorreta1EM[200];
- char respostaIncorreta2EM[200];
- char respostaIncorreta3EM[200];
- char enunciadoVF[200];
- char respostaCorretaVF[200];
- char respostaIncorretaVF[200];
- char enunciadoO[200];
- char respostaCorretaO[20];
- char enunciadoT[200];
- char respostaCorretaT[200];
- int resultadoEM = 0;
- int resultadoVF = 0;
- int resultadoO = 0;
- int resultadoT = 0;
- INFO_EM infoEMTemp;
- INFO_VF infoVFTemp;
- INFO_O infoOTemp;
- INFO_T infoTTemp;
- printf ("***** ALTERACAO DE PERGUNTAS ***** \n");
- printf ("********************************** \n\n");
- do {
- printf ("Que tipo de pergunta pretende alterar: \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao) {
- case 1 : printf ("Ira alterar uma pergunta do tipo <Escolha Multipla>. \n");
- registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
- if (registoDePerguntasEM == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasEM)){
- resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
- if (resultadoEM){
- printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
- printf ("Enunciado: %s \n", infoEMTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
- }
- }
- do{
- printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("3. Resposta Incorreta 1 \n");
- printf ("4. Resposta Incorreta 2 \n");
- printf ("5. Resposta Incorreta 3 \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoEM);
- switch (opcaoEM){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoEM);
- alterarPerguntaEM_Enunciado (iniListaEM, enunciadoEM);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaEM);
- alterarPerguntaEM_RC (iniListaEM, respostaCorretaEM);
- break;
- case 3 : printf ("Introduza a nova Resposta Incorreta 1: \n");
- fflush (stdin);
- gets (respostaIncorreta1EM);
- alterarPerguntaEM_RI1 (iniListaEM, respostaIncorreta1EM);
- break;
- case 4 : printf ("Introduza a nova Resposta Incorreta 2: \n");
- fflush (stdin);
- gets (respostaIncorreta2EM);
- alterarPerguntaEM_RI2 (iniListaEM, respostaIncorreta2EM);
- break;
- case 5 : printf ("Introduza a nova Resposta Incorreta 3: \n");
- fflush (stdin);
- gets (respostaIncorreta3EM);
- alterarPerguntaEM_RI3 (iniListaEM, respostaIncorreta3EM);
- break;
- }
- } while (opcaoEM != 0);
- fclose (registoDePerguntasEM);
- break;
- case 2 : printf ("Ira alterar uma pergunta do tipo <Verdadeiro ou Falso>. \n");
- registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
- if (registoDePerguntasVF == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasVF)){
- resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
- if (resultadoVF){
- printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
- printf ("Enunciado: %s \n", infoVFTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
- }
- }
- do{
- printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("3. Resposta Incorreta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoVF);
- switch (opcaoVF){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoVF);
- alterarPerguntaVF_Enunciado (iniListaVF, enunciadoVF);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaVF);
- alterarPerguntaVF_RC (iniListaVF, respostaCorretaVF);
- break;
- case 3 : printf ("Introduza a nova Resposta Incorreta: \n");
- fflush (stdin);
- gets (respostaIncorretaVF);
- alterarPerguntaVF_RI (iniListaVF, respostaIncorretaVF);
- break;
- }
- } while (opcaoVF != 0);
- fclose (registoDePerguntasVF);
- break;
- case 3 : printf ("Ira alterar uma pergunta do tipo <Ordenacao>. \n");
- registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
- if (registoDePerguntasO == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasO)){
- resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
- if (resultadoO){
- printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
- printf ("Enunciado: %s \n", infoOTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
- }
- }
- do{
- printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoO);
- switch (opcaoO){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoO);
- alterarPerguntaO_Enunciado (iniListaO, enunciadoO);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaO);
- alterarPerguntaO_RC (iniListaO, respostaCorretaO);
- break;
- }
- } while (opcaoO != 0);
- fclose (registoDePerguntasO);
- break;
- case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
- registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
- if (registoDePerguntasT == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasT)){
- resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
- if (resultadoT){
- printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
- printf ("Enunciado: %s \n", infoTTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
- }
- }
- do{
- printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoT);
- switch (opcaoVF){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoT);
- alterarPerguntaT_Enunciado (iniListaT, enunciadoT);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaT);
- alterarPerguntaT_RC (iniListaT, respostaCorretaT);
- break;
- }
- } while (opcaoT != 0);
- fclose (registoDePerguntasT);
- break;
- }
- } while (opcao != 0);
- }
- void removerPerguntasEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, int numeroEM, FILE *registoDePerguntasEM){
- ELEMENTO_EM *auxEM = NULL;
- auxEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM *));
- if (auxEM == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxEM = *iniListaEM;
- if (*iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxEM != NULL && auxEM->infoEM.numero != numeroEM){
- auxEM = auxEM->seguinte;
- }
- if (auxEM == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxEM->anterior == NULL){
- (*iniListaEM) = auxEM->seguinte;
- if ((*iniListaEM) != NULL){
- (*iniListaEM)->anterior = NULL;
- }
- else{
- auxEM->anterior->seguinte = auxEM->seguinte;
- }
- }
- if (auxEM->seguinte == NULL){
- (*fimListaEM) = auxEM->anterior;
- if ((*fimListaEM) != NULL){
- (*fimListaEM)->seguinte = NULL;
- }
- else{
- auxEM->seguinte->anterior = auxEM->anterior;
- }
- }
- free (auxEM);
- }
- void removerPerguntasVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, int numeroVF){
- ELEMENTO_VF *auxVF = NULL;
- auxVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF *));
- if (auxVF == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxVF = *iniListaVF;
- if (*iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxVF != NULL && auxVF->infoVF.numero != numeroVF){
- auxVF = auxVF->seguinte;
- }
- if (auxVF == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxVF->anterior == NULL){
- (*iniListaVF) = auxVF->seguinte;
- if ((*iniListaVF) != NULL){
- (*iniListaVF)->anterior = NULL;
- }
- else{
- auxVF->anterior->seguinte = auxVF->seguinte;
- }
- }
- if (auxVF->seguinte == NULL){
- (*fimListaVF) = auxVF->anterior;
- if ((*fimListaVF) != NULL){
- (*fimListaVF)->seguinte = NULL;
- }
- else{
- auxVF->seguinte->anterior = auxVF->anterior;
- }
- }
- free (auxVF);
- }
- void removerPerguntasO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, int numeroO){
- ELEMENTO_O *auxO = NULL;
- auxO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O *));
- if (auxO == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxO = *iniListaO;
- if (*iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxO != NULL && auxO->infoO.numero != numeroO){
- auxO = auxO->seguinte;
- }
- if (auxO == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxO->anterior == NULL){
- (*iniListaO) = auxO->seguinte;
- if ((*iniListaO) != NULL){
- (*iniListaO)->anterior = NULL;
- }
- else{
- auxO->anterior->seguinte = auxO->seguinte;
- }
- }
- if (auxO->seguinte == NULL){
- (*fimListaO) = auxO->anterior;
- if ((*fimListaO) != NULL){
- (*fimListaO)->seguinte = NULL;
- }
- else{
- auxO->seguinte->anterior = auxO->anterior;
- }
- }
- free (auxO);
- }
- void removerPerguntasT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, int numeroT){
- ELEMENTO_T *auxT = NULL;
- auxT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T *));
- if (auxT == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxT = *iniListaT;
- if (*iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxT != NULL && auxT->infoT.numero != numeroT){
- auxT = auxT->seguinte;
- }
- if (auxT == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxT->anterior == NULL){
- (*iniListaT) = auxT->seguinte;
- if ((*iniListaT) != NULL){
- (*iniListaT)->anterior = NULL;
- }
- else{
- auxT->anterior->seguinte = auxT->seguinte;
- }
- }
- if (auxT->seguinte == NULL){
- (*fimListaT) = auxT->anterior;
- if ((*fimListaT) != NULL){
- (*fimListaT)->seguinte = NULL;
- }
- else{
- auxT->seguinte->anterior = auxT->anterior;
- }
- }
- free (auxT);
- }
- void removerPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
- ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
- ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT){
- int opcao = 0;
- int numeroEM = 0;
- int numeroVF = 0;
- int numeroO = 0;
- int numeroT = 0;
- int resultadoEM = 0;
- int resultadoVF = 0;
- int resultadoO = 0;
- int resultadoT = 0;
- INFO_EM infoEMTemp;
- INFO_VF infoVFTemp;
- INFO_O infoOTemp;
- INFO_T infoTTemp;
- printf ("***** REMOCAO DE PERGUNTAS ***** \n");
- printf ("******************************** \n\n");
- do {
- printf ("Que tipo de pergunta pretende remover? \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
- registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
- if (registoDePerguntasEM == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasEM)){
- resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
- if (resultadoEM){
- printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
- printf ("Enunciado: %s \n", infoEMTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
- }
- }
- printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroEM);
- removerPerguntasEM (&iniListaEM, &fimListaEM, numeroEM, registoDePerguntasEM);
- fclose (registoDePerguntasEM);
- break;
- case 2 : printf ("Ira remover uma pergunta do tipo <Verdadeiro ou Falso>. \n");
- registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
- if (registoDePerguntasVF == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasVF)){
- resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
- if (resultadoVF){
- printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
- printf ("Enunciado: %s \n", infoVFTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
- }
- }
- printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroVF);
- removerPerguntasVF (&iniListaVF, &fimListaVF, numeroVF);
- fclose (registoDePerguntasVF);
- break;
- case 3 : printf ("Ira remover uma pergunta do tipo <Ordenacao>. \n");
- registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
- if (registoDePerguntasO == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasO)){
- resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
- if (resultadoO){
- printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
- printf ("Enunciado: %s \n", infoOTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
- }
- }
- printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroO);
- removerPerguntasO (&iniListaO, &fimListaO, numeroO);
- fclose (registoDePerguntasO);
- break;
- case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
- registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
- if (registoDePerguntasT == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasT)){
- resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
- if (resultadoT){
- printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
- printf ("Enunciado: %s \n", infoTTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
- }
- }
- printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroT);
- removerPerguntasT (&iniListaT, &fimListaT, numeroT);
- fclose (registoDePerguntasT);
- break;
- }
- } while (opcao != 0);
- }
- void menuAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores, JOGADOR jogador, FILE *registoJogadores){
- int opcao;
- FILE *registoDePerguntasEM = NULL;
- FILE *registoDePerguntasVF = NULL;
- FILE *registoDePerguntasO = NULL;
- FILE *registoDePerguntasT = NULL;
- ELEMENTO_EM *iniListaEM = NULL;
- ELEMENTO_EM *fimListaEM = NULL;
- ELEMENTO_VF *iniListaVF = NULL;
- ELEMENTO_VF *fimListaVF = NULL;
- ELEMENTO_O *iniListaO = NULL;
- ELEMENTO_O *fimListaO = NULL;
- ELEMENTO_T *iniListaT = NULL;
- ELEMENTO_T *fimListaT = NULL;
- INFO_EM newInfoEM;
- INFO_VF newInfoVF;
- INFO_O newInfoO;
- INFO_T newInfoT;
- int numTotalEM = 0;
- int numTotalVF = 0;
- int numTotalT = 0;
- int numTotalO = 0;
- do{
- printf ("***** MENU DE ADMINISTRACAO ***** \n");
- printf ("********************************* \n");
- printf ("Introduza a opcao pretendida: \n");
- printf ("1. Acrescentar perguntas \n");
- printf ("2. Alterar perguntas \n");
- printf ("3. Remover perguntas \n");
- printf ("4. Criar Administrador \n");
- printf ("5. Listar Administradores \n");
- printf ("6. Listar Jogadores \n");
- printf ("0. Sair \n");
- fflush(stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : acrescentarPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
- iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT, newInfoEM, newInfoVF,
- newInfoO, newInfoT, numTotalEM, numTotalVF, numTotalO, numTotalT);
- break;
- case 2 : alterarPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
- iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT);
- break;
- case 3 : removerPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
- iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT);
- break;
- case 4 : criarAdministrador (administrador, registoAdministradores);
- break;
- case 5 : listarAdministradores (administrador, registoAdministradores);
- break;
- case 6 : listarJogadores (jogador, registoJogadores);
- break;
- }
- } while (opcao != 0);
- }
- void jogoSmall (){
- printf ("***** JOGO DO TIPO S ***** \n");
- printf ("************************** \n\n");
- printf ("Neste tipo de jogo serao feitas 3 perguntas de cada grupo. \n");
- printf ("(FALTA IMPLEMENTAR) \n\n");
- }
- void jogoMedium (){
- printf ("***** JOGO DO TIPO M ***** \n");
- printf ("************************** \n\n");
- printf ("Neste tipo de jogo serao feitas 6 perguntas de cada grupo. \n");
- printf ("(FALTA IMPLEMENTAR) \n\n");
- }
- void jogoLarge (){
- printf ("***** JOGO DO TIPO L ***** \n");
- printf ("************************** \n\n");
- printf ("Neste tipo de jogo serao feitas 12 perguntas de cada grupo. \n");
- printf ("(FALTA IMPLEMENTAR) \n\n");
- }
- void jogoXL (){
- printf ("***** JOGO DO TIPO XL ***** \n");
- printf ("*************************** \n\n");
- printf ("Neste tipo de jogo serao feitas 24 perguntas de cada grupo. \n");
- printf ("(FALTA IMPLEMENTAR) \n\n");
- }
- void instrucoesJogador (){
- printf ("***** PAINEL DE INSTRUCOES ***** \n");
- printf ("******************************** \n");
- printf ("S - <Small> : 3 perguntas de cada grupo \n");
- printf ("M - <Medium> : 6 perguntas de cada grupo \n");
- printf ("L - <Large> : 12 perguntas de cada grupo \n");
- printf ("X - <Extra Large> : 24 perguntas de cada grupo \n\n");
- printf ("O jogo e constituido por 4 grupos de perguntas de cultura geral:\n");
- printf ("um grupo de escolha multipla, um grupo de verdadeiro ou falso,\n");
- printf ("um grupo de ordenacao e um grupo de quem perde sai. \n\n");
- printf ("- No 1o grupo, de escolha multipla, o jogador deve selecionar a \n");
- printf (" resposta correta entre as 4 opcoes de resposta possiveis. Cada \n");
- printf (" resposta correta acresce a pontuacao do jogador em 15 pontos. \n");
- printf (" Se errar, sao-lhe retirados 10 pontos ao total de pontos. \n\n");
- printf ("- No 2o grupo, verdadeiro ou falso, cada pergunta tem apenas duas \n");
- printf (" possiveis respostas: Verdadeiro ou Falso. Se o jogador acertar \n");
- printf (" soma 30 pontos a pontuação global, senão sao-lhe retirados 30 pontos. \n\n");
- printf ("- No 3o grupo, ordenacao, o jogador devera ordenar as 3 opcoes \n");
- printf (" apresentadas. Se a ordenacao estiver correta sao-lhe somada \n");
- printf (" 50 pontos a pontuacao total, senao sao-lhe retirados 20 pontos. \n\n");
- printf ("- No 4o grupo, quem perde sai, as perguntas devem ser de resposta curta.\n");
- printf (" Se o jogador errar uma reposta sai do grupo com 0 pontos e não responde \n");
- printf (" a mais perguntas do grupo. Se acertar em todas as respostas, soma 10 \n");
- printf (" pontos por cada pergunta ao total de pontos. \n");
- }
- void menuJogador (JOGADOR jogador, FILE *registoJogadores){
- int opcao;
- do {
- printf ("***** MENU DO JOGO ***** \n");
- printf ("************************ \n");
- printf ("Introduza o tipo de jogo que pretende iniciar: \n");
- printf ("1. Small \n");
- printf ("2. Medium \n");
- printf ("3. Large \n");
- printf ("4. Extra Large \n");
- printf ("5. Listar Jogadores \n");
- printf ("6. Instrucoes e outras informacoes importantes \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : jogoSmall ();
- break;
- case 2 : jogoMedium ();
- break;
- case 3 : jogoLarge ();
- break;
- case 4 : jogoXL ();
- break;
- case 5 : listarJogadores (jogador, registoJogadores);
- break;
- case 6 : instrucoesJogador ();
- break;
- }
- } while (opcao != 0);
- }
- int main(int argc, char *argv[]) {
- ADMINISTRADOR administrador;
- JOGADOR jogador;
- int opcao;
- FILE *registoAdministradores = NULL;
- FILE *registoJogadores = NULL;
- int administradorExiste = 0;
- int jogadorExiste = 0;
- FILE *registoDePerguntasEC = NULL;
- FILE *registoDePerguntasVF = NULL;
- FILE *registoDePerguntasO = NULL;
- FILE *registoDePerguntasT = NULL;
- ELEMENTO_EM *iniListaEM = NULL;
- ELEMENTO_EM *fimListaEM = NULL;
- ELEMENTO_VF *iniListaVF = NULL;
- ELEMENTO_VF *fimListaVF = NULL;
- ELEMENTO_O *iniListaO = NULL;
- ELEMENTO_O *fimListaO = NULL;
- ELEMENTO_T *iniListaT = NULL;
- ELEMENTO_T *fimListaT = NULL;
- do {
- printf ("**************************** QUEM SABE, SABE! ******************************\n");
- printf ("****************************** MENU INICIAL ********************************\n");
- printf ("****************************************************************************\n");
- printf ("Introduza a opcao pretendida: \n");
- printf ("1. Entrar como Administrador \n");
- printf ("2. Entrar como Jogador \n");
- printf ("0. Sair \n");
- fflush(stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : administradorExiste = existeAdministrador (administrador, registoAdministradores);
- if (administradorExiste == 2){
- printf ("Aprovado como ADMINISTRADOR. \n");
- menuAdministrador ( administrador, registoAdministradores, jogador, registoAdministradores);
- }
- if (administradorExiste == 1){
- printf ("Identificacao ERRADA. \n");
- continue; // permite reinicar o ciclo
- }
- if (administradorExiste == 0){
- printf ("Reprovado como ADMINISTRADOR. \n");
- printf ("Tente entrar como JOGADOR. \n");
- }
- break;
- case 2 : jogadorExiste = existeJogador (jogador, registoJogadores);
- if (jogadorExiste == 2){
- printf ("Aprovado como JOGADOR. \n");
- menuJogador (jogador, registoJogadores);
- }
- if (jogadorExiste == 1){
- printf ("Identificacao ERRADA. \n");
- continue; // permite reinicar o ciclo
- }
- if (jogadorExiste == 0) {
- printf ("Sera introduzido como novo JOGADOR. \n");
- criarJogador (jogador, registoJogadores);
- }
- break;
- case 3 : criarAdministrador (administrador, registoAdministradores);
- break;
- }
- } while (opcao != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement