Advertisement
Guest User

tp

a guest
Jun 4th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct jogador{
  6.  
  7. char userName[50];
  8. char password[50];
  9. char nome[100];
  10. int idade;
  11. int pontuacao;
  12. char data[50];
  13. char hora[50];
  14.  
  15. } JOGADOR;
  16.  
  17. typedef struct administrador{
  18.  
  19. char userName[50];
  20. char password[50];
  21.  
  22. } ADMINISTRADOR;
  23.  
  24. typedef struct infoEM {
  25.  
  26. int numero;
  27. char enunciado[200];
  28. char respostaCorreta[200];
  29. char respostaIncorreta1[200];
  30. char respostaIncorreta2[200];
  31. char respostaIncorreta3[200];
  32.  
  33. } INFO_EM;
  34.  
  35. typedef struct infoVF {
  36.  
  37. int numero;
  38. char enunciado[200];
  39. char respostaCorreta[200];
  40. char respostaIncorreta[200];
  41.  
  42. } INFO_VF;
  43.  
  44. typedef struct infoO {
  45.  
  46. int numero;
  47. char enunciado[200];
  48. char respostaCorreta[20];
  49.  
  50. } INFO_O;
  51.  
  52. typedef struct infoT {
  53.  
  54. int numero;
  55. char enunciado[200];
  56. char respostaCorreta[200];
  57.  
  58. } INFO_T;
  59.  
  60. typedef struct elemEM {
  61.  
  62. INFO_EM infoEM;
  63. struct elemEM *seguinte;
  64. struct elemEM *anterior;
  65.  
  66. } ELEMENTO_EM;
  67.  
  68. typedef struct elemVF {
  69.  
  70. INFO_VF infoVF;
  71. struct elemVF *seguinte;
  72. struct elemVF *anterior;
  73.  
  74. } ELEMENTO_VF;
  75.  
  76. typedef struct elemO {
  77.  
  78. INFO_O infoO;
  79. struct elemO *seguinte;
  80. struct elemO *anterior;
  81.  
  82. } ELEMENTO_O;
  83.  
  84. typedef struct elemT {
  85.  
  86. INFO_T infoT;
  87. struct elemT *seguinte;
  88. struct elemT *anterior;
  89.  
  90. } ELEMENTO_T;
  91.  
  92. void criarAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores){
  93.  
  94. registoAdministradores = fopen ("registoAdministradores.dat", "ab");
  95.  
  96. if (registoAdministradores == NULL){
  97. printf ("ERRO na abertura do ficheiro <registoAdministradores.dat>. \n \a");
  98. return;
  99. }
  100.  
  101. printf ("***** CRIACAO DE ADMINISTRADOR ***** \n");
  102. printf ("************************************ \n");
  103.  
  104. printf ("Introduza o username que pretende criar: (NOTA - Maximo de 50 carateres)\n");
  105. fflush(stdin);
  106. scanf ("%s", &administrador.userName);
  107.  
  108. printf ("Introduza a password do novo username: (NOTA - Maximo de 50 carateres)\n ");
  109. fflush(stdin);
  110. scanf ("%s", &administrador.password);
  111.  
  112. fwrite (&administrador, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  113.  
  114. fclose (registoAdministradores);
  115. }
  116.  
  117. void criarJogador (JOGADOR jogador, FILE *registoJogadores){
  118.  
  119. registoJogadores = fopen ("registoJogadores.dat", "ab");
  120.  
  121. if (registoJogadores == NULL){
  122. printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
  123. return;
  124. }
  125.  
  126. printf ("***** CRIACAO DE JOGADOR ***** \n");
  127. printf ("****************************** \n");
  128.  
  129. printf ("Introduza o username que pretende criar: (NOTA - Maximo de 50 carateres)\n");
  130. fflush(stdin);
  131. scanf ("%s", &jogador.userName);
  132.  
  133. printf ("Introduza a password do novo username: (NOTA - Maximo de 50 carateres)\n ");
  134. fflush(stdin);
  135. scanf ("%s", &jogador.password);
  136.  
  137. printf ("Introduza o seu nome: (NOTA - Maximo de 100 carateres) \n");
  138. fflush(stdin);
  139. scanf ("%s", &jogador.nome);
  140.  
  141. printf ("Introduza a sua idade: \n");
  142. fflush(stdin);
  143. scanf ("%i", &jogador.idade);
  144.  
  145. fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
  146.  
  147. fclose (registoJogadores);
  148. }
  149.  
  150. void listarAdministradores (ADMINISTRADOR administrador, FILE *registoAdministradores){
  151.  
  152. ADMINISTRADOR administradorTemp;
  153. int resultado = 0;
  154.  
  155. registoAdministradores = fopen ("registoAdministradores.dat", "rb");
  156.  
  157. if (registoAdministradores == NULL){
  158. printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
  159. return;
  160. }
  161.  
  162. printf ("***** LISTAGEM DE ADMINISTRADORES ***** \n");
  163. printf ("*************************************** \n");
  164.  
  165. while (!feof(registoAdministradores)){
  166. resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  167.  
  168. if (resultado){
  169. printf ("Username: %s\nPassword: %s\n\n",
  170. administradorTemp.userName, administradorTemp.password);
  171. }
  172. }
  173.  
  174. fclose (registoAdministradores);
  175. }
  176.  
  177. void listarJogadores (JOGADOR jogador, FILE *registoJogadores){
  178.  
  179. JOGADOR jogadorTemp;
  180. int resultado = 0;
  181.  
  182. registoJogadores = fopen ("registoJogadores.dat", "rb");
  183.  
  184. if (registoJogadores == NULL){
  185. printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n");
  186. return;
  187. }
  188.  
  189. printf ("***** LISTAGEM DE JOGADORES ***** \n");
  190. printf ("********************************* \n");
  191.  
  192. while (!feof(registoJogadores)){
  193. resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
  194.  
  195. if (resultado){
  196. printf ("Username: %s\nPassword: %s\nNome: %s\nIdade: %i \n\n",
  197. jogadorTemp.userName, jogadorTemp.password, jogadorTemp.nome, jogadorTemp.idade);
  198. }
  199. }
  200.  
  201. fclose (registoJogadores);
  202. }
  203.  
  204. // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
  205.  
  206. int existeAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores){
  207.  
  208. int resultado = 0;
  209. ADMINISTRADOR administradorTemp;
  210.  
  211. registoAdministradores = fopen ("registoAdministradores.dat", "rb");
  212.  
  213. if (registoAdministradores == NULL){
  214. printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
  215. return 0;
  216. }
  217.  
  218. printf ("***** LOGIN COMO ADMINISTRADOR ***** \n");
  219. printf ("************************************ \n");
  220.  
  221. printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
  222. fflush(stdin);
  223. scanf ("%s", &administrador.userName);
  224.  
  225. printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
  226. fflush(stdin);
  227. scanf ("%s", &administrador.password);
  228.  
  229. while (!feof(registoAdministradores)){
  230. resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  231.  
  232. if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) == 0){
  233. return 2;
  234. }
  235.  
  236. if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) != 0){
  237. return 1;
  238. }
  239. }
  240.  
  241. fclose (registoAdministradores);
  242.  
  243. return 0;
  244. }
  245.  
  246. // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
  247.  
  248. int existeJogador (JOGADOR jogador, FILE *registoJogadores){
  249.  
  250. int resultado = 0;
  251. JOGADOR jogadorTemp;
  252.  
  253. registoJogadores = fopen ("registoJogadores.dat", "rb");
  254.  
  255. if (registoJogadores == NULL){
  256. printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
  257. return 0;
  258. }
  259.  
  260. printf ("***** LOGIN COMO JOGADOR ***** \n");
  261. printf ("****************************** \n");
  262.  
  263. printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
  264. fflush(stdin);
  265. scanf ("%s", &jogador.userName);
  266.  
  267. printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
  268. fflush(stdin);
  269. scanf ("%s", &jogador.password);
  270.  
  271. while (!feof(registoJogadores)){
  272. resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
  273.  
  274. if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) == 0){
  275. return 2;
  276. }
  277.  
  278. if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) != 0){
  279. return 1;
  280. }
  281. }
  282.  
  283. fclose (registoJogadores);
  284.  
  285. return 0;
  286. }
  287.  
  288. void acrescentarFimListaEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, INFO_EM newInfoEM){
  289.  
  290. ELEMENTO_EM *novoEM = NULL;
  291.  
  292. novoEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM));
  293.  
  294. if (novoEM == NULL){
  295. printf ("ERRO ao reservar memoria. \n \a");
  296. return;
  297. }
  298.  
  299. novoEM->infoEM = newInfoEM;
  300. novoEM->seguinte = NULL;
  301. novoEM->anterior = NULL;
  302.  
  303. if (*iniListaEM == NULL){
  304. *iniListaEM = novoEM;
  305. *fimListaEM = novoEM;
  306. }
  307. else{
  308. novoEM->anterior = (*fimListaEM);
  309. (*fimListaEM)->seguinte = novoEM;
  310. (*fimListaEM) = novoEM;
  311. }
  312.  
  313. free (novoEM);
  314. }
  315.  
  316. void acrescentarFimListaVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, INFO_VF newInfoVF){
  317.  
  318. ELEMENTO_VF *novoVF = NULL;
  319.  
  320. novoVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF));
  321.  
  322. if (novoVF == NULL){
  323. printf ("ERRO ao reservar memoria. \n \a");
  324. return;
  325. }
  326.  
  327. novoVF->infoVF = newInfoVF;
  328. novoVF->seguinte = NULL;
  329. novoVF->anterior = NULL;
  330.  
  331. if (*iniListaVF == NULL){
  332. *iniListaVF = novoVF;
  333. *fimListaVF = novoVF;
  334. }
  335. else{
  336. novoVF->anterior = (*fimListaVF);
  337. (*fimListaVF)->seguinte = novoVF;
  338. (*fimListaVF) = novoVF;
  339. }
  340.  
  341. free (novoVF);
  342. }
  343.  
  344. void acrescentarFimListaO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, INFO_O newInfoO){
  345.  
  346. ELEMENTO_O *novoO = NULL;
  347.  
  348. novoO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O));
  349.  
  350. if (novoO == NULL){
  351. printf ("ERRO ao reservar memoria. \n \a");
  352. return;
  353. }
  354.  
  355. novoO->infoO = newInfoO;
  356. novoO->seguinte = NULL;
  357. novoO->anterior = NULL;
  358.  
  359. if (*iniListaO == NULL){
  360. *iniListaO = novoO;
  361. *fimListaO = novoO;
  362. }
  363. else{
  364. novoO->anterior = (*fimListaO);
  365. (*fimListaO)->seguinte = novoO;
  366. (*fimListaO) = novoO;
  367. }
  368.  
  369. free (novoO);
  370. }
  371.  
  372. void acrescentarFimListaT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, INFO_T newInfoT){
  373.  
  374. ELEMENTO_T *novoT = NULL;
  375.  
  376. novoT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T));
  377.  
  378. if (novoT == NULL){
  379. printf ("ERRO ao reservar memoria. \n \a");
  380. return;
  381. }
  382.  
  383. novoT->infoT = newInfoT;
  384. novoT->seguinte = NULL;
  385. novoT->anterior = NULL;
  386.  
  387. if (*iniListaT == NULL){
  388. *iniListaT = novoT;
  389. *fimListaT = novoT;
  390. }
  391. else{
  392. novoT->anterior = (*fimListaT);
  393. (*fimListaT)->seguinte = novoT;
  394. (*fimListaT) = novoT;
  395. }
  396.  
  397. free (novoT);
  398. }
  399.  
  400. void listarCrescentePerguntasEM (ELEMENTO_EM *iniListaEM){
  401.  
  402. ELEMENTO_EM *auxEM = NULL;
  403.  
  404. if (iniListaEM == NULL){
  405. printf ("Lista VAZIA! \n \a");
  406. return;
  407. }
  408.  
  409. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  410. printf ("%i. %s \n", auxEM->infoEM.numero, auxEM->infoEM.enunciado);
  411. printf ("Resposta Correta: %s \n", auxEM->infoEM.respostaCorreta);
  412. printf ("Resposta Incorreta 1: %s \n", auxEM->infoEM.respostaIncorreta1);
  413. printf ("Resposta Incorreta 2: %s \n", auxEM->infoEM.respostaIncorreta2);
  414. printf ("Resposta Incorreta 3: %s \n", auxEM->infoEM.respostaIncorreta3);
  415. }
  416. }
  417.  
  418. void listarCrescentePerguntasVF (ELEMENTO_VF *iniListaVF){
  419.  
  420. ELEMENTO_VF *auxVF = NULL;
  421.  
  422. if (iniListaVF == NULL){
  423. printf ("Lista VAZIA! \n \a");
  424. return;
  425. }
  426.  
  427. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  428. printf ("%i. %s \n", auxVF->infoVF.numero, auxVF->infoVF.enunciado);
  429. printf ("Resposta Correta: %s \n", auxVF->infoVF.respostaCorreta);
  430. printf ("Resposta Incorreta: %s \n", auxVF->infoVF.respostaIncorreta);
  431. }
  432. }
  433.  
  434. void listarCrescentePerguntasO (ELEMENTO_O *iniListaO){
  435.  
  436. ELEMENTO_O *auxO = NULL;
  437.  
  438. if (iniListaO == NULL){
  439. printf ("Lista VAZIA! \n \a");
  440. return;
  441. }
  442.  
  443. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  444. printf ("%i. %s \n", auxO->infoO.numero, auxO->infoO.enunciado);
  445. printf ("Resposta Correta: %s \n", auxO->infoO.respostaCorreta);
  446. }
  447. }
  448.  
  449. void listarCrescentePerguntasT (ELEMENTO_T *iniListaT){
  450.  
  451. ELEMENTO_T *auxT = NULL;
  452.  
  453. if (iniListaT == NULL){
  454. printf ("Lista VAZIA! \n \a");
  455. return;
  456. }
  457.  
  458. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  459. printf ("%i. %s \n", auxT->infoT.numero, auxT->infoT.enunciado);
  460. printf ("Resposta Correta: %s \n", auxT->infoT.respostaCorreta);
  461. }
  462. }
  463.  
  464. void lerFicheiroBinarioPerguntasEM (FILE *registoDePerguntasEM){
  465.  
  466. int resultadoEM = 0;
  467. INFO_EM infoEMTemp;
  468.  
  469. registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
  470.  
  471. if (registoDePerguntasEM == NULL){
  472. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
  473. return;
  474. }
  475.  
  476. while (!feof(registoDePerguntasEM)){
  477. resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
  478. if (resultadoEM){
  479. printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
  480. printf ("Enunciado: %s \n", infoEMTemp.enunciado);
  481. printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
  482. printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
  483. printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
  484. printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
  485. }
  486. }
  487.  
  488. fclose (registoDePerguntasEM);
  489. }
  490.  
  491. void lerFicheiroBinarioPerguntasVF (FILE *registoDePerguntasVF){
  492.  
  493. int resultadoVF = 0;
  494. INFO_VF infoVFTemp;
  495.  
  496. registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
  497.  
  498. if (registoDePerguntasVF == NULL){
  499. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
  500. return;
  501. }
  502.  
  503. while (!feof(registoDePerguntasVF)){
  504. resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
  505. if (resultadoVF){
  506. printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
  507. printf ("Enunciado: %s \n", infoVFTemp.enunciado);
  508. printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
  509. printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
  510. }
  511. }
  512.  
  513. fclose (registoDePerguntasVF);
  514. }
  515.  
  516. void lerFicheiroBinarioPerguntasO (FILE *registoDePerguntasO){
  517.  
  518. int resultadoO = 0;
  519. INFO_O infoOTemp;
  520.  
  521. registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
  522.  
  523. if (registoDePerguntasO == NULL){
  524. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
  525. return;
  526. }
  527.  
  528. while (!feof(registoDePerguntasO)){
  529. resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
  530. if (resultadoO){
  531. printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
  532. printf ("Enunciado: %s \n", infoOTemp.enunciado);
  533. printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
  534. }
  535. }
  536.  
  537. fclose (registoDePerguntasO);
  538. }
  539.  
  540. void lerFicheiroBinarioPerguntasT (FILE *registoDePerguntasT){
  541.  
  542. int resultadoT = 0;
  543. INFO_T infoTTemp;
  544.  
  545. registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
  546.  
  547. if (registoDePerguntasT == NULL){
  548. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
  549. return;
  550. }
  551.  
  552. while (!feof(registoDePerguntasT)){
  553. resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
  554. if (resultadoT){
  555. printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
  556. printf ("Enunciado: %s \n", infoTTemp.enunciado);
  557. printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
  558. }
  559. }
  560.  
  561. fclose (registoDePerguntasT);
  562. }
  563.  
  564. void acrescentarPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
  565. ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
  566. ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT, INFO_EM newInfoEM, INFO_VF newInfoVF,
  567. INFO_O newInfoO, INFO_T newInfoT, int numTotalEM, int numTotalVF, int numTotalO, int numTotalT){
  568.  
  569. int opcao;
  570.  
  571. printf ("***** ACRESCIMO DE PERGUNTAS ***** \n");
  572. printf ("********************************** \n\n");
  573.  
  574. do{
  575. printf ("Que tipo de pergunta pretende acrescentar? \n");
  576. printf ("1. Escolha Multipla \n");
  577. printf ("2. Verdadeiro ou Falso \n");
  578. printf ("3. Ordenacao \n");
  579. printf ("4. Texto \n");
  580. printf ("0. Sair \n");
  581. fflush (stdin);
  582. scanf ("%i", &opcao);
  583.  
  584. switch (opcao){
  585. case 1 : printf ("Ira inserir uma pergunta do tipo <Escolha Multipla>. \n");
  586. registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "ab");
  587. if (registoDePerguntasEM == NULL){
  588. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
  589. return;
  590. }
  591. numTotalEM++;
  592. printf ("Esta pergunta sera o numero %i do tipo <Escolha Multipla>. \n", numTotalEM);
  593. newInfoEM.numero = numTotalEM;
  594. printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
  595. fflush (stdin);
  596. gets (newInfoEM.enunciado);
  597. printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
  598. fflush (stdin);
  599. gets (newInfoEM.respostaCorreta);
  600. printf ("Introduza a primeira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
  601. fflush (stdin);
  602. gets (newInfoEM.respostaIncorreta1);
  603. printf ("Introduza a segunda resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
  604. fflush (stdin);
  605. gets (newInfoEM.respostaIncorreta2);
  606. printf ("Introduza a terceira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
  607. fflush (stdin);
  608. gets (newInfoEM.respostaIncorreta3);
  609. fwrite (&newInfoEM, sizeof(INFO_EM), 1, registoDePerguntasEM);
  610. acrescentarFimListaEM (&iniListaEM, &fimListaEM, newInfoEM);
  611. fclose (registoDePerguntasEM);
  612. break;
  613. case 2 : printf ("Ira inserir uma pergunta do tipo <Verdadeiro ou Falso>. \n");
  614. registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "ab");
  615. if (registoDePerguntasVF == NULL){
  616. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
  617. return;
  618. }
  619. numTotalVF++;
  620. printf ("Esta pergunta sera o numero %i do tipo <Verdadeiro ou Falso>. \n", numTotalVF);
  621. newInfoVF.numero = numTotalVF;
  622. printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
  623. fflush (stdin);
  624. gets (newInfoVF.enunciado);
  625. printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
  626. fflush (stdin);
  627. gets (newInfoVF.respostaCorreta);
  628. printf ("Introduza a primeira resposta incorreta: (NOTA: Maximo de 200 carateres) \n");
  629. fflush (stdin);
  630. gets (newInfoVF.respostaIncorreta);
  631. fwrite (&newInfoVF, sizeof(INFO_VF), 1, registoDePerguntasVF);
  632. acrescentarFimListaVF (&iniListaVF, &fimListaVF, newInfoVF);
  633. fclose (registoDePerguntasVF);
  634. break;
  635. case 3 : printf ("Ira inserir uma pergunta do tipo <Ordenacao>. \n");
  636. registoDePerguntasO = fopen ("registoDePerguntasO.dat", "ab");
  637. if (registoDePerguntasO == NULL){
  638. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
  639. return;
  640. }
  641. numTotalO++;
  642. printf ("Esta pergunta sera o numero %i do tipo <Ordenacao>. \n", numTotalO);
  643. newInfoO.numero = numTotalO;
  644. printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
  645. fflush (stdin);
  646. gets (newInfoO.enunciado);
  647. printf ("Introduza a resposta correta: (NOTA: Maximo de 10 carateres) \n");
  648. fflush (stdin);
  649. gets (newInfoO.respostaCorreta);
  650. fwrite (&newInfoO, sizeof(INFO_O), 1, registoDePerguntasO);
  651. acrescentarFimListaO (&iniListaO, &fimListaO, newInfoO);
  652. fclose (registoDePerguntasO);
  653. break;
  654. case 4 : printf ("Ira inserir uma pergunta do tipo <Texto>. \n");
  655. registoDePerguntasT = fopen ("registoDePerguntasT.dat", "ab");
  656. if (registoDePerguntasT == NULL){
  657. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
  658. return;
  659. }
  660. numTotalT++;
  661. newInfoT.numero = numTotalT;
  662. printf ("Esta pergunta sera o numero %i do tipo <Texto>. \n", numTotalT);
  663. printf ("Introduza o enunciado da pergunta: (NOTA: Maximo de 200 carateres) \n" );
  664. fflush (stdin);
  665. gets (newInfoO.enunciado);
  666. printf ("Introduza a resposta correta: (NOTA: Maximo de 200 carateres) \n");
  667. fflush (stdin);
  668. gets (newInfoO.respostaCorreta);
  669. fwrite (&newInfoT, sizeof(INFO_T), 1, registoDePerguntasT);
  670. acrescentarFimListaT (&iniListaT, &fimListaT, newInfoT);
  671. fclose (registoDePerguntasT);
  672. break;
  673. }
  674.  
  675. } while (opcao != 0);
  676. }
  677.  
  678. void alterarPerguntaEM_Enunciado (ELEMENTO_EM *iniListaEM, char enunciadoEM []){
  679.  
  680. ELEMENTO_EM *auxEM = NULL;
  681.  
  682. if (iniListaEM == NULL){
  683. printf ("Lista VAZIA ! \n");
  684. return;
  685. }
  686.  
  687. strcpy (auxEM->infoEM.enunciado, enunciadoEM);
  688. }
  689.  
  690. void alterarPerguntaEM_RC (ELEMENTO_EM *iniListaEM, char respostaCorretaEM []){
  691.  
  692. ELEMENTO_EM *auxEM = NULL;
  693.  
  694. if (iniListaEM == NULL){
  695. printf ("Lista VAZIA ! \n");
  696. return;
  697. }
  698.  
  699. strcpy (auxEM->infoEM.respostaCorreta, respostaCorretaEM);
  700. }
  701.  
  702. void alterarPerguntaEM_RI1 (ELEMENTO_EM *iniListaEM, char respostaIncorreta1EM []){
  703.  
  704. ELEMENTO_EM *auxEM = NULL;
  705.  
  706. if (iniListaEM == NULL){
  707. printf ("Lista VAZIA ! \n");
  708. return;
  709. }
  710.  
  711. strcpy (auxEM->infoEM.respostaIncorreta1, respostaIncorreta1EM);
  712. }
  713.  
  714. void alterarPerguntaEM_RI2 (ELEMENTO_EM *iniListaEM, char respostaIncorreta2EM []){
  715.  
  716. ELEMENTO_EM *auxEM = NULL;
  717.  
  718. if (iniListaEM == NULL){
  719. printf ("Lista VAZIA ! \n");
  720. return;
  721. }
  722.  
  723. strcpy (auxEM->infoEM.respostaIncorreta2, respostaIncorreta2EM);
  724. }
  725.  
  726. void alterarPerguntaEM_RI3 (ELEMENTO_EM *iniListaEM, char respostaIncorreta3EM []){
  727.  
  728. ELEMENTO_EM *auxEM = NULL;
  729.  
  730. if (iniListaEM == NULL){
  731. printf ("Lista VAZIA ! \n");
  732. return;
  733. }
  734.  
  735. strcpy (auxEM->infoEM.respostaIncorreta3, respostaIncorreta3EM);
  736. }
  737.  
  738. void alterarPerguntaVF_Enunciado (ELEMENTO_VF *iniListaVF, char enunciadoVF []){
  739.  
  740. ELEMENTO_VF *auxVF = NULL;
  741.  
  742. if (iniListaVF == NULL){
  743. printf ("Lista VAZIA ! \n");
  744. return;
  745. }
  746.  
  747. strcpy (auxVF->infoVF.enunciado, enunciadoVF);
  748. }
  749.  
  750. void alterarPerguntaVF_RC (ELEMENTO_VF *iniListaVF, char respostaCorretaVF []){
  751.  
  752. ELEMENTO_VF *auxVF = NULL;
  753.  
  754. if (iniListaVF == NULL){
  755. printf ("Lista VAZIA ! \n");
  756. return;
  757. }
  758.  
  759. strcpy (auxVF->infoVF.respostaCorreta, respostaCorretaVF);
  760. }
  761.  
  762. void alterarPerguntaVF_RI (ELEMENTO_VF *iniListaVF, char respostaIncorretaVF []){
  763.  
  764. ELEMENTO_VF *auxVF = NULL;
  765.  
  766. if (iniListaVF == NULL){
  767. printf ("Lista VAZIA ! \n");
  768. return;
  769. }
  770.  
  771. strcpy (auxVF->infoVF.respostaIncorreta, respostaIncorretaVF);
  772. }
  773.  
  774. void alterarPerguntaO_Enunciado (ELEMENTO_O *iniListaO, char enunciadoO []){
  775.  
  776. ELEMENTO_O *auxO = NULL;
  777.  
  778. if (iniListaO == NULL){
  779. printf ("Lista VAZIA ! \n");
  780. return;
  781. }
  782.  
  783. strcpy (auxO->infoO.enunciado, enunciadoO);
  784. }
  785.  
  786. void alterarPerguntaO_RC (ELEMENTO_O *iniListaO, char respostaCorretaO []){
  787.  
  788. ELEMENTO_O *auxO = NULL;
  789.  
  790. if (iniListaO == NULL){
  791. printf ("Lista VAZIA ! \n");
  792. return;
  793. }
  794.  
  795. strcpy (auxO->infoO.respostaCorreta, respostaCorretaO);
  796. }
  797.  
  798. void alterarPerguntaT_Enunciado (ELEMENTO_T *iniListaT, char enunciadoT []){
  799.  
  800. ELEMENTO_T *auxT = NULL;
  801.  
  802. if (iniListaT == NULL){
  803. printf ("Lista VAZIA ! \n");
  804. return;
  805. }
  806.  
  807. strcpy (auxT->infoT.enunciado, enunciadoT);
  808. }
  809.  
  810. void alterarPerguntaT_RC (ELEMENTO_T *iniListaT, char respostaCorretaT []){
  811.  
  812. ELEMENTO_T *auxT = NULL;
  813.  
  814. if (iniListaT == NULL){
  815. printf ("Lista VAZIA ! \n");
  816. return;
  817. }
  818.  
  819. strcpy (auxT->infoT.respostaCorreta, respostaCorretaT);
  820. }
  821.  
  822. void alterarPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
  823. ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
  824. ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT){
  825.  
  826. int opcao = 0;
  827. int opcaoEM = 0;
  828. int opcaoVF = 0;
  829. int opcaoO = 0;
  830. int opcaoT = 0;
  831. char enunciadoEM[200];
  832. char respostaCorretaEM[200];
  833. char respostaIncorreta1EM[200];
  834. char respostaIncorreta2EM[200];
  835. char respostaIncorreta3EM[200];
  836. char enunciadoVF[200];
  837. char respostaCorretaVF[200];
  838. char respostaIncorretaVF[200];
  839. char enunciadoO[200];
  840. char respostaCorretaO[20];
  841. char enunciadoT[200];
  842. char respostaCorretaT[200];
  843. int resultadoEM = 0;
  844. int resultadoVF = 0;
  845. int resultadoO = 0;
  846. int resultadoT = 0;
  847. INFO_EM infoEMTemp;
  848. INFO_VF infoVFTemp;
  849. INFO_O infoOTemp;
  850. INFO_T infoTTemp;
  851.  
  852. printf ("***** ALTERACAO DE PERGUNTAS ***** \n");
  853. printf ("********************************** \n\n");
  854.  
  855. do {
  856. printf ("Que tipo de pergunta pretende alterar: \n");
  857. printf ("1. Escolha Multipla \n");
  858. printf ("2. Verdadeiro ou Falso \n");
  859. printf ("3. Ordenacao \n");
  860. printf ("4. Texto \n");
  861. printf ("0. Sair \n");
  862. fflush (stdin);
  863. scanf ("%i", &opcao);
  864.  
  865. switch (opcao) {
  866. case 1 : printf ("Ira alterar uma pergunta do tipo <Escolha Multipla>. \n");
  867. registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
  868. if (registoDePerguntasEM == NULL){
  869. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
  870. return;
  871. }
  872. while (!feof(registoDePerguntasEM)){
  873. resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
  874. if (resultadoEM){
  875. printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
  876. printf ("Enunciado: %s \n", infoEMTemp.enunciado);
  877. printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
  878. printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
  879. printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
  880. printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
  881. }
  882. }
  883. do{
  884. printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende alterar? \n");
  885. printf ("1. Enunciado \n");
  886. printf ("2. Resposta Correta \n");
  887. printf ("3. Resposta Incorreta 1 \n");
  888. printf ("4. Resposta Incorreta 2 \n");
  889. printf ("5. Resposta Incorreta 3 \n");
  890. printf ("0. Sair \n");
  891. fflush (stdin);
  892. scanf ("%i", &opcaoEM);
  893.  
  894. switch (opcaoEM){
  895. case 1 : printf ("Introduza o novo Enunciado: \n");
  896. fflush (stdin);
  897. gets (enunciadoEM);
  898. alterarPerguntaEM_Enunciado (iniListaEM, enunciadoEM);
  899. break;
  900. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  901. fflush (stdin);
  902. gets (respostaCorretaEM);
  903. alterarPerguntaEM_RC (iniListaEM, respostaCorretaEM);
  904. break;
  905. case 3 : printf ("Introduza a nova Resposta Incorreta 1: \n");
  906. fflush (stdin);
  907. gets (respostaIncorreta1EM);
  908. alterarPerguntaEM_RI1 (iniListaEM, respostaIncorreta1EM);
  909. break;
  910. case 4 : printf ("Introduza a nova Resposta Incorreta 2: \n");
  911. fflush (stdin);
  912. gets (respostaIncorreta2EM);
  913. alterarPerguntaEM_RI2 (iniListaEM, respostaIncorreta2EM);
  914. break;
  915. case 5 : printf ("Introduza a nova Resposta Incorreta 3: \n");
  916. fflush (stdin);
  917. gets (respostaIncorreta3EM);
  918. alterarPerguntaEM_RI3 (iniListaEM, respostaIncorreta3EM);
  919. break;
  920. }
  921. } while (opcaoEM != 0);
  922. fclose (registoDePerguntasEM);
  923. break;
  924. case 2 : printf ("Ira alterar uma pergunta do tipo <Verdadeiro ou Falso>. \n");
  925. registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
  926. if (registoDePerguntasVF == NULL){
  927. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
  928. return;
  929. }
  930. while (!feof(registoDePerguntasVF)){
  931. resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
  932. if (resultadoVF){
  933. printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
  934. printf ("Enunciado: %s \n", infoVFTemp.enunciado);
  935. printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
  936. printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
  937. }
  938. }
  939. do{
  940. printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende alterar? \n");
  941. printf ("1. Enunciado \n");
  942. printf ("2. Resposta Correta \n");
  943. printf ("3. Resposta Incorreta \n");
  944. printf ("0. Sair \n");
  945. fflush (stdin);
  946. scanf ("%i", &opcaoVF);
  947.  
  948. switch (opcaoVF){
  949. case 1 : printf ("Introduza o novo Enunciado: \n");
  950. fflush (stdin);
  951. gets (enunciadoVF);
  952. alterarPerguntaVF_Enunciado (iniListaVF, enunciadoVF);
  953. break;
  954. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  955. fflush (stdin);
  956. gets (respostaCorretaVF);
  957. alterarPerguntaVF_RC (iniListaVF, respostaCorretaVF);
  958. break;
  959. case 3 : printf ("Introduza a nova Resposta Incorreta: \n");
  960. fflush (stdin);
  961. gets (respostaIncorretaVF);
  962. alterarPerguntaVF_RI (iniListaVF, respostaIncorretaVF);
  963. break;
  964. }
  965. } while (opcaoVF != 0);
  966. fclose (registoDePerguntasVF);
  967. break;
  968. case 3 : printf ("Ira alterar uma pergunta do tipo <Ordenacao>. \n");
  969. registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
  970. if (registoDePerguntasO == NULL){
  971. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
  972. return;
  973. }
  974. while (!feof(registoDePerguntasO)){
  975. resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
  976. if (resultadoO){
  977. printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
  978. printf ("Enunciado: %s \n", infoOTemp.enunciado);
  979. printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
  980. }
  981. }
  982. do{
  983. printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
  984. printf ("1. Enunciado \n");
  985. printf ("2. Resposta Correta \n");
  986. printf ("0. Sair \n");
  987. fflush (stdin);
  988. scanf ("%i", &opcaoO);
  989.  
  990. switch (opcaoO){
  991. case 1 : printf ("Introduza o novo Enunciado: \n");
  992. fflush (stdin);
  993. gets (enunciadoO);
  994. alterarPerguntaO_Enunciado (iniListaO, enunciadoO);
  995. break;
  996. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  997. fflush (stdin);
  998. gets (respostaCorretaO);
  999. alterarPerguntaO_RC (iniListaO, respostaCorretaO);
  1000. break;
  1001. }
  1002. } while (opcaoO != 0);
  1003. fclose (registoDePerguntasO);
  1004. break;
  1005. case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
  1006. registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
  1007. if (registoDePerguntasT == NULL){
  1008. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
  1009. return;
  1010. }
  1011. while (!feof(registoDePerguntasT)){
  1012. resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
  1013. if (resultadoT){
  1014. printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
  1015. printf ("Enunciado: %s \n", infoTTemp.enunciado);
  1016. printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
  1017. }
  1018. }
  1019. do{
  1020. printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
  1021. printf ("1. Enunciado \n");
  1022. printf ("2. Resposta Correta \n");
  1023. printf ("0. Sair \n");
  1024. fflush (stdin);
  1025. scanf ("%i", &opcaoT);
  1026.  
  1027. switch (opcaoVF){
  1028. case 1 : printf ("Introduza o novo Enunciado: \n");
  1029. fflush (stdin);
  1030. gets (enunciadoT);
  1031. alterarPerguntaT_Enunciado (iniListaT, enunciadoT);
  1032. break;
  1033. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  1034. fflush (stdin);
  1035. gets (respostaCorretaT);
  1036. alterarPerguntaT_RC (iniListaT, respostaCorretaT);
  1037. break;
  1038. }
  1039. } while (opcaoT != 0);
  1040. fclose (registoDePerguntasT);
  1041. break;
  1042. }
  1043. } while (opcao != 0);
  1044. }
  1045.  
  1046. void removerPerguntasEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, int numeroEM, FILE *registoDePerguntasEM){
  1047.  
  1048. ELEMENTO_EM *auxEM = NULL;
  1049.  
  1050. auxEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM *));
  1051.  
  1052. if (auxEM == NULL){
  1053. printf ("ERRO ao reservar memoria. \n \a");
  1054. return;
  1055. }
  1056.  
  1057. auxEM = *iniListaEM;
  1058.  
  1059. if (*iniListaEM == NULL){
  1060. printf ("Lista VAZIA! \n \a");
  1061. return;
  1062. }
  1063.  
  1064. while (auxEM != NULL && auxEM->infoEM.numero != numeroEM){
  1065. auxEM = auxEM->seguinte;
  1066. }
  1067.  
  1068. if (auxEM == NULL){
  1069. printf ("Numero da pergunta NAO EXISTE. \n");
  1070. return;
  1071. }
  1072.  
  1073. if (auxEM->anterior == NULL){
  1074. (*iniListaEM) = auxEM->seguinte;
  1075. if ((*iniListaEM) != NULL){
  1076. (*iniListaEM)->anterior = NULL;
  1077. }
  1078. else{
  1079. auxEM->anterior->seguinte = auxEM->seguinte;
  1080. }
  1081. }
  1082.  
  1083. if (auxEM->seguinte == NULL){
  1084. (*fimListaEM) = auxEM->anterior;
  1085. if ((*fimListaEM) != NULL){
  1086. (*fimListaEM)->seguinte = NULL;
  1087. }
  1088. else{
  1089. auxEM->seguinte->anterior = auxEM->anterior;
  1090. }
  1091. }
  1092.  
  1093. free (auxEM);
  1094. }
  1095.  
  1096. void removerPerguntasVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, int numeroVF){
  1097.  
  1098. ELEMENTO_VF *auxVF = NULL;
  1099.  
  1100. auxVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF *));
  1101.  
  1102. if (auxVF == NULL){
  1103. printf ("ERRO ao reservar memoria. \n \a");
  1104. return;
  1105. }
  1106.  
  1107. auxVF = *iniListaVF;
  1108.  
  1109. if (*iniListaVF == NULL){
  1110. printf ("Lista VAZIA! \n \a");
  1111. return;
  1112. }
  1113.  
  1114. while (auxVF != NULL && auxVF->infoVF.numero != numeroVF){
  1115. auxVF = auxVF->seguinte;
  1116. }
  1117.  
  1118. if (auxVF == NULL){
  1119. printf ("Numero da pergunta NAO EXISTE. \n");
  1120. return;
  1121. }
  1122.  
  1123. if (auxVF->anterior == NULL){
  1124. (*iniListaVF) = auxVF->seguinte;
  1125. if ((*iniListaVF) != NULL){
  1126. (*iniListaVF)->anterior = NULL;
  1127. }
  1128. else{
  1129. auxVF->anterior->seguinte = auxVF->seguinte;
  1130. }
  1131. }
  1132.  
  1133. if (auxVF->seguinte == NULL){
  1134. (*fimListaVF) = auxVF->anterior;
  1135. if ((*fimListaVF) != NULL){
  1136. (*fimListaVF)->seguinte = NULL;
  1137. }
  1138. else{
  1139. auxVF->seguinte->anterior = auxVF->anterior;
  1140. }
  1141. }
  1142.  
  1143. free (auxVF);
  1144. }
  1145.  
  1146. void removerPerguntasO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, int numeroO){
  1147.  
  1148. ELEMENTO_O *auxO = NULL;
  1149.  
  1150. auxO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O *));
  1151.  
  1152. if (auxO == NULL){
  1153. printf ("ERRO ao reservar memoria. \n \a");
  1154. return;
  1155. }
  1156.  
  1157. auxO = *iniListaO;
  1158.  
  1159. if (*iniListaO == NULL){
  1160. printf ("Lista VAZIA! \n \a");
  1161. return;
  1162. }
  1163.  
  1164. while (auxO != NULL && auxO->infoO.numero != numeroO){
  1165. auxO = auxO->seguinte;
  1166. }
  1167.  
  1168. if (auxO == NULL){
  1169. printf ("Numero da pergunta NAO EXISTE. \n");
  1170. return;
  1171. }
  1172.  
  1173. if (auxO->anterior == NULL){
  1174. (*iniListaO) = auxO->seguinte;
  1175. if ((*iniListaO) != NULL){
  1176. (*iniListaO)->anterior = NULL;
  1177. }
  1178. else{
  1179. auxO->anterior->seguinte = auxO->seguinte;
  1180. }
  1181. }
  1182.  
  1183. if (auxO->seguinte == NULL){
  1184. (*fimListaO) = auxO->anterior;
  1185. if ((*fimListaO) != NULL){
  1186. (*fimListaO)->seguinte = NULL;
  1187. }
  1188. else{
  1189. auxO->seguinte->anterior = auxO->anterior;
  1190. }
  1191. }
  1192.  
  1193. free (auxO);
  1194. }
  1195.  
  1196. void removerPerguntasT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, int numeroT){
  1197.  
  1198. ELEMENTO_T *auxT = NULL;
  1199.  
  1200. auxT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T *));
  1201.  
  1202. if (auxT == NULL){
  1203. printf ("ERRO ao reservar memoria. \n \a");
  1204. return;
  1205. }
  1206.  
  1207. auxT = *iniListaT;
  1208.  
  1209. if (*iniListaT == NULL){
  1210. printf ("Lista VAZIA! \n \a");
  1211. return;
  1212. }
  1213.  
  1214. while (auxT != NULL && auxT->infoT.numero != numeroT){
  1215. auxT = auxT->seguinte;
  1216. }
  1217.  
  1218. if (auxT == NULL){
  1219. printf ("Numero da pergunta NAO EXISTE. \n");
  1220. return;
  1221. }
  1222.  
  1223. if (auxT->anterior == NULL){
  1224. (*iniListaT) = auxT->seguinte;
  1225. if ((*iniListaT) != NULL){
  1226. (*iniListaT)->anterior = NULL;
  1227. }
  1228. else{
  1229. auxT->anterior->seguinte = auxT->seguinte;
  1230. }
  1231. }
  1232.  
  1233. if (auxT->seguinte == NULL){
  1234. (*fimListaT) = auxT->anterior;
  1235. if ((*fimListaT) != NULL){
  1236. (*fimListaT)->seguinte = NULL;
  1237. }
  1238. else{
  1239. auxT->seguinte->anterior = auxT->anterior;
  1240. }
  1241. }
  1242.  
  1243. free (auxT);
  1244. }
  1245.  
  1246.  
  1247. void removerPerguntas (FILE *registoDePerguntasEM, FILE *registoDePerguntasVF, FILE *registoDePerguntasO, FILE *registoDePerguntasT,
  1248. ELEMENTO_EM *iniListaEM, ELEMENTO_EM *fimListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_VF *fimListaVF,
  1249. ELEMENTO_O *iniListaO, ELEMENTO_O *fimListaO, ELEMENTO_T *iniListaT, ELEMENTO_T *fimListaT){
  1250.  
  1251. int opcao = 0;
  1252. int numeroEM = 0;
  1253. int numeroVF = 0;
  1254. int numeroO = 0;
  1255. int numeroT = 0;
  1256. int resultadoEM = 0;
  1257. int resultadoVF = 0;
  1258. int resultadoO = 0;
  1259. int resultadoT = 0;
  1260. INFO_EM infoEMTemp;
  1261. INFO_VF infoVFTemp;
  1262. INFO_O infoOTemp;
  1263. INFO_T infoTTemp;
  1264.  
  1265. printf ("***** REMOCAO DE PERGUNTAS ***** \n");
  1266. printf ("******************************** \n\n");
  1267.  
  1268. do {
  1269. printf ("Que tipo de pergunta pretende remover? \n");
  1270. printf ("1. Escolha Multipla \n");
  1271. printf ("2. Verdadeiro ou Falso \n");
  1272. printf ("3. Ordenacao \n");
  1273. printf ("4. Texto \n");
  1274. printf ("0. Sair \n");
  1275. fflush (stdin);
  1276. scanf ("%i", &opcao);
  1277.  
  1278. switch (opcao){
  1279. case 1 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
  1280. registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
  1281. if (registoDePerguntasEM == NULL){
  1282. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
  1283. return;
  1284. }
  1285. while (!feof(registoDePerguntasEM)){
  1286. resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
  1287. if (resultadoEM){
  1288. printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
  1289. printf ("Enunciado: %s \n", infoEMTemp.enunciado);
  1290. printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
  1291. printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
  1292. printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
  1293. printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
  1294. }
  1295. }
  1296. printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende remover? \n");
  1297. fflush (stdin);
  1298. scanf ("%i", &numeroEM);
  1299. removerPerguntasEM (&iniListaEM, &fimListaEM, numeroEM, registoDePerguntasEM);
  1300. fclose (registoDePerguntasEM);
  1301. break;
  1302. case 2 : printf ("Ira remover uma pergunta do tipo <Verdadeiro ou Falso>. \n");
  1303. registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
  1304. if (registoDePerguntasVF == NULL){
  1305. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
  1306. return;
  1307. }
  1308. while (!feof(registoDePerguntasVF)){
  1309. resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
  1310. if (resultadoVF){
  1311. printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
  1312. printf ("Enunciado: %s \n", infoVFTemp.enunciado);
  1313. printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
  1314. printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
  1315. }
  1316. }
  1317. printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende remover? \n");
  1318. fflush (stdin);
  1319. scanf ("%i", &numeroVF);
  1320. removerPerguntasVF (&iniListaVF, &fimListaVF, numeroVF);
  1321. fclose (registoDePerguntasVF);
  1322. break;
  1323. case 3 : printf ("Ira remover uma pergunta do tipo <Ordenacao>. \n");
  1324. registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
  1325. if (registoDePerguntasO == NULL){
  1326. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
  1327. return;
  1328. }
  1329. while (!feof(registoDePerguntasO)){
  1330. resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
  1331. if (resultadoO){
  1332. printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
  1333. printf ("Enunciado: %s \n", infoOTemp.enunciado);
  1334. printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
  1335. }
  1336. }
  1337. printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
  1338. fflush (stdin);
  1339. scanf ("%i", &numeroO);
  1340. removerPerguntasO (&iniListaO, &fimListaO, numeroO);
  1341. fclose (registoDePerguntasO);
  1342. break;
  1343. case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
  1344. registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
  1345. if (registoDePerguntasT == NULL){
  1346. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
  1347. return;
  1348. }
  1349. while (!feof(registoDePerguntasT)){
  1350. resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
  1351. if (resultadoT){
  1352. printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
  1353. printf ("Enunciado: %s \n", infoTTemp.enunciado);
  1354. printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
  1355. }
  1356. }
  1357. printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
  1358. fflush (stdin);
  1359. scanf ("%i", &numeroT);
  1360. removerPerguntasT (&iniListaT, &fimListaT, numeroT);
  1361. fclose (registoDePerguntasT);
  1362. break;
  1363. }
  1364. } while (opcao != 0);
  1365.  
  1366.  
  1367. }
  1368.  
  1369. void menuAdministrador (ADMINISTRADOR administrador, FILE *registoAdministradores, JOGADOR jogador, FILE *registoJogadores){
  1370.  
  1371. int opcao;
  1372. FILE *registoDePerguntasEM = NULL;
  1373. FILE *registoDePerguntasVF = NULL;
  1374. FILE *registoDePerguntasO = NULL;
  1375. FILE *registoDePerguntasT = NULL;
  1376. ELEMENTO_EM *iniListaEM = NULL;
  1377. ELEMENTO_EM *fimListaEM = NULL;
  1378. ELEMENTO_VF *iniListaVF = NULL;
  1379. ELEMENTO_VF *fimListaVF = NULL;
  1380. ELEMENTO_O *iniListaO = NULL;
  1381. ELEMENTO_O *fimListaO = NULL;
  1382. ELEMENTO_T *iniListaT = NULL;
  1383. ELEMENTO_T *fimListaT = NULL;
  1384. INFO_EM newInfoEM;
  1385. INFO_VF newInfoVF;
  1386. INFO_O newInfoO;
  1387. INFO_T newInfoT;
  1388. int numTotalEM = 0;
  1389. int numTotalVF = 0;
  1390. int numTotalT = 0;
  1391. int numTotalO = 0;
  1392.  
  1393. do{
  1394. printf ("***** MENU DE ADMINISTRACAO ***** \n");
  1395. printf ("********************************* \n");
  1396. printf ("Introduza a opcao pretendida: \n");
  1397. printf ("1. Acrescentar perguntas \n");
  1398. printf ("2. Alterar perguntas \n");
  1399. printf ("3. Remover perguntas \n");
  1400. printf ("4. Criar Administrador \n");
  1401. printf ("5. Listar Administradores \n");
  1402. printf ("6. Listar Jogadores \n");
  1403. printf ("0. Sair \n");
  1404. fflush(stdin);
  1405. scanf ("%i", &opcao);
  1406.  
  1407. switch (opcao){
  1408. case 1 : acrescentarPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
  1409. iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT, newInfoEM, newInfoVF,
  1410. newInfoO, newInfoT, numTotalEM, numTotalVF, numTotalO, numTotalT);
  1411. break;
  1412. case 2 : alterarPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
  1413. iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT);
  1414. break;
  1415. case 3 : removerPerguntas (registoDePerguntasEM, registoDePerguntasVF, registoDePerguntasO, registoDePerguntasT,
  1416. iniListaEM, fimListaEM, iniListaVF, fimListaVF, iniListaO, fimListaO, iniListaT, fimListaT);
  1417. break;
  1418. case 4 : criarAdministrador (administrador, registoAdministradores);
  1419. break;
  1420. case 5 : listarAdministradores (administrador, registoAdministradores);
  1421. break;
  1422. case 6 : listarJogadores (jogador, registoJogadores);
  1423. break;
  1424. }
  1425. } while (opcao != 0);
  1426. }
  1427.  
  1428. void jogoSmall (){
  1429.  
  1430. printf ("***** JOGO DO TIPO S ***** \n");
  1431. printf ("************************** \n\n");
  1432.  
  1433. printf ("Neste tipo de jogo serao feitas 3 perguntas de cada grupo. \n");
  1434. printf ("(FALTA IMPLEMENTAR) \n\n");
  1435.  
  1436. }
  1437.  
  1438. void jogoMedium (){
  1439.  
  1440. printf ("***** JOGO DO TIPO M ***** \n");
  1441. printf ("************************** \n\n");
  1442.  
  1443. printf ("Neste tipo de jogo serao feitas 6 perguntas de cada grupo. \n");
  1444. printf ("(FALTA IMPLEMENTAR) \n\n");
  1445. }
  1446.  
  1447. void jogoLarge (){
  1448.  
  1449. printf ("***** JOGO DO TIPO L ***** \n");
  1450. printf ("************************** \n\n");
  1451.  
  1452. printf ("Neste tipo de jogo serao feitas 12 perguntas de cada grupo. \n");
  1453. printf ("(FALTA IMPLEMENTAR) \n\n");
  1454.  
  1455. }
  1456.  
  1457. void jogoXL (){
  1458.  
  1459. printf ("***** JOGO DO TIPO XL ***** \n");
  1460. printf ("*************************** \n\n");
  1461.  
  1462. printf ("Neste tipo de jogo serao feitas 24 perguntas de cada grupo. \n");
  1463. printf ("(FALTA IMPLEMENTAR) \n\n");
  1464.  
  1465. }
  1466.  
  1467. void instrucoesJogador (){
  1468.  
  1469. printf ("***** PAINEL DE INSTRUCOES ***** \n");
  1470. printf ("******************************** \n");
  1471.  
  1472. printf ("S - <Small> : 3 perguntas de cada grupo \n");
  1473. printf ("M - <Medium> : 6 perguntas de cada grupo \n");
  1474. printf ("L - <Large> : 12 perguntas de cada grupo \n");
  1475. printf ("X - <Extra Large> : 24 perguntas de cada grupo \n\n");
  1476.  
  1477. printf ("O jogo e constituido por 4 grupos de perguntas de cultura geral:\n");
  1478. printf ("um grupo de escolha multipla, um grupo de verdadeiro ou falso,\n");
  1479. printf ("um grupo de ordenacao e um grupo de quem perde sai. \n\n");
  1480.  
  1481. printf ("- No 1o grupo, de escolha multipla, o jogador deve selecionar a \n");
  1482. printf (" resposta correta entre as 4 opcoes de resposta possiveis. Cada \n");
  1483. printf (" resposta correta acresce a pontuacao do jogador em 15 pontos. \n");
  1484. printf (" Se errar, sao-lhe retirados 10 pontos ao total de pontos. \n\n");
  1485.  
  1486. printf ("- No 2o grupo, verdadeiro ou falso, cada pergunta tem apenas duas \n");
  1487. printf (" possiveis respostas: Verdadeiro ou Falso. Se o jogador acertar \n");
  1488. printf (" soma 30 pontos a pontuação global, senão sao-lhe retirados 30 pontos. \n\n");
  1489.  
  1490. printf ("- No 3o grupo, ordenacao, o jogador devera ordenar as 3 opcoes \n");
  1491. printf (" apresentadas. Se a ordenacao estiver correta sao-lhe somada \n");
  1492. printf (" 50 pontos a pontuacao total, senao sao-lhe retirados 20 pontos. \n\n");
  1493.  
  1494. printf ("- No 4o grupo, quem perde sai, as perguntas devem ser de resposta curta.\n");
  1495. printf (" Se o jogador errar uma reposta sai do grupo com 0 pontos e não responde \n");
  1496. printf (" a mais perguntas do grupo. Se acertar em todas as respostas, soma 10 \n");
  1497. printf (" pontos por cada pergunta ao total de pontos. \n");
  1498.  
  1499. }
  1500.  
  1501. void menuJogador (JOGADOR jogador, FILE *registoJogadores){
  1502.  
  1503. int opcao;
  1504.  
  1505. do {
  1506. printf ("***** MENU DO JOGO ***** \n");
  1507. printf ("************************ \n");
  1508. printf ("Introduza o tipo de jogo que pretende iniciar: \n");
  1509. printf ("1. Small \n");
  1510. printf ("2. Medium \n");
  1511. printf ("3. Large \n");
  1512. printf ("4. Extra Large \n");
  1513. printf ("5. Listar Jogadores \n");
  1514. printf ("6. Instrucoes e outras informacoes importantes \n");
  1515. printf ("0. Sair \n");
  1516. fflush (stdin);
  1517. scanf ("%i", &opcao);
  1518.  
  1519. switch (opcao){
  1520. case 1 : jogoSmall ();
  1521. break;
  1522. case 2 : jogoMedium ();
  1523. break;
  1524. case 3 : jogoLarge ();
  1525. break;
  1526. case 4 : jogoXL ();
  1527. break;
  1528. case 5 : listarJogadores (jogador, registoJogadores);
  1529. break;
  1530. case 6 : instrucoesJogador ();
  1531. break;
  1532. }
  1533. } while (opcao != 0);
  1534. }
  1535.  
  1536. int main(int argc, char *argv[]) {
  1537.  
  1538. ADMINISTRADOR administrador;
  1539. JOGADOR jogador;
  1540. int opcao;
  1541. FILE *registoAdministradores = NULL;
  1542. FILE *registoJogadores = NULL;
  1543. int administradorExiste = 0;
  1544. int jogadorExiste = 0;
  1545. FILE *registoDePerguntasEC = NULL;
  1546. FILE *registoDePerguntasVF = NULL;
  1547. FILE *registoDePerguntasO = NULL;
  1548. FILE *registoDePerguntasT = NULL;
  1549. ELEMENTO_EM *iniListaEM = NULL;
  1550. ELEMENTO_EM *fimListaEM = NULL;
  1551. ELEMENTO_VF *iniListaVF = NULL;
  1552. ELEMENTO_VF *fimListaVF = NULL;
  1553. ELEMENTO_O *iniListaO = NULL;
  1554. ELEMENTO_O *fimListaO = NULL;
  1555. ELEMENTO_T *iniListaT = NULL;
  1556. ELEMENTO_T *fimListaT = NULL;
  1557.  
  1558. do {
  1559. printf ("**************************** QUEM SABE, SABE! ******************************\n");
  1560. printf ("****************************** MENU INICIAL ********************************\n");
  1561. printf ("****************************************************************************\n");
  1562. printf ("Introduza a opcao pretendida: \n");
  1563. printf ("1. Entrar como Administrador \n");
  1564. printf ("2. Entrar como Jogador \n");
  1565. printf ("0. Sair \n");
  1566. fflush(stdin);
  1567. scanf ("%i", &opcao);
  1568.  
  1569. switch (opcao){
  1570. case 1 : administradorExiste = existeAdministrador (administrador, registoAdministradores);
  1571. if (administradorExiste == 2){
  1572. printf ("Aprovado como ADMINISTRADOR. \n");
  1573. menuAdministrador ( administrador, registoAdministradores, jogador, registoAdministradores);
  1574. }
  1575. if (administradorExiste == 1){
  1576. printf ("Identificacao ERRADA. \n");
  1577. continue; // permite reinicar o ciclo
  1578. }
  1579. if (administradorExiste == 0){
  1580. printf ("Reprovado como ADMINISTRADOR. \n");
  1581. printf ("Tente entrar como JOGADOR. \n");
  1582. }
  1583. break;
  1584. case 2 : jogadorExiste = existeJogador (jogador, registoJogadores);
  1585. if (jogadorExiste == 2){
  1586. printf ("Aprovado como JOGADOR. \n");
  1587. menuJogador (jogador, registoJogadores);
  1588. }
  1589.  
  1590. if (jogadorExiste == 1){
  1591. printf ("Identificacao ERRADA. \n");
  1592. continue; // permite reinicar o ciclo
  1593. }
  1594. if (jogadorExiste == 0) {
  1595. printf ("Sera introduzido como novo JOGADOR. \n");
  1596. criarJogador (jogador, registoJogadores);
  1597. }
  1598. break;
  1599. case 3 : criarAdministrador (administrador, registoAdministradores);
  1600. break;
  1601. }
  1602. } while (opcao != 0);
  1603.  
  1604. return 0;
  1605. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement