Advertisement
Jvsierra

top

Nov 12th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio2.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7.  
  8. #define X_I 1
  9. #define Y_I 1
  10. #define X_F 80
  11. #define Y_F 20
  12.  
  13. struct TpPalavra
  14. {
  15. char port[30], ing[30], significado[100];
  16. int pont, status;
  17. };
  18.  
  19. struct TpData
  20. {
  21. int dia, mes, ano;
  22. };
  23.  
  24. struct TpPessoa
  25. {
  26. char nome[40], login[10];
  27. int senha, pont, status;
  28. TpData Data;
  29. };
  30.  
  31. struct TpPalavForca
  32. {
  33. char Palavra[30], Login[10];
  34. int Acertou;
  35. };
  36.  
  37. void Quadro()
  38. {
  39. int i;
  40. textcolor(14);
  41. gotoxy(X_I,Y_I);
  42. printf("%c",201);
  43. gotoxy(X_F,Y_I);
  44. printf("%c",187);
  45. gotoxy(X_I,Y_F);
  46. printf("%c",200);
  47. gotoxy(X_F,Y_F);
  48. printf("%c",188);
  49. for(i = X_I + 1; i < X_F; i++)
  50. {
  51. gotoxy(i, Y_I);
  52. printf("%c", 205);
  53. gotoxy(i, Y_F);
  54. printf("%c", 205);
  55. }
  56.  
  57. for(i = Y_I + 1; i < Y_F; i++)
  58. {
  59. gotoxy(X_I, i);
  60. printf("%c", 186);
  61.  
  62. gotoxy(X_F, i);
  63. printf("%c", 186);
  64. }
  65.  
  66. textcolor(15);
  67. }
  68.  
  69. void QuadroFlexivel(int XI, int YI, int XF, int YF)
  70. {
  71. int i;
  72. textcolor(14);
  73. gotoxy(XI, YI);
  74. printf("%c",201);
  75. gotoxy(XF, YI);
  76. printf("%c",187);
  77. gotoxy(XI, YF);
  78. printf("%c",200);
  79. gotoxy(XF, YF);
  80. printf("%c",188);
  81.  
  82. for(i = XI + 1; i < XF; i++)
  83. {
  84. gotoxy(i, YI);
  85. printf("%c", 205);
  86. gotoxy(i, YF);
  87. printf("%c", 205);
  88. }
  89.  
  90. for(i = YI + 1; i < YF; i++)
  91. {
  92. gotoxy(XI, i);
  93. printf("%c", 186);
  94.  
  95. gotoxy(XF, i);
  96. printf("%c", 186);
  97. }
  98. }
  99.  
  100. void Cabecalho(char Titulo[100])
  101. {
  102. Quadro();
  103.  
  104. textcolor(15);
  105.  
  106. gotoxy(30, 2);
  107.  
  108. printf("%s\n", Titulo);
  109.  
  110. textcolor(14);
  111.  
  112. for(int i = 2; i <= 79; i++)
  113. {
  114. gotoxy(i, 3);
  115. printf("%c", 205);
  116. }
  117.  
  118. textcolor(15);
  119. }
  120.  
  121. void ImprimePalavra(TpPalavra Pal, int linha)
  122. {
  123. QuadroFlexivel(2, linha - 1, 79, linha + 4);
  124. gotoxy(3, linha++);
  125. textcolor(14);
  126. printf("Portugues: ");
  127. textcolor(15);
  128. printf("%s", Pal.port);
  129. gotoxy(3, linha++);
  130. textcolor(14);
  131. printf("Ingles: ");
  132. textcolor(15);
  133. printf("%s", Pal.ing);
  134. gotoxy(3, linha++);
  135. textcolor(14);
  136. printf("Pontuacao: ");
  137. textcolor(15);
  138. printf("%d", Pal.pont);
  139. gotoxy(3, linha);
  140. printf("%s", Pal.significado);
  141. }
  142.  
  143. void ImprimePessoa(TpPessoa Pes, int linha)
  144. {
  145. QuadroFlexivel(2, linha - 1, 79, linha + 4);
  146. gotoxy(3, linha++);
  147. textcolor(14);
  148. printf("Nome: ");
  149. textcolor(15);
  150. printf("%s", Pes.nome);
  151. gotoxy(3, linha);
  152. textcolor(14);
  153. printf("Login: ");
  154. textcolor(15);
  155. printf("%s", Pes.login);
  156. gotoxy(30, linha);
  157. textcolor(14);
  158. printf("Pontuacao: ");
  159. textcolor(15);
  160. printf("%d", Pes.pont);
  161. linha++;
  162. gotoxy(3, linha);
  163. textcolor(14);
  164. printf("Data: ");
  165. textcolor(15);
  166. printf("%d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
  167.  
  168. textcolor(15);
  169. }
  170.  
  171. void RelatorioPalavras(FILE *PtrArq)
  172. {
  173. TpPalavra Pal;
  174. int linha = 6;
  175.  
  176. system("cls");
  177.  
  178. QuadroFlexivel(1, 1, 80, 3);
  179. gotoxy(30, 2);
  180. printf("Relatorio de palavras");
  181.  
  182. PtrArq = fopen("Palavra.dat", "rb");
  183.  
  184. if(PtrArq == NULL)
  185. {
  186. gotoxy(30, 6);
  187. textcolor(4);
  188. printf("Arquivo de palavras inexistente");
  189. textcolor(15);
  190. }
  191. else
  192. {
  193. rewind(PtrArq);
  194.  
  195. fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  196.  
  197. while(!feof(PtrArq))
  198. {
  199. if(Pal.status == 1)
  200. {
  201. ImprimePalavra(Pal, linha);
  202. linha += 6;
  203. }
  204.  
  205. fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  206. }
  207.  
  208. gotoxy(1, 1);
  209. }
  210.  
  211. fclose(PtrArq);
  212.  
  213. getch();
  214. }
  215.  
  216. int PosicaoMaiorPessoa(FILE *PtrPes, int NumR)
  217. {
  218. TpPessoa Pes;
  219. int Pos, i = 0;
  220. char MaiorNome[40];
  221.  
  222. rewind(PtrPes);
  223. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  224.  
  225. strcpy(MaiorNome, Pes.login);
  226. Pos = 0;
  227.  
  228. for(i = 1; i < NumR; i++)
  229. {
  230. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  231.  
  232. if(stricmp(Pes.login, MaiorNome) > 0)
  233. {
  234. strcpy(MaiorNome, Pes.login);
  235. Pos = i;
  236. }
  237. }
  238.  
  239. return Pos * sizeof(TpPessoa);
  240. }
  241.  
  242. void SelecaoDiretaPessoa(FILE *PtrPes)
  243. {
  244. int PosMaior, NumR;
  245. TpPessoa PesA, PesB;
  246.  
  247. PtrPes = fopen("Pessoa.dat", "rb+");
  248.  
  249. fseek(PtrPes, 0, 2);
  250. NumR = ftell(PtrPes) / sizeof(TpPessoa);
  251.  
  252. while(NumR > 0)
  253. {
  254. PosMaior = PosicaoMaiorPessoa(PtrPes, NumR);
  255.  
  256. if(PosMaior < (NumR - 1) * sizeof(TpPessoa))
  257. {
  258. fseek(PtrPes, PosMaior, 0);
  259. fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  260. fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  261. fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  262.  
  263. fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  264. fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  265. fseek(PtrPes, PosMaior, 0);
  266. fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  267. }
  268.  
  269. NumR--;
  270. }
  271.  
  272. fclose(PtrPes);
  273. }
  274.  
  275. void InsercaoDiretaPessoa(FILE *PtrPes)
  276. {
  277. TpPessoa PesA, PesB;
  278. int NumR, Pos;
  279.  
  280. PtrPes = fopen("Pessoa.dat", "rb+");
  281.  
  282. if(PtrPes != NULL)
  283. {
  284. fseek(PtrPes, 0, 2);
  285. NumR = ftell(PtrPes) / sizeof(TpPessoa);
  286.  
  287. if(NumR > 1)
  288. {
  289. Pos = NumR - 1;
  290.  
  291. fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  292. fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  293. fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  294. fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  295.  
  296. while(Pos > 0 && stricmp(PesA.login, PesB.login) < 0)
  297. {
  298. fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  299. fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  300. fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  301. fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  302.  
  303. Pos--;
  304.  
  305. if(Pos > 0)
  306. {
  307. fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  308. fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  309. fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  310. fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  311. }
  312. }
  313. }
  314. }
  315.  
  316. fclose(PtrPes);
  317. }
  318.  
  319. void InsercaoDiretaPalavra(FILE *PtrPal)
  320. {
  321. TpPalavra PalA, PalB;
  322. int Pos, NumR;
  323.  
  324. PtrPal = fopen("Palavra.dat", "rb+");
  325.  
  326. if(PtrPal != NULL)
  327. {
  328. fseek(PtrPal, 0, 2);
  329.  
  330. NumR = ftell(PtrPal) / sizeof(TpPalavra);
  331.  
  332. if(NumR > 1)
  333. {
  334. Pos = NumR - 1;
  335.  
  336. fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
  337. fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
  338. fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
  339. fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
  340.  
  341. while(Pos > 0 && stricmp(PalA.port, PalB.port) < 0)
  342. {
  343. fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
  344. fwrite(&PalB, sizeof(TpPalavra), 1, PtrPal);
  345. fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
  346. fwrite(&PalA, sizeof(TpPalavra), 1, PtrPal);
  347.  
  348. Pos--;
  349.  
  350. if(Pos > 0)
  351. {
  352. fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
  353. fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
  354. fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
  355. fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
  356. }
  357. }
  358. }
  359. }
  360.  
  361. fclose(PtrPal);
  362. }
  363.  
  364. void RelatorioPessoa(FILE *PtrPes)
  365. {
  366. int linha = 5;
  367. TpPessoa Pes;
  368.  
  369. clrscr();
  370.  
  371. QuadroFlexivel(1, 1, 80, 3);
  372. gotoxy(30, 2);
  373. printf("Relatorio de pessoas");
  374.  
  375. PtrPes = fopen("Pessoa.dat", "rb");
  376.  
  377. if(PtrPes == NULL)
  378. {
  379. gotoxy(30, 6);
  380. textcolor(4);
  381. printf("Arquivo de pessoas inexistente");
  382. textcolor(15);
  383. }
  384. else
  385. {
  386. rewind(PtrPes);
  387.  
  388. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  389.  
  390. while(!feof(PtrPes))
  391. {
  392. if(Pes.status == 1)
  393. {
  394. ImprimePessoa(Pes, linha);
  395. linha += 6;
  396. }
  397.  
  398. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  399. }
  400.  
  401. gotoxy(1, 1);
  402. }
  403.  
  404. fclose(PtrPes);
  405.  
  406. getch();
  407. }
  408.  
  409. int BuscaPalavraPort(FILE *PtrPal, char Palavra[40])
  410. {
  411. TpPalavra Pal;
  412.  
  413. //BUSCA EXAUSTIVA DE PALAVRAS
  414.  
  415. rewind(PtrPal);
  416.  
  417. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  418.  
  419. while(!feof(PtrPal) && stricmp(Pal.port, Palavra) != 0)
  420. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  421.  
  422. if(stricmp(Palavra, Pal.port) == 0)
  423. return ftell(PtrPal) - sizeof(TpPalavra);
  424. else
  425. return -1;
  426. }
  427.  
  428. int BuscaExaustivaPessoa(FILE *PtrPes, char login[10])
  429. {
  430. TpPessoa Pes;
  431.  
  432. rewind(PtrPes);
  433.  
  434. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  435.  
  436. while(!feof(PtrPes) && (stricmp(login, Pes.login) != 0 || Pes.status == 0))
  437. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  438.  
  439. if(stricmp(login, Pes.login) == 0)
  440. return ftell(PtrPes) - sizeof(TpPessoa);
  441. else
  442. return -1;
  443. }
  444. void BubbleSortPessoa(FILE *PtrPes)
  445. {
  446. TpPessoa PesA, PesB;
  447. int i, j, QntdR;
  448.  
  449. PtrPes = fopen("Pessoa.dat", "rb+");
  450.  
  451. fseek(PtrPes, 0, 2);
  452.  
  453. QntdR = ftell(PtrPes) / sizeof(TpPessoa);
  454.  
  455. while(QntdR > 0)
  456. {
  457. for(i = 0; i < QntdR - 1; i++)
  458. {
  459. fseek(PtrPes, i * sizeof(TpPessoa), 0);
  460. fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  461. fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  462.  
  463. if(stricmp(PesA.nome, PesB.nome) > 0)
  464. {
  465. fseek(PtrPes, i * sizeof(TpPessoa), 0);
  466. fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  467. fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  468. }
  469. }
  470.  
  471. QntdR--;
  472. }
  473.  
  474. fclose(PtrPes);
  475.  
  476. getch();
  477. }
  478.  
  479. void BubbleSortPalavra(FILE *PtrPal)
  480. {
  481. TpPalavra PalA, PalB;
  482. int i, j, QntdR;
  483.  
  484. PtrPal = fopen("Palavra.dat", "rb+");
  485.  
  486. if(PtrPal != NULL)
  487. {
  488. fseek(PtrPal, 0, 2);
  489. QntdR = ftell(PtrPal) / sizeof(TpPalavra);
  490.  
  491. while(QntdR > 0)
  492. {
  493. for(i = 0; i < QntdR - 1; i++)
  494. {
  495. fseek(PtrPal, i * sizeof(TpPalavra), 0);
  496. fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
  497. fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
  498.  
  499. if(stricmp(PalA.port, PalB.port) > 0)
  500. {
  501. fseek(PtrPal, i * sizeof(TpPalavra), 0);
  502. fwrite(&PalB, sizeof(TpPalavra), 1, PtrPal);
  503. fwrite(&PalA, sizeof(TpPalavra), 1, PtrPal);
  504. }
  505. }
  506.  
  507. QntdR--;
  508. }
  509. }
  510.  
  511. fclose(PtrPal);
  512. }
  513.  
  514. int BuscaSeqIndPessoa(FILE *PtrPes, char loginChave[10])
  515. {
  516. TpPessoa Pes;
  517.  
  518. rewind(PtrPes);
  519.  
  520. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  521.  
  522. while(!feof(PtrPes) && (stricmp(loginChave, Pes.login) > 0 || Pes.login == 0))
  523. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  524.  
  525. if(stricmp(loginChave, Pes.login) == 0)
  526. return ftell(PtrPes) - sizeof(TpPessoa);
  527. else
  528. return -1;
  529. }
  530.  
  531. int BuscaSentinelaPessoa(FILE *PtrPes, char loginChave[10])
  532. {
  533. FILE *PtrAux;
  534. int i = 0, j, NumR;
  535. TpPessoa R;
  536.  
  537. PtrPes = fopen("Pessoa.dat", "rb+");
  538. fseek(PtrPes, 0, 2);
  539. NumR = ftell(PtrPes) / sizeof(TpPessoa);
  540.  
  541. strcpy(R.login, loginChave);
  542.  
  543. fwrite(&R, sizeof(TpPessoa), 1, PtrPes);
  544.  
  545. rewind(PtrPes);
  546.  
  547. fread(&R, sizeof(TpPessoa), 1, PtrPes);
  548.  
  549. while(strcmp(R.login, loginChave) != 0 || R.status == 0)
  550. {
  551. i++;
  552. fread(&R, sizeof(TpPessoa), 1, PtrPes);
  553. }
  554.  
  555. PtrAux = fopen("Temp.dat", "ab+");
  556.  
  557. rewind(PtrPes);
  558.  
  559. for(j = 0; j < NumR; j++)
  560. {
  561. fread(&R, sizeof(TpPessoa), 1, PtrPes);
  562. fwrite(&R, sizeof(TpPessoa), 1, PtrAux);
  563. }
  564.  
  565. fclose(PtrPes);
  566. fclose(PtrAux);
  567.  
  568. remove("Pessoa.dat");
  569. rename("Temp.dat", "Pessoa.dat");
  570.  
  571. if(i < NumR)
  572. return i * sizeof(TpPessoa);
  573. else
  574. return -1;
  575. }
  576.  
  577. int BuscaBinariaPessoa(FILE *PtrPes, char loginChave[10])
  578. {
  579. int inicio = 0, meio, fim;
  580. TpPessoa R;
  581.  
  582. fseek(PtrPes, 0, 2);
  583.  
  584. fim = ftell(PtrPes) / sizeof(TpPessoa) - 1;
  585. meio = fim / 2;
  586.  
  587. fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  588. fread(&R, sizeof(TpPessoa), 1, PtrPes);
  589.  
  590. while(inicio < fim && (strcmp(loginChave, R.login) != 0 || R.status == 0))
  591. {
  592. if(strcmp(loginChave, R.login) > 0)
  593. inicio = meio + 1;
  594. else
  595. fim = meio - 1;
  596.  
  597. meio = (inicio + fim) / 2;
  598.  
  599. fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  600. fread(&R, sizeof(TpPessoa), 1, PtrPes);
  601. }
  602.  
  603. if(strcmp(loginChave, R.login) == 0)
  604. return meio * sizeof(TpPessoa);
  605. else
  606. return -1;
  607. }
  608.  
  609. int BuscaBinariaPalavra(FILE *PtrPal, char palavraChave[40])
  610. {
  611. TpPalavra R;
  612. int inicio = 0, meio, fim;
  613.  
  614. fseek(PtrPal, 0, 2);
  615.  
  616. fim = ftell(PtrPal) / sizeof(TpPalavra) - 1;
  617.  
  618. meio = fim / 2;
  619.  
  620. fseek(PtrPal, meio * sizeof(TpPalavra), 0);
  621. fread(&R, sizeof(TpPalavra), 1, PtrPal);
  622.  
  623. while(inicio < fim && (strcmp(R.port, palavraChave) != 0 && R.status == 0))
  624. {
  625. if(strcmp(palavraChave, R.port) > 0)
  626. inicio = meio + 1;
  627. else
  628. fim = meio - 1;
  629.  
  630. meio = (inicio + fim) / 2;
  631. fseek(PtrPal, meio * sizeof(TpPalavra), 0);
  632. fread(&R, sizeof(TpPalavra), 1, PtrPal);
  633. }
  634. if(strcmp(palavraChave, R.port) == 0)
  635. return meio * sizeof(TpPalavra);
  636. else
  637. return -1;
  638. }
  639.  
  640. void ExclusaoFisicaPessoa(FILE *PtrPes)
  641. {
  642. TpPessoa Pes;
  643. char LoginAux[10];
  644. int Pos;
  645.  
  646. system("cls");
  647. Cabecalho("Exclusao Fisica de Pessoas");
  648.  
  649. gotoxy(2, 4);
  650. printf("Pessoa a ser excluida:");
  651. fflush(stdin);
  652. gets(LoginAux);
  653.  
  654. while(strcmp(LoginAux, "\0") != 0)
  655. {
  656. PtrPes = fopen("Pessoa.dat", "rb");
  657.  
  658. if(PtrPes == NULL)
  659. {
  660. gotoxy(30, 6);
  661. textcolor(4);
  662. printf("Arquivo de pessoas inexistente");
  663. textcolor(15);
  664. fclose(PtrPes);
  665. }
  666. else
  667. {
  668. Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
  669.  
  670. if(Pos == -1)
  671. {
  672. gotoxy(30, 6);
  673. textcolor(4);
  674. printf("Login nao cadastrado");
  675. textcolor(15);
  676. fclose(PtrPes);
  677. }
  678. else
  679. {
  680. gotoxy(2, 5);
  681. printf("Dados encontrados:");
  682. fseek(PtrPes, Pos, 0);
  683. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  684. ImprimePessoa(Pes, 7);
  685.  
  686. gotoxy(2, 12);
  687. printf("Confirma exclusao?(S/N)");
  688.  
  689. if(toupper(getche()) == 'S')
  690. {
  691. FILE *PtrTemp = fopen("Temp.dat", "ab+");
  692.  
  693. rewind(PtrPes);
  694.  
  695. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  696.  
  697. while(!feof(PtrPes))
  698. {
  699. if(strcmp(Pes.login, LoginAux) != 0)
  700. fwrite(&Pes, sizeof(TpPessoa), 1, PtrTemp);
  701.  
  702. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  703. }
  704.  
  705. fclose(PtrPes);
  706. fclose(PtrTemp);
  707.  
  708. remove("Pessoa.dat");
  709. rename("Temp.dat", "Pessoa.dat");
  710.  
  711. textcolor(3);
  712. gotoxy(25, 15);
  713. printf("Pessoa excluida!");
  714. }
  715. else
  716. fclose(PtrPes);
  717. }
  718.  
  719. getch();
  720.  
  721. system("cls");
  722. Cabecalho("Exclusao Fisica de Pessoas");
  723.  
  724. gotoxy(2, 4);
  725. printf("Pessoa a ser excluida:");
  726. fflush(stdin);
  727. gets(LoginAux);
  728. }
  729. }
  730.  
  731. getch();
  732. }
  733.  
  734. void ExclusaoLogicaPessoa(FILE *PtrPes)
  735. {
  736. TpPessoa Pes;
  737. int Pos;
  738. char LoginAux[10];
  739.  
  740. system("cls");
  741. Cabecalho("Exclusao Logica de Pessoas");
  742.  
  743. PtrPes = fopen("Pessoa.dat", "rb+");
  744.  
  745. if(PtrPes == NULL)
  746. {
  747.  
  748. }
  749. else
  750. {
  751. gotoxy(2, 4);
  752. printf("Login:");
  753. fflush(stdin);
  754. gets(LoginAux);
  755.  
  756. while(strcmp(LoginAux, "\0") != 0)
  757. {
  758. Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
  759.  
  760. if(Pos == -1)
  761. {
  762. gotoxy(30, 6);
  763. textcolor(4);
  764. printf("Login nao cadastrado");
  765. textcolor(15);
  766. fclose(PtrPes);
  767. }
  768. else
  769. {
  770. gotoxy(2, 5);
  771. printf("Dados encontrados:");
  772. fseek(PtrPes, Pos, 0);
  773. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  774. ImprimePessoa(Pes, 7);
  775.  
  776. gotoxy(2, 12);
  777. printf("Confirma exclusao?(S/N)");
  778.  
  779. if(toupper(getche()) == 'S')
  780. {
  781. Pes.status = 0;
  782. fseek(PtrPes, Pos, 0);
  783. fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  784.  
  785. textcolor(3);
  786. gotoxy(25, 15);
  787. printf("Pessoa excluida!");
  788. }
  789. }
  790.  
  791. getch();
  792.  
  793. system("cls");
  794. Cabecalho("Exclusao Logica de Pessoas");
  795.  
  796. gotoxy(2, 4);
  797. printf("Login:");
  798. fflush(stdin);
  799. gets(LoginAux);
  800. }
  801.  
  802. }
  803. fclose(PtrPes);
  804.  
  805. getch();
  806. }
  807.  
  808. void ConsultaPalavras(FILE *PtrArq)
  809. {
  810. TpPalavra Pal;
  811. int Pos, linha;
  812.  
  813. system("cls");
  814. Cabecalho("Consulta de Palavras");
  815.  
  816. PtrArq = fopen("Palavra.dat", "rb");
  817.  
  818. if(PtrArq == NULL)
  819. {
  820. gotoxy(30, 6);
  821. textcolor(4);
  822. printf("Arquivo de palavras inexistente");
  823. textcolor(15);
  824. }
  825. else
  826. {
  827. gotoxy(2, 4);
  828. printf("Palavra em portugues:");
  829. fflush(stdin);
  830. gets(Pal.port);
  831.  
  832. while(strcmp(Pal.port, "\0") != 0)
  833. {
  834. Pos = BuscaPalavraPort(PtrArq, Pal.port);
  835.  
  836. if(Pos == -1)
  837. {
  838. gotoxy(30, 6);
  839. textcolor(4);
  840. printf("Palavra inexistente");
  841. textcolor(15);
  842. }
  843. else
  844. {
  845. gotoxy(30, 5);
  846. printf("Dados encontrados:");
  847. fseek(PtrArq, Pos, 0);
  848. fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  849.  
  850. ImprimePalavra(Pal, 7);
  851. }
  852.  
  853. getch();
  854.  
  855. system("cls");
  856. Cabecalho("Consulta de Palavras");
  857.  
  858. gotoxy(2, 4);
  859. printf("Palavra em portugues:");
  860. fflush(stdin);
  861. gets(Pal.port);
  862. }
  863. }
  864.  
  865. fclose(PtrArq);
  866.  
  867. getch();
  868. }
  869.  
  870. char MenuAlteraPessoa(void)
  871. {
  872. gotoxy(3, 6);
  873. printf("[A] - Alterar nome");
  874. gotoxy(3, 7);
  875. printf("[B] - Alterar senha");
  876. gotoxy(3, 8);
  877. printf("[ESC] - Sair ");
  878.  
  879. return toupper(getche());
  880. }
  881.  
  882. char MenuAlteraPalavra(void)
  883. {
  884. gotoxy(3, 6);
  885. printf("[A] - Alterar palavra em ingles");
  886. gotoxy(3, 7);
  887. printf("[B] - Alterar pontuacao");
  888. gotoxy(3, 8);
  889. printf("[C] - Alterar significado ");
  890. gotoxy(3, 9);
  891. printf("[ESC] - Sair ");
  892.  
  893. return toupper(getche());
  894. }
  895.  
  896. void CadastraPalavra(FILE *PtrPal)
  897. {
  898. TpPalavra Pal;
  899.  
  900. system("cls");
  901. Cabecalho("Cadastro de Palavras");
  902.  
  903. gotoxy(2, 4);
  904. printf("Palavra em portugues: ");
  905. fflush(stdin);
  906. gets(Pal.port);
  907.  
  908. while(strcmp(Pal.port, "\0") != 0)
  909. {
  910. PtrPal = fopen("Palavra.dat", "rb+");
  911.  
  912. if(PtrPal == NULL)
  913. {
  914. gotoxy(30, 6);
  915. textcolor(4);
  916. printf("Arquivo de palavras inexistente!");
  917. textcolor(15);
  918. fclose(PtrPal);
  919. }
  920. else
  921. {
  922. if(BuscaPalavraPort(PtrPal, Pal.port) >= 0)
  923. {
  924. gotoxy(30, 6);
  925. textcolor(4);
  926. printf("Palavra ja cadastrada");
  927. textcolor(15);
  928. fclose(PtrPal);
  929. }
  930. else
  931. {
  932. gotoxy(2, 5);
  933. printf("Palavra em ingles: ");
  934. fflush(stdin);
  935. gets(Pal.ing);
  936.  
  937. while(strcmp(Pal.ing, "\0") == 0)
  938. {
  939. textcolor(4);
  940. gotoxy(2, 6);
  941. printf("Digite uma palavra valida:");
  942. fflush(stdin);
  943. textcolor(15);
  944. gets(Pal.ing);
  945. }
  946.  
  947. gotoxy(2, 7);
  948. printf("Significado da palavra: ");
  949. fflush(stdin);
  950. gets(Pal.significado);
  951.  
  952. while(strcmp(Pal.significado, "\0") == 0)
  953. {
  954. textcolor(4);
  955. gotoxy(2, 8);
  956. printf("Digite um significado valido:");
  957. fflush(stdin);
  958. textcolor(15);
  959. gets(Pal.significado);
  960. }
  961.  
  962. gotoxy(2, 9);
  963. printf("Pontuacao: ");
  964. scanf("%d", &Pal.pont);
  965.  
  966. while(Pal.pont <= 0)
  967. {
  968. textcolor(4);
  969. gotoxy(2, 10);
  970. printf("Digite uma pontuacao valida:");
  971. textcolor(15);
  972. scanf("%d", &Pal.pont);
  973. }
  974.  
  975. Pal.status = 1;
  976. fseek(PtrPal, 0, 2);
  977. fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  978. fclose(PtrPal);
  979. InsercaoDiretaPalavra(PtrPal);
  980.  
  981. textcolor(3);
  982. gotoxy(25, 15);
  983. printf("Palavra cadastrada!");
  984. }
  985. }
  986.  
  987. getch();
  988.  
  989. system("cls");
  990. Cabecalho("Cadastro de Palavras");
  991. gotoxy(2, 4);
  992. printf("Palavra em portugues: ");
  993. fflush(stdin);
  994. gets(Pal.port);
  995. }
  996.  
  997. getch();
  998. }
  999.  
  1000. void AlteracaoPalavra(FILE *PtrPal)
  1001. {
  1002. TpPalavra Pal;
  1003. char Op;
  1004. int Pos;
  1005.  
  1006. system("cls");
  1007.  
  1008. Cabecalho("Alteracao de Palavras");
  1009.  
  1010. PtrPal = fopen("Palavra.dat", "rb+");
  1011.  
  1012. if(PtrPal == NULL)
  1013. {
  1014. gotoxy(30, 6);
  1015. textcolor(4);
  1016. printf("Arquivo de palavras inexistente!");
  1017. textcolor(15);
  1018. fclose(PtrPal);
  1019. }
  1020. else
  1021. {
  1022. gotoxy(2, 4);
  1023. printf("Palavra em portugues: ");
  1024. fflush(stdin);
  1025. gets(Pal.port);
  1026.  
  1027. while(strcmp(Pal.port, "\0") != 0)
  1028. {
  1029. Pos = BuscaBinariaPalavra(PtrPal, Pal.port);
  1030.  
  1031. if(Pos == -1)
  1032. {
  1033. gotoxy(30, 6);
  1034. textcolor(4);
  1035. printf("Palavra inexistente");
  1036. textcolor(15);
  1037. }
  1038. else
  1039. {
  1040. fseek(PtrPal, Pos, 0);
  1041.  
  1042. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1043.  
  1044. Op = MenuAlteraPalavra();
  1045.  
  1046. while(Op != 27)
  1047. {
  1048. switch(Op)
  1049. {
  1050. case 'A':
  1051. gotoxy(2, 10);
  1052. printf("Palavra em ingles atual: %s", Pal.ing);
  1053.  
  1054. gotoxy(2, 11);
  1055. printf("Nova palavra em ingles: ");
  1056. fflush(stdin);
  1057. gets(Pal.ing);
  1058.  
  1059. while(strcmp(Pal.ing, "\0") == 0)
  1060. {
  1061. textcolor(4);
  1062. gotoxy(2, 12);
  1063. printf("Digite uma palavra valida:");
  1064. fflush(stdin);
  1065. textcolor(15);
  1066. gets(Pal.ing);
  1067. }
  1068.  
  1069. fseek(PtrPal, Pos, 0);
  1070. fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1071.  
  1072. textcolor(3);
  1073. gotoxy(25, 15);
  1074. printf("Palavra alterada!");
  1075. break;
  1076. case 'B':
  1077. gotoxy(2, 10);
  1078. printf("Pontuacao atual: %d", Pal.pont);
  1079.  
  1080. gotoxy(2, 11);
  1081. printf("Nova pontuacao: ");
  1082. scanf("%d", &Pal.pont);
  1083.  
  1084. while(Pal.pont <= 0)
  1085. {
  1086. textcolor(4);
  1087. gotoxy(2, 12);
  1088. printf("Digite uma pontuacao valida:");
  1089. textcolor(15);
  1090. scanf("%d", &Pal.pont);
  1091. }
  1092.  
  1093. textcolor(3);
  1094. gotoxy(25, 15);
  1095. printf("Pontuacao alterada!");
  1096. break;
  1097. case 'C':
  1098. gotoxy(2, 10);
  1099. printf("Significado atual: %s", Pal.significado);
  1100.  
  1101. gotoxy(2, 11);
  1102. printf("Novo significado: ");
  1103. fflush(stdin);
  1104. gets(Pal.significado);
  1105.  
  1106. while(strcmp(Pal.significado, "\0") == 0)
  1107. {
  1108. textcolor(4);
  1109. gotoxy(2, 12);
  1110. printf("Digite um significado valido:");
  1111. fflush(stdin);
  1112. textcolor(15);
  1113. gets(Pal.significado);
  1114. }
  1115.  
  1116. fseek(PtrPal, Pos, 0);
  1117. fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1118.  
  1119. textcolor(3);
  1120. gotoxy(25, 15);
  1121. printf("Significado alterado!");
  1122. break;
  1123. default:
  1124. gotoxy(2, 11);
  1125. textcolor(4);
  1126. printf("Opcao invalida!");
  1127. textcolor(15);
  1128. break;
  1129. }
  1130.  
  1131. getch();
  1132. system("cls");
  1133. Cabecalho("Alteracao de Palavras");
  1134.  
  1135. Op = MenuAlteraPalavra();
  1136. }
  1137. }
  1138.  
  1139. getch();
  1140.  
  1141. system("cls");
  1142. Cabecalho("Alteracao de Palavras");
  1143.  
  1144. gotoxy(2, 4);
  1145. printf("Palavra em portugues: ");
  1146. gotoxy(2, 5);
  1147. fflush(stdin);
  1148. gets(Pal.port);
  1149. }
  1150. }
  1151.  
  1152. fclose(PtrPal);
  1153.  
  1154. getch();
  1155. }
  1156.  
  1157. void ExclusaoFisicaPalavra(FILE *PtrPal)
  1158. {
  1159. TpPalavra Pal;
  1160. int Pos;
  1161. char PalavraAux[40];
  1162.  
  1163. system("cls");
  1164. Cabecalho("Exclusao Fisica de Palavras");
  1165.  
  1166. gotoxy(2, 4);
  1167. printf("Palavra a ser excluida:");
  1168. fflush(stdin);
  1169. gets(PalavraAux);
  1170.  
  1171. while(strcmp(PalavraAux, "\0") != 0)
  1172. {
  1173. PtrPal = fopen("Palavra.dat", "rb");
  1174.  
  1175. if(PtrPal == NULL)
  1176. {
  1177. gotoxy(30, 6);
  1178. textcolor(4);
  1179. printf("Arquivo de palavras inexistente");
  1180. textcolor(15);
  1181. fclose(PtrPal);
  1182. }
  1183. else
  1184. {
  1185. Pos = BuscaBinariaPalavra(PtrPal, PalavraAux);
  1186.  
  1187. if(Pos == -1)
  1188. {
  1189. gotoxy(30, 6);
  1190. textcolor(4);
  1191. printf("Palavra inexistente");
  1192. textcolor(15);
  1193. fclose(PtrPal);
  1194. }
  1195. else
  1196. {
  1197. fseek(PtrPal, Pos, 0);
  1198. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1199. gotoxy(2, 5);
  1200. printf("Dados encontrados:");
  1201. ImprimePalavra(Pal, 7);
  1202.  
  1203. gotoxy(2, 12);
  1204. printf("Confirma exclusao?(S/N)");
  1205.  
  1206. if(toupper(getche()) == 'S')
  1207. {
  1208. FILE *PtrTemp = fopen("Temp.dat", "ab+");
  1209.  
  1210. rewind(PtrPal);
  1211.  
  1212. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1213.  
  1214. while(!feof(PtrPal))
  1215. {
  1216. if(strcmp(Pal.port, PalavraAux) != 0)
  1217. fwrite(&Pal, sizeof(TpPalavra), 1, PtrTemp);
  1218.  
  1219. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1220. }
  1221.  
  1222. fclose(PtrPal);
  1223. fclose(PtrTemp);
  1224.  
  1225. remove("Palavra.dat");
  1226. rename("Temp.dat", "Palavra.dat");
  1227.  
  1228. textcolor(3);
  1229. gotoxy(25, 15);
  1230. printf("Palavra excluida!");
  1231. }
  1232. else
  1233. fclose(PtrPal);
  1234. }
  1235. }
  1236.  
  1237. getch();
  1238.  
  1239. system("cls");
  1240. Cabecalho("Exclusao Fisica de Palavras");
  1241. gotoxy(2, 4);
  1242. printf("Palavra a ser excluida:");
  1243. fflush(stdin);
  1244. gets(PalavraAux);
  1245. }
  1246.  
  1247. getch();
  1248. }
  1249.  
  1250. void ExclusaoLogicaPalavra(FILE *PtrPal)
  1251. {
  1252. TpPalavra Pal;
  1253. int Pos;
  1254.  
  1255. system("cls");
  1256. Cabecalho("Exclusao Logica de Palavras");
  1257.  
  1258. PtrPal = fopen("Palavra.dat", "rb+");
  1259.  
  1260. if(PtrPal == NULL)
  1261. {
  1262. gotoxy(30, 6);
  1263. textcolor(4);
  1264. printf("Arquivo de palavras inexistente!");
  1265. textcolor(15);
  1266. fclose(PtrPal);
  1267. }
  1268. else
  1269. {
  1270. gotoxy(2, 4);
  1271. printf("Palavra a ser excluida:");
  1272. fflush(stdin);
  1273. gets(Pal.port);
  1274.  
  1275. while(strcmp(Pal.port, "\0") != 0)
  1276. {
  1277. Pos = BuscaBinariaPalavra(PtrPal, Pal.port);
  1278.  
  1279. if(Pos == -1)
  1280. {
  1281. gotoxy(30, 6);
  1282. textcolor(4);
  1283. printf("Palavra inexistente");
  1284. textcolor(15);
  1285. fclose(PtrPal);
  1286. }
  1287. else
  1288. {
  1289. fseek(PtrPal, Pos, 0);
  1290. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1291. gotoxy(2, 5);
  1292. printf("Dados encontrados:");
  1293. ImprimePalavra(Pal, 7);
  1294.  
  1295. gotoxy(2, 12);
  1296. printf("Confirma exclusao?(S/N)");
  1297.  
  1298. if(toupper(getche()) == 'S')
  1299. {
  1300. Pal.status = 0;
  1301.  
  1302. fseek(PtrPal, Pos, 0);
  1303. fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1304.  
  1305. textcolor(3);
  1306. gotoxy(25, 15);
  1307. printf("Palavra excluida!");
  1308. }
  1309. }
  1310.  
  1311. getch();
  1312.  
  1313. system("cls");
  1314. Cabecalho("Exclusao Logica de Palavras");
  1315.  
  1316. gotoxy(2, 4);
  1317. printf("Palavra a ser excluida:");
  1318. fflush(stdin);
  1319. gets(Pal.port);
  1320. }
  1321. }
  1322.  
  1323. fclose(PtrPal);
  1324.  
  1325. getch();
  1326. }
  1327.  
  1328. void CadastraPessoa(FILE *PtrPes)
  1329. {
  1330. TpPessoa Pes;
  1331.  
  1332. time_t t = time(NULL);
  1333. struct tm tm = *localtime(&t);
  1334.  
  1335. system("cls");
  1336. Cabecalho("Cadastro de Pessoas");
  1337.  
  1338. gotoxy(2, 4);
  1339. printf("Login a ser cadastrado: ");
  1340. fflush(stdin);
  1341. gets(Pes.login);
  1342.  
  1343. while(strcmp(Pes.login, "\0") != 0)
  1344. {
  1345. PtrPes = fopen("Pessoa.dat", "rb+");
  1346.  
  1347. if(BuscaExaustivaPessoa(PtrPes, Pes.login) >= 0)
  1348. {
  1349. gotoxy(30, 6);
  1350. textcolor(4);
  1351. printf("Login ja cadastrado");
  1352. textcolor(15);
  1353. fclose(PtrPes);
  1354. }
  1355. else
  1356. {
  1357. gotoxy(2, 5);
  1358. printf("Nome: ");
  1359. fflush(stdin);
  1360. gets(Pes.nome);
  1361.  
  1362. while(strcmp(Pes.nome, "\0") == 0)
  1363. {
  1364. textcolor(4);
  1365. gotoxy(2, 6);
  1366. printf("Digite um nome valido:");
  1367. fflush(stdin);
  1368. textcolor(15);
  1369. gets(Pes.nome);
  1370. }
  1371.  
  1372. gotoxy(2, 7);
  1373. printf("Senha: "); textcolor(0);
  1374. scanf("%d", &Pes.senha);
  1375.  
  1376. while(Pes.senha <= 0)
  1377. {
  1378. textcolor(4);
  1379. gotoxy(2, 8);
  1380. printf("Digite uma senha valida:");
  1381. textcolor(0);
  1382. scanf("%d", &Pes.senha);
  1383. }
  1384.  
  1385. textcolor(15);
  1386.  
  1387. Pes.Data.dia = tm.tm_mday;
  1388. Pes.Data.mes = tm.tm_mon + 1;
  1389. Pes.Data.ano = tm.tm_year + 1900;
  1390.  
  1391. Pes.pont = 0;
  1392. Pes.status = 1;
  1393. fseek(PtrPes, 0, 2);
  1394. fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1395. fclose(PtrPes);
  1396. InsercaoDiretaPessoa(PtrPes);
  1397.  
  1398. textcolor(3);
  1399. gotoxy(25, 15);
  1400. printf("Pessoa cadastrada!");
  1401. }
  1402.  
  1403. getch();
  1404. system("cls");
  1405. Cabecalho("Cadastro de Pessoas");
  1406.  
  1407. gotoxy(2, 4);
  1408. printf("Login a ser cadastrado: ");
  1409. fflush(stdin);
  1410. gets(Pes.login);
  1411. }
  1412.  
  1413.  
  1414. getch();
  1415. }
  1416.  
  1417. void AlteracaoPessoa(FILE *PtrPes)
  1418. {
  1419. TpPessoa Pes;
  1420. int Pos;
  1421. char Op;
  1422.  
  1423. system("cls");
  1424. Cabecalho("Alteracao de Pessoas");
  1425.  
  1426. PtrPes = fopen("Pessoa.dat", "rb+");
  1427.  
  1428. if(PtrPes == NULL)
  1429. {
  1430. gotoxy(30, 6);
  1431. textcolor(4);
  1432. printf("Arquivo de pessoas inexistente!");
  1433. textcolor(15);
  1434. fclose(PtrPes);
  1435. }
  1436. else
  1437. {
  1438. gotoxy(2, 4);
  1439. printf("Login da pessoa a ser alterada: ");
  1440. fflush(stdin);
  1441. gets(Pes.login);
  1442.  
  1443. while(strcmp(Pes.login, "\0") != 0)
  1444. {
  1445. Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
  1446.  
  1447. if(Pos == -1)
  1448. {
  1449. gotoxy(30, 6);
  1450. textcolor(4);
  1451. printf("Login inexistente!");
  1452. textcolor(15);
  1453. }
  1454. else
  1455. {
  1456. fseek(PtrPes, Pos, 0);
  1457.  
  1458. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1459.  
  1460. Op = MenuAlteraPessoa();
  1461.  
  1462. while(Op != 27)
  1463. {
  1464. switch(Op)
  1465. {
  1466. case 'A':
  1467. gotoxy(2, 10);
  1468. printf("Nome atual: %s\n", Pes.nome);
  1469. gotoxy(2, 11);
  1470. printf("Novo nome: ");
  1471. fflush(stdin);
  1472. gets(Pes.nome);
  1473.  
  1474. while(strcmp(Pes.nome, "\0") == 0)
  1475. {
  1476. textcolor(4);
  1477. gotoxy(2, 12);
  1478. printf("Digite um nome valido:");
  1479. fflush(stdin);
  1480. textcolor(15);
  1481. gets(Pes.nome);
  1482. }
  1483.  
  1484. fseek(PtrPes, Pos, 0);
  1485. fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1486.  
  1487. textcolor(3);
  1488. gotoxy(25, 15);
  1489. printf("Nome alterado!");
  1490. break;
  1491. case 'B':
  1492. gotoxy(2, 10);
  1493. printf("Senha atual: %d\n", Pes.senha);
  1494. gotoxy(2, 11);
  1495. printf("Nova senha: "); textcolor(0);
  1496. scanf("%d", &Pes.senha);
  1497.  
  1498. while(Pes.senha <= 0)
  1499. {
  1500. textcolor(4);
  1501. gotoxy(2, 12);
  1502. printf("Digite uma senha valida:");
  1503. textcolor(0);
  1504. scanf("%d", &Pes.senha);
  1505. }
  1506.  
  1507. fseek(PtrPes, Pos, 0);
  1508. fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1509.  
  1510. textcolor(3);
  1511. gotoxy(25, 15);
  1512. printf("Senha alterada!");
  1513. break;
  1514. default:
  1515. gotoxy(2, 11);
  1516. textcolor(4);
  1517. printf("Opcao invalida!");
  1518. textcolor(15);
  1519. break;
  1520. }
  1521.  
  1522. getch();
  1523. system("cls");
  1524. Cabecalho("Alteracao de Pessoas");
  1525.  
  1526. Op = MenuAlteraPessoa();
  1527. }
  1528. }
  1529.  
  1530. getch();
  1531.  
  1532. system("cls");
  1533. Cabecalho("Alteracao de Pessoas");
  1534.  
  1535. gotoxy(2, 4);
  1536. printf("Login da pessoa a ser alterada: ");
  1537. fflush(stdin);
  1538. gets(Pes.login);
  1539. }
  1540. }
  1541.  
  1542. fclose(PtrPes);
  1543.  
  1544. getch();
  1545. }
  1546.  
  1547. void ConsultaPessoa(FILE *PtrPes)
  1548. {
  1549. TpPessoa Pes;
  1550. int Pos;
  1551.  
  1552. system("cls");
  1553. Cabecalho("Consulta de pessoas");
  1554.  
  1555. PtrPes = fopen("Pessoa.dat", "rb");
  1556.  
  1557. if(PtrPes == NULL)
  1558. {
  1559. gotoxy(30, 6);
  1560. textcolor(4);
  1561. printf("Arquivo de pessoas inexistente");
  1562. textcolor(15);
  1563. }
  1564. else
  1565. {
  1566. gotoxy(2, 4);
  1567. printf("Login a ser procurado: ");
  1568. fflush(stdin);
  1569. gets(Pes.login);
  1570.  
  1571. while(strcmp(Pes.login, "\0") != 0)
  1572. {
  1573. Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
  1574.  
  1575. if(Pos == -1)
  1576. {
  1577. gotoxy(30, 6);
  1578. textcolor(4);
  1579. printf("Login inexistente");
  1580. textcolor(15);
  1581. }
  1582. else
  1583. {
  1584. gotoxy(30, 5);
  1585. printf("Dados encontrados:");
  1586. fseek(PtrPes, Pos, 0);
  1587. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1588. ImprimePessoa(Pes, 7);
  1589. }
  1590.  
  1591. getch();
  1592.  
  1593. system("cls");
  1594. Cabecalho("Consulta de pessoas");
  1595.  
  1596. gotoxy(2, 4);
  1597. printf("Login a ser procurado: ");
  1598. fflush(stdin);
  1599. gets(Pes.login);
  1600. }
  1601. }
  1602.  
  1603. fclose(PtrPes);
  1604. getch();
  1605. }
  1606.  
  1607. int BuscaPalavraIngles(FILE *PtrPal, char Ing[40])
  1608. {
  1609. TpPalavra Pal;
  1610.  
  1611. rewind(PtrPal);
  1612.  
  1613. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1614.  
  1615. while(!feof(PtrPal) && (stricmp(Pal.ing, Ing) != 0 || Pal.status == 0))
  1616. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1617.  
  1618. if(stricmp(Pal.ing, Ing) == 0)
  1619. return ftell(PtrPal) - sizeof(TpPalavra);
  1620. else
  1621. return -1;
  1622. }
  1623.  
  1624. int ELetra(char c)
  1625. {
  1626. if(toupper(c) >= 65 && toupper(c) <= 92)
  1627. return 1;
  1628. else
  1629. return 0;
  1630. }
  1631.  
  1632. void Tradutor(FILE *PtrPal)
  1633. {
  1634. TpPalavra Pal;
  1635. int Pos, i, Aux;
  1636. char Frase[1000], StrAux[1000], Traducao[1000];
  1637.  
  1638. system("cls");
  1639.  
  1640. Cabecalho("Tradutor");
  1641.  
  1642. PtrPal = fopen("Palavra.dat", "rb");
  1643.  
  1644. if(PtrPal == NULL)
  1645. {
  1646. gotoxy(30, 6);
  1647. textcolor(4);
  1648. printf("Arquivo de palavras inexistente");
  1649. textcolor(15);
  1650. }
  1651. else
  1652. {
  1653. gotoxy(2, 4);
  1654. printf("Texto em ingles:");
  1655. fflush(stdin);
  1656. gets(Frase);
  1657.  
  1658. while(strcmp(Frase, "\0") != 0)
  1659. {
  1660. strcpy(Traducao, "\0");
  1661.  
  1662. Aux = 0;
  1663.  
  1664. for(i = 0; i <= strlen(Frase); i++)
  1665. {
  1666. if(ELetra(Frase[i]) == 1)
  1667. StrAux[Aux++] = Frase[i];
  1668. else if(i > 0 && Frase[i] == ' ' || Frase[i] == '\0' && ELetra(Frase[i - 1]) == 1)
  1669. {
  1670. StrAux[Aux] = '\0';
  1671.  
  1672. Pos = BuscaPalavraIngles(PtrPal, StrAux);
  1673.  
  1674. if(Pos == -1)
  1675. {
  1676. strcat(Traducao, StrAux);
  1677. strcat(Traducao, " ");
  1678. }
  1679. else
  1680. {
  1681. fseek(PtrPal, Pos, 0);
  1682. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1683.  
  1684. strcat(Traducao, Pal.port);
  1685. strcat(Traducao, " ");
  1686. }
  1687.  
  1688. strcpy(StrAux, "\0");
  1689. Aux = 0;
  1690. }
  1691. }
  1692.  
  1693. gotoxy(2, 5);
  1694. printf("Traducao: %s", Traducao);
  1695.  
  1696. getch();
  1697.  
  1698. system("cls");
  1699. Cabecalho("Tradutor");
  1700.  
  1701. gotoxy(2, 4);
  1702. printf("Texto em ingles:");
  1703. fflush(stdin);
  1704. gets(Frase);
  1705. }
  1706. }
  1707.  
  1708. fclose(PtrPal);
  1709. }
  1710.  
  1711. void InsercaoAutomatica(FILE *PtrPes, FILE *PtrPal)
  1712. {
  1713. int NumRPes, NumRPal, i;
  1714. time_t t = time(NULL);
  1715. struct tm tm = *localtime(&t);
  1716.  
  1717. TpPessoa VetPessoa[5] = {{"Joao Victor", "jvsierra", 12345, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1718. {"Rafael", "rafa", 45678, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1719. {"Miranda", "mir23", 12458, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1720. {"Arthur", "art657", 41256, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1721. {"Sofia", "sf123", 13879, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}}};
  1722.  
  1723. TpPalavra VetPalavra[5] = {{"lapis", "pencil", "Instrumento usado para escrever", 10, 1},
  1724. {"celular", "cellphone", "Dispositivo telefonico movel", 15, 1},
  1725. {"bolsa", "bag", "Item usado para carregar coisas", 20, 1},
  1726. {"copo", "cup", "Item usado para colocar liquidos", 15, 1},
  1727. {"cama", "bed", "Lugar onde se dorme", 10, 1}};
  1728.  
  1729.  
  1730. system("cls");
  1731. Cabecalho("Insercao Automatica");
  1732.  
  1733. PtrPes = fopen("Pessoa.dat", "ab+");
  1734. PtrPal = fopen("Palavra.dat", "ab+");
  1735.  
  1736. fseek(PtrPes, 0, 2);
  1737. NumRPes = ftell(PtrPes) / sizeof(TpPessoa);
  1738. fseek(PtrPal, 0, 2);
  1739. NumRPal = ftell(PtrPal) / sizeof(TpPalavra);
  1740.  
  1741. if(NumRPes > 0 || NumRPal > 0)
  1742. {
  1743. gotoxy(30, 6);
  1744. textcolor(4);
  1745. printf("Os arquivos ja contem dados");
  1746. textcolor(15);
  1747. fclose(PtrPal);
  1748. }
  1749. else
  1750. {
  1751. fwrite(VetPessoa, sizeof(TpPessoa), 5, PtrPes);
  1752. fwrite(VetPalavra, sizeof(TpPalavra), 5, PtrPal);
  1753.  
  1754. gotoxy(30, 6);
  1755. textcolor(2);
  1756. printf("Dados inseridos");
  1757. textcolor(15);
  1758. }
  1759.  
  1760. fclose(PtrPes);
  1761. fclose(PtrPal);
  1762. SelecaoDiretaPessoa(PtrPes);
  1763. BubbleSortPalavra(PtrPal);
  1764.  
  1765. getch();
  1766. }
  1767.  
  1768. int TemLetraPalavra(char Palavra[40], char Letra)
  1769. {
  1770. int i = 0;
  1771.  
  1772. while(i < strlen(Palavra) && Palavra[i] != Letra)
  1773. i++;
  1774.  
  1775. if(i < strlen(Palavra))
  1776. return i;
  1777. else
  1778. return -1;
  1779. }
  1780.  
  1781. void OrdenaJogadoresPontuacao(FILE *PtrPes)
  1782. {
  1783. int a, NumR;
  1784. TpPessoa RegA, RegB;
  1785.  
  1786. PtrPes = fopen("Pessoa.dat", "rb+");
  1787.  
  1788. fseek(PtrPes, 0, 2);
  1789. NumR = ftell(PtrPes) / sizeof(TpPessoa);
  1790.  
  1791. while(NumR > 0)
  1792. {
  1793. for(a = 0; a < NumR - 1; a++)
  1794. {
  1795. fseek(PtrPes, a * sizeof(TpPessoa), 0);
  1796. fread(&RegA, sizeof(TpPessoa), 1, PtrPes);
  1797. fread(&RegB, sizeof(TpPessoa), 1, PtrPes);
  1798.  
  1799. if(RegA.pont < RegB.pont)
  1800. {
  1801. fseek(PtrPes, a * sizeof(TpPessoa), 0);
  1802. fwrite(&RegB, sizeof(TpPessoa), 1, PtrPes);
  1803. fwrite(&RegA, sizeof(TpPessoa), 1, PtrPes);
  1804. }
  1805. }
  1806.  
  1807. NumR--;
  1808. }
  1809.  
  1810. fclose(PtrPes);
  1811. }
  1812.  
  1813. void RankingJogadores(FILE *PtrPes)
  1814. {
  1815. int linha = 5;
  1816. TpPessoa Pes;
  1817.  
  1818. system("cls");
  1819.  
  1820. QuadroFlexivel(1, 1, 80, 3);
  1821. gotoxy(30, 2);
  1822. printf("Ranking dos Jogadores");
  1823.  
  1824. PtrPes = fopen("Pessoa.dat", "rb");
  1825.  
  1826. if(PtrPes == NULL)
  1827. {
  1828. gotoxy(30, 6);
  1829. textcolor(4);
  1830. printf("Arquivo de jogadores inexistente");
  1831. textcolor(15);
  1832. }
  1833. else
  1834. {
  1835. OrdenaJogadoresPontuacao(PtrPes);
  1836.  
  1837. rewind(PtrPes);
  1838. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1839.  
  1840. while(!feof(PtrPes))
  1841. {
  1842. if(Pes.status == 1)
  1843. {
  1844. ImprimePessoa(Pes, linha);
  1845. linha += 6;
  1846. }
  1847.  
  1848. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1849. }
  1850.  
  1851. gotoxy(1, 1);
  1852. }
  1853.  
  1854. fclose(PtrPes);
  1855.  
  1856. getch();
  1857. }
  1858.  
  1859. void ImprimeJogada(TpPalavForca Jog, int linha)
  1860. {
  1861. QuadroFlexivel(2, linha - 1, 79, linha + 4);
  1862. gotoxy(3, linha++);
  1863. textcolor(14);
  1864. printf("Login: ");
  1865. textcolor(15);
  1866. printf("%s", Jog.Login);
  1867. gotoxy(4, linha++);
  1868. textcolor(14);
  1869. printf("Palavra: ");
  1870. textcolor(15);
  1871. printf("%s", Jog.Palavra);
  1872. gotoxy(4, linha);
  1873. textcolor(14);
  1874.  
  1875. if(Jog.Acertou == 0)
  1876. printf("Jogador perdeu");
  1877. else
  1878. printf("Joador ganhou");
  1879.  
  1880. textcolor(15);
  1881. }
  1882.  
  1883. void ConsultaJogadas(FILE *PtrPalavForca)
  1884. {
  1885. TpPalavForca PalForca;
  1886. char loginAux[10];
  1887. int linha = 7, Pos;
  1888.  
  1889. system("cls");
  1890.  
  1891. QuadroFlexivel(1, 1, 80, 3);
  1892. gotoxy(30, 2);
  1893. printf("Consulta de Jogadas");
  1894.  
  1895. PtrPalavForca = fopen("PalavraForca.dat", "rb");
  1896.  
  1897. if(PtrPalavForca == NULL)
  1898. {
  1899. gotoxy(30, 6);
  1900. textcolor(4);
  1901. printf("Arquivo de jogadas inexistente");
  1902. textcolor(15);
  1903. }
  1904. else
  1905. {
  1906. gotoxy(2, 5);
  1907. printf("Digite o login: ");
  1908. fflush(stdin);
  1909. gets(loginAux);
  1910.  
  1911. while(strcmp(loginAux, "\0") != 0)
  1912. {
  1913. rewind(PtrPalavForca);
  1914.  
  1915. fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
  1916.  
  1917. while(!feof(PtrPalavForca))
  1918. {
  1919. if(strcmp(PalForca.Login, loginAux) == 0)
  1920. {
  1921. ImprimeJogada(PalForca, linha);
  1922. linha += 6;
  1923. }
  1924.  
  1925. fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
  1926. }
  1927.  
  1928. gotoxy(20, linha);
  1929. printf("Relatorio concluido");
  1930. gotoxy(1, 1);
  1931.  
  1932. getch();
  1933.  
  1934. system("cls");
  1935. QuadroFlexivel(1, 1, 80, 3);
  1936. gotoxy(30, 2);
  1937. printf("Consulta de Jogadas");
  1938. gotoxy(2, 5);
  1939. printf("Digite o login: ");
  1940. fflush(stdin);
  1941. gets(loginAux);
  1942. }
  1943. }
  1944.  
  1945. fclose(PtrPalavForca);
  1946. getch();
  1947. }
  1948.  
  1949. int UsuarioGanhou(char Letras[40], char Palavra[40])
  1950. {
  1951. int i, Cont = 0;
  1952.  
  1953. for(i = 0; i < strlen(Palavra); i++)
  1954. if(TemLetraPalavra(Letras, Palavra[i]) >= 0)
  1955. Cont++;
  1956.  
  1957. if(Cont == strlen(Palavra))
  1958. return 1;
  1959. else
  1960. return 0;
  1961. }
  1962.  
  1963. void Desenha(char Palavra[40], char LetrasCorretas[40], int NumErros)
  1964. {
  1965. int i, j;
  1966.  
  1967. textcolor(14);
  1968.  
  1969. gotoxy(45, 5);
  1970. printf("Chances restantes: ");
  1971. textcolor(15);
  1972. printf("%d", 6 - NumErros);
  1973.  
  1974. textcolor(14);
  1975. if(NumErros >= 1)
  1976. {
  1977. gotoxy(30, 10);
  1978. printf("%c", 2);
  1979. }
  1980. if(NumErros >= 2)
  1981. {
  1982. gotoxy(30, 11);
  1983. printf("%c", '|');
  1984. }
  1985. if(NumErros >= 3)
  1986. {
  1987. gotoxy(29,11);
  1988. printf("%c", '/');
  1989. }
  1990. if(NumErros >= 4)
  1991. {
  1992. gotoxy(31,11);
  1993. printf("%c", '\\');
  1994. }
  1995. if(NumErros >= 5)
  1996. {
  1997. gotoxy(29,12);
  1998. printf("%c", '/');
  1999. }
  2000. if(NumErros >= 6)
  2001. {
  2002. gotoxy(31,12);
  2003. printf("%c", '\\');
  2004. }
  2005.  
  2006. textcolor(15);
  2007. for(i = 0; i < strlen(Palavra); i++)
  2008. {
  2009. gotoxy((i+2) * 5, 15);
  2010. printf("___");
  2011. }
  2012.  
  2013. textcolor(14);
  2014. gotoxy(2, 6);
  2015. textcolor(14);
  2016. printf("Letras ja colocadas: ");
  2017. gotoxy(25, 6);
  2018.  
  2019. for(i = 0; i < strlen(LetrasCorretas); i++)
  2020. printf("%c ", LetrasCorretas[i]);
  2021.  
  2022. for(i = 0; LetrasCorretas[i] != '\0'; i++)
  2023. {
  2024. for(j = 0; j < strlen(Palavra); j++)
  2025. if(toupper(Palavra[j]) == toupper(LetrasCorretas[i]))
  2026. {
  2027. gotoxy((j + 2) * 5, 14);
  2028. printf("%c", LetrasCorretas[i]);
  2029. }
  2030. }
  2031.  
  2032. textcolor(15);
  2033.  
  2034. gotoxy(20, 10);
  2035. }
  2036.  
  2037. int BuscaJogada(FILE *PtrJogada, char login[10], char palavra[40])
  2038. {
  2039. int i = 0;
  2040. TpPalavForca Reg;
  2041.  
  2042. rewind(PtrJogada);
  2043.  
  2044. fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
  2045.  
  2046. while(!feof(PtrJogada) && (strcmp(Reg.Login, login) != 0 || strcmp(Reg.Palavra, palavra) != 0))
  2047. fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
  2048.  
  2049. if(!feof(PtrJogada))
  2050. return ftell(PtrJogada) - sizeof(TpPalavForca);
  2051. else
  2052. return -1;
  2053. }
  2054.  
  2055. void JogoForca(FILE *PtrPes, FILE *PtrPal)
  2056. {
  2057. FILE *PtrPalForca;
  2058. TpPalavForca PalForca;
  2059. TpPessoa Pes;
  2060. TpPalavra Pal;
  2061. int Pos, NumR, SenhaAux, UsuarioLogado = 0;
  2062. int PosPalavra, Lingua, NumTentativas, TLLetras, Ganhou, i;
  2063. char Letra, PalavraSorteada[40], VetLetras[40];
  2064.  
  2065. system("cls");
  2066. Cabecalho("Jogo da Forca");
  2067.  
  2068. PtrPes = fopen("Pessoa.dat", "rb+");
  2069.  
  2070. if(PtrPes == NULL)
  2071. {
  2072. gotoxy(30, 6);
  2073. textcolor(4);
  2074. printf("Arquivo de pessoas inexistente");
  2075. textcolor(15);
  2076. }
  2077. else
  2078. {
  2079. PtrPal = fopen("Palavra.dat", "rb");
  2080.  
  2081. if(PtrPal == NULL)
  2082. {
  2083. gotoxy(30, 6);
  2084. textcolor(4);
  2085. printf("Arquivo de palavras inexistente");
  2086. textcolor(15);
  2087. }
  2088. else
  2089. {
  2090. fseek(PtrPal, 0, 2);
  2091. NumR = ftell(PtrPal) / sizeof(TpPalavra);
  2092.  
  2093. if(NumR == 0)
  2094. {
  2095. gotoxy(30, 6);
  2096. textcolor(4);
  2097. printf("Nenhuma palavra cadastrada");
  2098. textcolor(15);
  2099. }
  2100. else
  2101. {
  2102. do
  2103. {
  2104. system("cls");
  2105. Cabecalho("Jogo da Forca");
  2106.  
  2107. gotoxy(2, 4);
  2108. printf("Login: ");
  2109. fflush(stdin);
  2110. gets(Pes.login);
  2111. gotoxy(2, 5);
  2112. printf("Senha: ");
  2113. textcolor(0);
  2114. scanf("%d", &SenhaAux);
  2115. textcolor(15);
  2116.  
  2117. Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
  2118.  
  2119. if(Pos == -1)
  2120. {
  2121. gotoxy(30, 6);
  2122. textcolor(4);
  2123. printf("Login inexistente");
  2124. textcolor(15);
  2125. }
  2126. else
  2127. {
  2128. fseek(PtrPes, Pos, 0);
  2129. fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  2130.  
  2131. if(Pes.senha != SenhaAux)
  2132. {
  2133. gotoxy(30, 6);
  2134. textcolor(4);
  2135. printf("Senha errada");
  2136. textcolor(15);
  2137. }
  2138. else
  2139. UsuarioLogado = 1;
  2140. }
  2141.  
  2142. getch();
  2143. }while(strcmp(Pes.login, "\0") != 0 && UsuarioLogado == 0);
  2144. }
  2145.  
  2146.  
  2147. if(UsuarioLogado == 1)
  2148. {
  2149. PtrPalForca = fopen("PalavraForca.dat", "ab+");
  2150.  
  2151. do
  2152. {
  2153. system("cls");
  2154. Cabecalho("Jogo da forca");
  2155.  
  2156. do
  2157. {
  2158. Lingua = rand() % 2;
  2159. PosPalavra = rand() % NumR;
  2160. fseek(PtrPal, PosPalavra * sizeof(TpPalavra), 0);
  2161. fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  2162.  
  2163. if(Lingua == 0)
  2164. strcpy(PalavraSorteada, Pal.port);
  2165. else
  2166. strcpy(PalavraSorteada, Pal.ing);
  2167.  
  2168. gotoxy(30, 18);
  2169. printf("%d", NumR);
  2170. }while(BuscaJogada(PtrPalForca, Pes.login, PalavraSorteada) != -1);
  2171.  
  2172. NumTentativas = 6;
  2173. strcpy(VetLetras, "\0");
  2174. TLLetras = 0;
  2175.  
  2176. while(NumTentativas > 0 && UsuarioGanhou(VetLetras, PalavraSorteada) == 0)
  2177. {
  2178. system("cls");
  2179. Cabecalho("Jogo da forca");
  2180.  
  2181. gotoxy(2, 4);
  2182. textcolor(14);
  2183. printf("Dica: ");
  2184. textcolor(15);
  2185. printf("%s", Pal.significado);
  2186. gotoxy(2, 5);
  2187. textcolor(14);
  2188. printf("Lingua: ");
  2189. textcolor(15);
  2190. if(Lingua == 0)
  2191. printf("Portugues");
  2192. else
  2193. printf("Ingles");
  2194.  
  2195. Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
  2196.  
  2197. gotoxy(2, 7);
  2198. printf("Digite uma letra: ");
  2199. fflush(stdin);
  2200. Letra = getche();
  2201.  
  2202. if(TemLetraPalavra(VetLetras, Letra) >= 0)
  2203. {
  2204. gotoxy(30, 8);
  2205. textcolor(14);
  2206. printf("Voce ja usou essa letra!");
  2207. }
  2208. else
  2209. {
  2210. gotoxy(30, 8);
  2211. if(TemLetraPalavra(PalavraSorteada, Letra) >= 0)
  2212. {
  2213. textcolor(2);
  2214. printf("Acertou a letra");
  2215. textcolor(15);
  2216. }
  2217. else
  2218. {
  2219. textcolor(4);
  2220. printf("Errou a letra");
  2221. textcolor(15);
  2222. NumTentativas--;
  2223. }
  2224.  
  2225. VetLetras[TLLetras++] = Letra;
  2226. VetLetras[TLLetras] = '\0';
  2227. }
  2228.  
  2229. getch();
  2230. }
  2231.  
  2232. Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
  2233.  
  2234. if(NumTentativas == 0)
  2235. {
  2236. textcolor(4);
  2237. gotoxy(2, 17);
  2238. printf("Voce perdeu! A palavra era: %s", PalavraSorteada);
  2239. Ganhou = 0;
  2240. }
  2241. else
  2242. {
  2243. Pes.pont += Pal.pont;
  2244. fseek(PtrPes, Pos, 0);
  2245. fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  2246. Ganhou = 1;
  2247.  
  2248. textcolor(2);
  2249. gotoxy(2, 17);
  2250. printf("Voce ganhou!");
  2251. }
  2252.  
  2253. PalForca.Acertou = Ganhou;
  2254. strcpy(PalForca.Login, Pes.login);
  2255. strcpy(PalForca.Palavra, PalavraSorteada);
  2256. fwrite(&PalForca, sizeof(TpPalavForca), 1, PtrPalForca);
  2257.  
  2258. gotoxy(2, 18);
  2259. textcolor(14);
  2260. printf("Deseja jogar novamente? (S/N):");
  2261. textcolor(15);
  2262. }while(toupper(getche()) == 'S');
  2263.  
  2264. fclose(PtrPalForca);
  2265. }
  2266. }
  2267.  
  2268. fclose(PtrPal);
  2269. }
  2270.  
  2271. fclose(PtrPes);
  2272.  
  2273. getch();
  2274. }
  2275.  
  2276. char Menu(void)
  2277. {
  2278. int i;
  2279.  
  2280. system("cls");
  2281. Quadro();
  2282.  
  2283. textcolor(14);
  2284.  
  2285. gotoxy(27, 2);
  2286. printf("ATP 2 - JOGO DA FORCA\n");
  2287.  
  2288. for(i = 2; i <= 79; i++)
  2289. {
  2290. gotoxy(i, 3);
  2291. printf("%c", 205);
  2292. }
  2293.  
  2294. textbackground(4);
  2295.  
  2296. gotoxy(4, 4);
  2297. printf(" MENU DE PALAVRAS ");
  2298.  
  2299. gotoxy(4, 5);
  2300. printf("[A] - Cadastrar palavras ");
  2301. gotoxy(4, 6);
  2302. printf("[B] - Relatorio de palavras ");
  2303. gotoxy(4, 7);
  2304. printf("[C] - Alteracao de palavras ");
  2305. gotoxy(4, 8);
  2306. printf("[D] - Consulta de palavras ");
  2307. gotoxy(4, 9);
  2308. printf("[E] - Exclusao Fisica de Palavras");
  2309. gotoxy(4, 10);
  2310. printf("[F] - Exclusao Logica de Palavras");
  2311. gotoxy(4, 11);
  2312. printf("[G] - Ordenar Palavras ");
  2313.  
  2314. gotoxy(40, 4);
  2315. printf(" MENU DE PESSOAS ");
  2316. gotoxy(40, 5);
  2317. printf("[H] - Cadastrar pessoas ");
  2318. gotoxy(40, 6);
  2319. printf("[I] - Relatorio de pessoas ");
  2320. gotoxy(40, 7);
  2321. printf("[J] - Alteracao de pessoas ");
  2322. gotoxy(40, 8);
  2323. printf("[K] - Consulta de pessoas ");
  2324. gotoxy(40, 9);
  2325. printf("[L] - Exclusao Fisica de Pessoas ");
  2326. gotoxy(40, 10);
  2327. printf("[M] - Exclusao Logica de Pessoas ");
  2328. gotoxy(40, 11);
  2329. printf("[N] - Ordenar Pessoas Por Nome ");
  2330.  
  2331. gotoxy(25, 13);
  2332. printf(" MENU GERAL ");
  2333.  
  2334. gotoxy(4, 15);
  2335. printf("[O] - JOGAR FORCA ");
  2336. gotoxy(40, 15);
  2337. printf("[P] - Tradutor de frases ");
  2338. gotoxy(4, 16);
  2339. printf("[Q] - Insercao Automatica ");
  2340. gotoxy(40, 16);
  2341. printf("[R] - Ranking dos Jogadores ");
  2342.  
  2343. gotoxy(4, 19);
  2344. printf("[ESC] - Sair ");
  2345.  
  2346. gotoxy(40, 19);
  2347. printf("[S] - Consulta de jogadas ");
  2348.  
  2349. textbackground(0);
  2350. textcolor(7);
  2351.  
  2352. return toupper(getche());
  2353. }
  2354.  
  2355. void TestaBusca(FILE *PtrPes)
  2356. {
  2357. system("cls");
  2358. PtrPes = fopen("Pessoa.dat", "rb+");
  2359. char login[10];
  2360. fflush(stdin);
  2361. gets(login);
  2362.  
  2363. printf("\n%d", BuscaSentinelaPessoa(PtrPes, login));
  2364. fclose(PtrPes);
  2365. getch();
  2366. }
  2367.  
  2368. void Executa(void)
  2369. {
  2370. char Op;
  2371. FILE *PtrArq, *PtrPes, *PtrPalavForca;
  2372.  
  2373. //TestaBusca(PtrPes);
  2374.  
  2375. Op = Menu();
  2376.  
  2377. while(Op != 27)
  2378. {
  2379. switch(Op)
  2380. {
  2381. case 'A':
  2382. CadastraPalavra(PtrArq);
  2383. break;
  2384. case 'B':
  2385. RelatorioPalavras(PtrArq);
  2386. break;
  2387. case 'C':
  2388. AlteracaoPalavra(PtrArq);
  2389. break;
  2390. case 'D':
  2391. ConsultaPalavras(PtrArq);
  2392. break;
  2393. case 'E':
  2394. ExclusaoFisicaPalavra(PtrArq);
  2395. break;
  2396. case 'F':
  2397. ExclusaoLogicaPalavra(PtrArq);
  2398. break;
  2399. case 'G':
  2400. BubbleSortPalavra(PtrArq);
  2401.  
  2402. system("cls");
  2403. gotoxy(40, 2);
  2404. printf("Palavras ordenadas");
  2405. getch();
  2406. break;
  2407. case 'H':
  2408. CadastraPessoa(PtrPes);
  2409. break;
  2410. case 'I':
  2411. RelatorioPessoa(PtrPes);
  2412. break;
  2413. case 'J':
  2414. AlteracaoPessoa(PtrPes);
  2415. break;
  2416. case 'K':
  2417. ConsultaPessoa(PtrPes);
  2418. break;
  2419. case 'L':
  2420. ExclusaoFisicaPessoa(PtrPes);
  2421. break;
  2422. case 'M':
  2423. ExclusaoLogicaPessoa(PtrPes);
  2424. break;
  2425. case 'N':
  2426. BubbleSortPessoa(PtrPes);
  2427.  
  2428. system("cls");
  2429. gotoxy(40, 2);
  2430. printf("Pessoas ordenadas");
  2431. getch();
  2432. break;
  2433. case 'O':
  2434. JogoForca(PtrPes, PtrArq);
  2435. break;
  2436. case 'P':
  2437. Tradutor(PtrArq);
  2438. break;
  2439. case 'Q':
  2440. InsercaoAutomatica(PtrPes, PtrArq);
  2441. break;
  2442. case 'R':
  2443. RankingJogadores(PtrPes);
  2444. break;
  2445. case 'S':
  2446. ConsultaJogadas(PtrPalavForca);
  2447. break;
  2448. default:
  2449. printf("Opcao invalida\n");
  2450. getch();
  2451. break;
  2452. }
  2453.  
  2454.  
  2455. Op = Menu();
  2456. }
  2457.  
  2458. getch();
  2459. }
  2460.  
  2461. int main(void)
  2462. {
  2463. srand(time(NULL));
  2464.  
  2465. Executa();
  2466.  
  2467. return 1;
  2468. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement