Advertisement
Jvsierra

Esboço trabalho

Oct 26th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 31.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio2.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <time.h>
  8.  
  9. #define X_I 1
  10. #define Y_I 1
  11. #define X_F 80
  12. #define Y_F 20
  13.  
  14. struct TpPalavra
  15. {
  16.     char port[30], ing[30], significado[100];
  17.     int pont, status;  
  18. };
  19.  
  20. struct TpData
  21. {
  22.     int dia, mes, ano;
  23. };
  24.  
  25. struct TpPessoa
  26. {
  27.     char nome[40], login[10];
  28.     int senha, pont, status;
  29.     TpData Data;
  30. };
  31.  
  32. struct TpPalavForca
  33. {
  34.     char Palavra[30], Login[10];
  35.     int Acertou;
  36. };
  37.  
  38. void Quadro()
  39. {
  40.     int i;
  41.     textcolor(14);
  42.     gotoxy(X_I,Y_I);
  43.     printf("%c",201);
  44.     gotoxy(X_F,Y_I);
  45.     printf("%c",187);
  46.     gotoxy(X_I,Y_F);
  47.     printf("%c",200);
  48.     gotoxy(X_F,Y_F);
  49.     printf("%c",188);
  50.     for(i = X_I + 1; i < X_F; i++)
  51.     {
  52.         gotoxy(i, Y_I);
  53.         printf("%c", 205);
  54.         gotoxy(i, Y_F);
  55.         printf("%c", 205);
  56.     }
  57.    
  58.     for(i = Y_I + 1; i < Y_F; i++)
  59.     {
  60.         gotoxy(X_I, i);
  61.         printf("%c", 186);
  62.        
  63.         gotoxy(X_F, i);
  64.         printf("%c", 186);
  65.     }
  66.  
  67.     textcolor(15);
  68. }
  69.  
  70. void QuadroFlexivel(int XI, int YI, int XF, int YF)
  71. {
  72.     int i;
  73.     textcolor(14);
  74.     gotoxy(XI, YI);
  75.     printf("%c",201);
  76.     gotoxy(XF, YI);
  77.     printf("%c",187);
  78.     gotoxy(XI, YF);
  79.     printf("%c",200);
  80.     gotoxy(XF, YF);
  81.     printf("%c",188);
  82.    
  83.     for(i = XI + 1; i < XF; i++)
  84.     {
  85.         gotoxy(i, YI);
  86.         printf("%c", 205);
  87.         gotoxy(i, YF);
  88.         printf("%c", 205);
  89.     }
  90.    
  91.     for(i = YI + 1; i < YF; i++)
  92.     {
  93.         gotoxy(XI, i);
  94.         printf("%c", 186);
  95.        
  96.         gotoxy(XF, i);
  97.         printf("%c", 186);
  98.     }
  99. }
  100.  
  101. void Cabecalho(char Titulo[100])
  102. {
  103.     Quadro();
  104.    
  105.     textcolor(15);
  106.    
  107.     gotoxy(30, 2);
  108.    
  109.     printf("%s\n", Titulo);
  110.    
  111.     textcolor(14);
  112.    
  113.     for(int i = 2; i <= 79; i++)
  114.     {
  115.         gotoxy(i, 3);
  116.         printf("%c", 205);
  117.     }
  118.    
  119.     textcolor(15);
  120. }
  121.  
  122. void ImprimePalavra(TpPalavra Pal, int linha)
  123. {
  124.     /*
  125.     QuadroFlexivel(XI, YI, XF, YF);
  126.     gotoxy(YI, XI + 4);
  127.     textcolor(14);
  128.     printf("Portugues: ");
  129.     textcolor(15);
  130.     printf("%s", Pal.port);
  131.     gotoxy(YI, XI + 5);
  132.     textcolor(14);
  133.     printf("Ingles: ");
  134.     textcolor(15);
  135.     printf("%s", Pal.ing);
  136.    
  137.     */
  138.    
  139. }
  140.  
  141. void ImprimePessoa(TpPessoa Pes, int linha)
  142. {
  143.     QuadroFlexivel(2, linha - 1, 79, linha + 4);
  144.     gotoxy(3, linha++);
  145.     textcolor(14);
  146.     printf("Nome: ");
  147.     textcolor(15);
  148.     printf("%s", Pes.nome);
  149.     gotoxy(3, linha);
  150.     textcolor(14);
  151.     printf("Login: ");
  152.     textcolor(15);
  153.     printf("%s", Pes.login);
  154.     gotoxy(30, linha);
  155.     textcolor(14);
  156.     printf("Pontuacao: ");
  157.     textcolor(15);
  158.     printf("%d", Pes.pont);
  159.     gotoxy(50, linha);
  160.     textcolor(14);
  161.     printf("Status: ");
  162.     textcolor(15);
  163.     printf("%d", Pes.status);
  164.     linha++;
  165.     gotoxy(3, linha);
  166.     textcolor(14);
  167.     printf("Data: ");
  168.     textcolor(15);
  169.     printf("%d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
  170.    
  171.     textcolor(15); 
  172. }
  173.  
  174. void RelatorioPalavras(FILE *PtrArq)
  175. {
  176.     TpPalavra Pal;
  177.    
  178.     system("cls");
  179.    
  180.     QuadroFlexivel(1, 1, 25, 5);
  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.        
  194.     }
  195.    
  196.     fclose(PtrArq);
  197.    
  198.     getch();
  199. }
  200.  
  201. int PosicaoMaiorPessoa(FILE *PtrPes, int NumR)
  202. {
  203.     TpPessoa Pes;
  204.     int Pos, i = 0;
  205.     char MaiorNome[40];
  206.    
  207.     rewind(PtrPes);
  208.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  209.    
  210.     strcpy(MaiorNome, Pes.login);
  211.     Pos = 0;
  212.    
  213.     for(i = 1; i < NumR; i++)
  214.     {
  215.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  216.        
  217.         if(stricmp(Pes.login, MaiorNome) > 0)
  218.         {
  219.             strcpy(MaiorNome, Pes.login);
  220.             Pos = i;
  221.         }
  222.     }
  223.    
  224.     fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  225.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  226.    
  227.     return Pos * sizeof(TpPessoa);
  228. }
  229.  
  230. void SelecaoDiretaPessoa(FILE *PtrPes)
  231. {
  232.     int PosMaior, NumR;
  233.     TpPessoa PesA, PesB;
  234.    
  235.     PtrPes = fopen("Pessoa.dat", "rb+");
  236.    
  237.     fseek(PtrPes, 0, 2);
  238.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  239.    
  240.     while(NumR > 0)
  241.     {
  242.         PosMaior = PosicaoMaiorPessoa(PtrPes, NumR);
  243.        
  244.         if(PosMaior < (NumR - 1) * sizeof(TpPessoa))
  245.         {
  246.            
  247.             fseek(PtrPes, PosMaior, 0);
  248.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  249.             fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  250.             fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  251.            
  252.             fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  253.             fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  254.            
  255.             fseek(PtrPes, PosMaior, 0);
  256.             fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  257.         }
  258.        
  259.         NumR--;
  260.     }
  261.    
  262.     fclose(PtrPes);
  263. }
  264.  
  265. void InsercaoDiretaPessoa(FILE *PtrPes)
  266. {
  267.     TpPessoa PesA, PesB;
  268.     int NumR, Pos;
  269.    
  270.     PtrPes = fopen("Pessoa.dat", "rb+");
  271.    
  272.     fseek(PtrPes, 0, 2);
  273.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  274.    
  275.     if(NumR > 1)
  276.     {
  277.         Pos = NumR - 1;
  278.        
  279.         fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  280.         fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  281.        
  282.         fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  283.         fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  284.        
  285.         while(Pos > 0 && stricmp(PesA.login, PesB.login) < 0)
  286.         {
  287.             fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  288.             fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  289.             fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  290.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  291.            
  292.             Pos--;
  293.            
  294.             fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  295.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  296.             fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  297.             fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  298.         }
  299.     }
  300.    
  301.     fclose(PtrPes);
  302. }
  303.  
  304. void RelatorioPessoa(FILE *PtrPes)
  305. {
  306.     int linha = 5;
  307.     TpPessoa Pes;
  308.    
  309.     clrscr();
  310.    
  311.     QuadroFlexivel(1, 1, 80, 3);
  312.     gotoxy(30, 2);
  313.     printf("Relatorio de pessoas");
  314.    
  315.     PtrPes = fopen("Pessoa.dat", "rb");
  316.    
  317.     if(PtrPes == NULL)
  318.     {
  319.         gotoxy(30, 6);
  320.         textcolor(4);
  321.         printf("Arquivo de pessoas inexistente");
  322.         textcolor(15);
  323.     }
  324.     else
  325.     {
  326.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  327.        
  328.         while(!feof(PtrPes))
  329.         {
  330.             if(Pes.status == 1)
  331.             {
  332.                 ImprimePessoa(Pes, linha);
  333.                 linha += 6;
  334.             }
  335.            
  336.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  337.         }
  338.        
  339.         //printf("\n\nRelatorio finalizado\n\n");
  340.     }
  341.    
  342.     fclose(PtrPes);
  343.    
  344.     getch();
  345. }
  346.  
  347. int BuscaPalavraPort(FILE *PtrPal, char Palavra[40])
  348. {
  349.     TpPalavra Pal;
  350.    
  351.     rewind(PtrPal);
  352.    
  353.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  354.    
  355.     while(!feof(PtrPal) && stricmp(Pal.port, Palavra) != 0)
  356.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  357.    
  358.     if(stricmp(Palavra, Pal.port) == 0)
  359.         return ftell(PtrPal) - sizeof(TpPalavra);
  360.     else
  361.         return -1;
  362. }
  363.  
  364. int BuscaExaustivaPessoa(FILE *PtrPes, char login[10])
  365. {
  366.     TpPessoa Pes;
  367.    
  368.     rewind(PtrPes);
  369.    
  370.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  371.    
  372.     while(!feof(PtrPes) && (stricmp(login, Pes.login) != 0 || Pes.status == 1))
  373.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  374.        
  375.     if(stricmp(login, Pes.login) == 0)
  376.         return ftell(PtrPes) - sizeof(TpPessoa);
  377.     else
  378.         return -1;
  379. }
  380.  
  381. int BubbleSortPessoa(FILE *PtrPes)
  382. {
  383.     TpPessoa PesA, PesB;
  384.     int i, j, QntdR;
  385.    
  386.     PtrPes = fopen("Pessoa.dat", "rb+");
  387.    
  388.     fseek(PtrPes, 0, 2);
  389.        
  390.     QntdR = ftell(PtrPes) / sizeof(TpPessoa);
  391.        
  392.     while(QntdR > 0)
  393.     {
  394.         for(i = 0; i < QntdR - 1; i++)
  395.         {
  396.             fseek(PtrPes, i * sizeof(TpPessoa), 0);
  397.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  398.             fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  399.                
  400.             if(strcmp(PesA.login, PesB.login) > 0)
  401.             {
  402.                 fseek(PtrPes, i * sizeof(TpPessoa), 0);
  403.                 fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  404.                 fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  405.             }
  406.         }
  407.            
  408.             QntdR--;
  409.     }
  410.    
  411.     fclose(PtrPes);
  412.    
  413.     getch();
  414. }
  415.  
  416.  
  417. int BuscaSeqIndPessoa(FILE *PtrPes, char loginChave[10])
  418. {
  419.     TpPessoa Pes;
  420.  
  421.     rewind(PtrPes);
  422.    
  423.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  424.    
  425.     while(!feof(PtrPes) && stricmp(loginChave, Pes.login) > 0)
  426.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  427.        
  428.     if(stricmp(loginChave, Pes.login) == 0)
  429.         return ftell(PtrPes) - sizeof(TpPessoa);
  430.     else
  431.         return -1;
  432. }
  433.  
  434. int BuscaSentinelaPessoa(FILE *PtrPes, char loginChave[10])
  435. {
  436.     FILE *PtrAux;
  437.     int i = 0, j, NumR;
  438.     TpPessoa Pes;
  439.    
  440.     strcpy(Pes.login, loginChave);
  441.    
  442.     fseek(PtrPes, 0, 2);
  443.    
  444.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  445.    
  446.     fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  447.    
  448.     rewind(PtrPes);
  449.    
  450.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  451.    
  452.     while(stricmp(Pes.login, loginChave) != 0)
  453.     {
  454.         i++;
  455.        
  456.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  457.     }
  458.    
  459.     rewind(PtrPes);
  460.    
  461.     PtrAux = fopen("Temp.dat", "ab+");
  462.    
  463.     for(j = 0; j < NumR; j++)
  464.     {
  465.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  466.        
  467.         fwrite(&Pes, sizeof(TpPessoa), 1, PtrAux);
  468.     }
  469.    
  470.     fclose(PtrPes);
  471.     fclose(PtrAux);
  472.    
  473.     remove("Pessoa.dat");
  474.    
  475.     rename("Temp.dat", "Pessoa.dat");
  476.    
  477.     if(i < NumR)
  478.         return i * sizeof(TpPessoa);
  479.     else
  480.         return -1;
  481. }
  482.  
  483. void ExclusaoFisicaPessoa(FILE *PtrPes)
  484. {
  485.     TpPessoa Pes;
  486.     char LoginAux[10];
  487.     int Pos;
  488.    
  489.     system("cls");
  490.     Cabecalho("Exclusao Fisica de Pessoas");
  491.    
  492.     gotoxy(2, 4);
  493.     printf("Pessoa a ser excluida:");
  494.     fflush(stdin);
  495.     gets(LoginAux);
  496.    
  497.     while(strcmp(LoginAux, "\0") != 0)
  498.     {
  499.         PtrPes = fopen("Pessoa.dat", "rb");
  500.        
  501.         if(PtrPes == NULL)
  502.         {
  503.             gotoxy(30, 6);
  504.             textcolor(4);
  505.             printf("Arquivo de pessoas inexistente");
  506.             textcolor(15);
  507.             fclose(PtrPes);
  508.         }
  509.         else
  510.         {
  511.             Pos = BuscaExaustivaPessoa(PtrPes, LoginAux);
  512.                
  513.             if(Pos == -1)
  514.             {
  515.                 gotoxy(30, 6);
  516.                 textcolor(4);
  517.                 printf("Login nao cadastrado");
  518.                 textcolor(15);
  519.                 fclose(PtrPes);
  520.             }
  521.             else
  522.             {
  523.                 gotoxy(2, 5);
  524.                 printf("Dados encontrados:");      
  525.                 fseek(PtrPes, Pos, 0);
  526.                 fread(&Pes, sizeof(TpPessoa), 1, PtrPes);  
  527.                 ImprimePessoa(Pes, 3);
  528.                            
  529.                 gotoxy(2, 12);
  530.                 printf("Confirma exclusao?(S/N)");
  531.                            
  532.                 if(toupper(getche()) == 'S')
  533.                 {
  534.                     FILE *PtrTemp = fopen("Temp.dat", "ab+");
  535.                            
  536.                     rewind(PtrPes);
  537.                                
  538.                     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  539.                            
  540.                     while(!feof(PtrPes))
  541.                     {
  542.                         if(strcmp(Pes.login, LoginAux) != 0)
  543.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrTemp);
  544.                                        
  545.                         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  546.                     }
  547.                                
  548.                     fclose(PtrPes);
  549.                     fclose(PtrTemp);
  550.                                
  551.                     remove("Pessoa.dat");
  552.                     rename("Temp.dat", "Pessoa.dat");
  553.                                
  554.                     textcolor(3);
  555.                     gotoxy(25, 15);
  556.                     printf("Pessoa excluida!");
  557.                 }
  558.                 else
  559.                     fclose(PtrPes);
  560.             }
  561.            
  562.             getch();
  563.            
  564.             system("cls");
  565.             Cabecalho("Exclusao Fisica de Pessoas");
  566.                
  567.             gotoxy(2, 4);
  568.             printf("Pessoa a ser excluida:");
  569.             fflush(stdin);
  570.             gets(LoginAux);
  571.         }
  572.     }  
  573.    
  574.     getch();
  575. }
  576.  
  577. void ExclusaoLogicaPessoa(FILE *PtrPes)
  578. {
  579.     TpPessoa Pes;
  580.     int Pos;
  581.     char LoginAux[10];
  582.    
  583.     system("cls");
  584.     Cabecalho("Exclusao Logica de Pessoas");
  585.    
  586.     PtrPes = fopen("Pessoa.dat", "rb+");
  587.  
  588.     gotoxy(2, 4);
  589.     printf("Login:");
  590.     fflush(stdin);
  591.     gets(LoginAux);
  592.        
  593.     while(strcmp(LoginAux, "\0") != 0)
  594.     {
  595.         Pos = BuscaExaustivaPessoa(PtrPes, LoginAux);
  596.            
  597.         if(Pos == -1)
  598.         {
  599.             gotoxy(30, 6);
  600.             textcolor(4);
  601.             printf("Login nao cadastrado");
  602.             textcolor(15);
  603.             fclose(PtrPes);
  604.         }
  605.         else
  606.         {
  607.             gotoxy(2, 5);
  608.             printf("Dados encontrados:");      
  609.             fseek(PtrPes, Pos, 0);
  610.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);  
  611.             ImprimePessoa(Pes, 3);
  612.                            
  613.             gotoxy(2, 12);
  614.             printf("Confirma exclusao?(S/N)");
  615.            
  616.             if(toupper(getche()) == 'S')
  617.             {
  618.                 Pes.status = 0;
  619.                 fseek(PtrPes, Pos, 0);
  620.                 fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  621.                
  622.                 textcolor(3);
  623.                 gotoxy(25, 15);
  624.                 printf("Pessoa excluida!");
  625.             }
  626.         }
  627.        
  628.         getch();
  629.        
  630.         system("cls");
  631.         Cabecalho("Exclusao Logica de Pessoas");
  632.            
  633.         gotoxy(2, 4);
  634.         printf("Login:");
  635.         fflush(stdin);
  636.         gets(LoginAux);
  637.     }
  638.    
  639.     fclose(PtrPes);
  640.    
  641.     getch();
  642. }
  643.  
  644. void ConsultaPalavras(FILE *PtrArq)
  645. {
  646.     TpPalavra Pal;
  647.     int Pos;
  648.    
  649.     system("cls");
  650.     Cabecalho("Consulta de Palavras");
  651.    
  652.     PtrArq = fopen("Palavra.dat", "rb");
  653.    
  654.     if(PtrArq == NULL)
  655.     {
  656.         gotoxy(30, 6);
  657.         textcolor(4);
  658.         printf("Arquivo de palavras inexistente");
  659.         textcolor(15);
  660.     }
  661.     else
  662.     {
  663.         gotoxy(2, 4);
  664.         printf("Palavra em portugues:");
  665.         fflush(stdin);
  666.         gets(Pal.port);
  667.        
  668.         while(strcmp(Pal.port, "\0") != 0)
  669.         {
  670.             Pos = BuscaPalavraPort(PtrArq, Pal.port);
  671.            
  672.             if(Pos == -1)
  673.             {
  674.                 gotoxy(30, 6);
  675.                 textcolor(4);
  676.                 printf("Palavra inexistente");
  677.                 textcolor(15);
  678.             }
  679.             else
  680.             {
  681.                 gotoxy(30, 5);
  682.                 printf("Dados encontrados:");
  683.                 fseek(PtrArq, Pos, 0);
  684.                 fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  685.                 ImprimePalavra(Pal, 3);
  686.             }
  687.            
  688.             getch();
  689.            
  690.             system("cls");
  691.             Cabecalho("Consulta de Palavras");
  692.            
  693.             gotoxy(2, 4);
  694.             printf("Palavra em portugues:");
  695.             fflush(stdin);
  696.             gets(Pal.port);
  697.         }
  698.     }
  699.    
  700.     fclose(PtrArq);
  701.    
  702.     getch();
  703. }
  704.  
  705. char MenuAlteraPessoa(void)
  706. {
  707.     gotoxy(3, 6);
  708.     printf("[A] - Alterar nome");
  709.     gotoxy(3, 7);
  710.     printf("[B] - Alterar senha");
  711.     gotoxy(3, 8);
  712.     printf("[C] - Alterar data");
  713.     gotoxy(3, 9);
  714.     printf("[ESC] - Sair    ");
  715.    
  716.     return toupper(getche());
  717. }
  718.  
  719. char MenuAlteraPalavra(void)
  720. {
  721.     gotoxy(3, 6);
  722.     printf("[A] - Alterar palavra em ingles");
  723.     gotoxy(3, 7);
  724.     printf("[B] - Alterar pontuacao");
  725.     gotoxy(3, 8);
  726.     printf("[C] - Alterar significado ");
  727.     gotoxy(3, 9);
  728.     printf("[ESC] - Sair    ");
  729.    
  730.     return toupper(getche());
  731. }
  732.  
  733. void CadastraPalavra(FILE *PtrPal)
  734. {
  735.     TpPalavra Pal;
  736.    
  737.     system("cls");
  738.     Cabecalho("Cadastro de Palavras");
  739.    
  740.     PtrPal = fopen("Palavra.dat", "ab+");
  741.    
  742.     gotoxy(2, 4);
  743.     printf("Palavra em portugues: ");
  744.     fflush(stdin);
  745.     gets(Pal.port);
  746.    
  747.     while(strcmp(Pal.port, "\0") != 0)
  748.     {
  749.         if(BuscaPalavraPort(PtrPal, Pal.port) >= 0)
  750.         {
  751.             gotoxy(30, 6);
  752.             textcolor(4);
  753.             printf("Palavra ja cadastrada");
  754.             textcolor(15);
  755.         }
  756.         else
  757.         {
  758.             gotoxy(2, 5);
  759.             printf("Palavra em ingles: ");
  760.             fflush(stdin);
  761.             gets(Pal.ing);
  762.            
  763.             while(strcmp(Pal.ing, "\0") == 0)
  764.             {
  765.                 textcolor(4);
  766.                 gotoxy(2, 6);
  767.                 printf("Digite uma palavra valida:");
  768.                 fflush(stdin);
  769.                 textcolor(15);
  770.                 gets(Pal.ing);
  771.             }
  772.            
  773.             gotoxy(2, 7);
  774.             printf("Significado da palavra: ");
  775.             fflush(stdin);
  776.             gets(Pal.significado);
  777.            
  778.             while(strcmp(Pal.significado, "\0") == 0)
  779.             {
  780.                 textcolor(4);
  781.                 gotoxy(2, 8);
  782.                 printf("Digite um significado valido:");
  783.                 fflush(stdin);
  784.                 textcolor(15);
  785.                 gets(Pal.significado);
  786.             }  
  787.            
  788.             gotoxy(2, 9);
  789.             printf("Pontuacao: ");
  790.             scanf("%d", &Pal.pont);
  791.            
  792.             while(Pal.pont <= 0)
  793.             {
  794.                 textcolor(4);
  795.                 gotoxy(2, 10);
  796.                 printf("Digite uma pontuacao valida:");
  797.                 textcolor(15);
  798.                 scanf("%d", &Pal.pont);
  799.             }
  800.            
  801.             Pal.status = 1;
  802.            
  803.             fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  804.            
  805.             textcolor(3);
  806.             gotoxy(25, 15);
  807.             printf("Palavra cadastrada!");
  808.         }
  809.        
  810.         getch();
  811.        
  812.         system("cls");
  813.         Cabecalho("Cadastro de Palavras");
  814.         gotoxy(2, 4);
  815.         printf("Palavra em portugues: ");
  816.         fflush(stdin);
  817.         gets(Pal.port);
  818.     }
  819.    
  820.     getch();
  821.    
  822.     fclose(PtrPal);
  823. }
  824.  
  825. void AlteracaoPalavra(FILE *PtrPal)
  826. {
  827.     TpPalavra Pal;
  828.     char Op;
  829.     int Pos;
  830.    
  831.     system("cls");
  832.    
  833.     Cabecalho("Alteracao de Palavras");
  834.    
  835.     PtrPal = fopen("Palavra.dat", "rb+");
  836.    
  837.     gotoxy(2, 4);
  838.     printf("Palavra em portugues: ");
  839.     fflush(stdin);
  840.     gets(Pal.port);
  841.    
  842.     while(strcmp(Pal.port, "\0") != 0)
  843.     {
  844.         Pos = BuscaPalavraPort(PtrPal, Pal.port);
  845.        
  846.         if(Pos == -1)
  847.         {
  848.             gotoxy(30, 6);
  849.             textcolor(4);
  850.             printf("Palavra inexistente");
  851.             textcolor(15);
  852.         }
  853.         else
  854.         {
  855.             fseek(PtrPal, Pos, 0);
  856.            
  857.             fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  858.            
  859.             Op = MenuAlteraPalavra();
  860.            
  861.             while(Op != 27)
  862.             {
  863.                 switch(Op)
  864.                 {
  865.                     case 'A':
  866.                         gotoxy(2, 10);
  867.                         printf("Palavra em ingles atual: %s", Pal.ing);
  868.                        
  869.                         gotoxy(2, 11);
  870.                         printf("Nova palavra em ingles: ");
  871.                         fflush(stdin);
  872.                         gets(Pal.ing);
  873.                        
  874.                         while(strcmp(Pal.ing, "\0") == 0)
  875.                         {
  876.                             textcolor(4);
  877.                             gotoxy(2, 12);
  878.                             printf("Digite uma palavra valida:");
  879.                             fflush(stdin);
  880.                             textcolor(15);
  881.                             gets(Pal.ing);
  882.                         }
  883.                        
  884.                         fseek(PtrPal, Pos, 0);
  885.                         fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  886.                        
  887.                         textcolor(3);
  888.                         gotoxy(25, 15);
  889.                         printf("Palavra alterada!");
  890.                     break;
  891.                     case 'B':
  892.                         gotoxy(2, 10);
  893.                         printf("Pontuacao atual: %d", Pal.pont);
  894.                            
  895.                         gotoxy(2, 11);
  896.                         printf("Nova pontuacao: ");
  897.                         scanf("%d", &Pal.pont);
  898.                        
  899.                         while(Pal.pont <= 0)
  900.                         {
  901.                             textcolor(4);
  902.                             gotoxy(2, 12);
  903.                             printf("Digite uma pontuacao valida:");
  904.                             textcolor(15);
  905.                             scanf("%d", &Pal.pont);
  906.                         }
  907.                            
  908.                         textcolor(3);
  909.                         gotoxy(25, 15);
  910.                         printf("Pontuacao alterada!");
  911.                     break;
  912.                     case 'C':
  913.                         gotoxy(2, 10);
  914.                         printf("Significado atual: %s", Pal.significado);
  915.                        
  916.                         gotoxy(2, 11);
  917.                         printf("Novo significado: ");
  918.                         fflush(stdin);
  919.                         gets(Pal.significado);
  920.                        
  921.                         while(strcmp(Pal.significado, "\0") == 0)
  922.                         {
  923.                             textcolor(4);
  924.                             gotoxy(2, 12);
  925.                             printf("Digite um significado valido:");
  926.                             fflush(stdin);
  927.                             textcolor(15);
  928.                             gets(Pal.significado);
  929.                         }
  930.                        
  931.                         fseek(PtrPal, Pos, 0);
  932.                         fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  933.                        
  934.                         textcolor(3);
  935.                         gotoxy(25, 15);
  936.                         printf("Significado alterado!");   
  937.                     break;
  938.                     default:
  939.                         gotoxy(2, 11);
  940.                         textcolor(4);
  941.                         printf("Opcao invalida!");
  942.                         textcolor(15);
  943.                     break;
  944.                 }
  945.                
  946.                 getch();
  947.                 system("cls");
  948.                 Cabecalho("Alteracao de Palavras");
  949.                
  950.                 Op = MenuAlteraPalavra();
  951.             }
  952.         }
  953.        
  954.         getch();
  955.        
  956.         system("cls");
  957.         Cabecalho("Alteracao de Palavras");
  958.        
  959.         gotoxy(2, 4);
  960.         printf("Palavra em portugues: ");
  961.         gotoxy(2, 5);
  962.         fflush(stdin);
  963.         gets(Pal.port);
  964.     }
  965.    
  966.     fclose(PtrPal);
  967.    
  968.     getch();
  969. }
  970.  
  971. void ExclusaoFisicaPalavra(FILE *PtrPal)
  972. {
  973.     TpPalavra Pal;
  974.     int Pos;
  975.     char PalavraAux[40];
  976.    
  977.     system("cls");
  978.     Cabecalho("Exclusao Fisica de Palavras");
  979.    
  980.     gotoxy(2, 4);
  981.     printf("Palavra a ser excluida:");
  982.     fflush(stdin);
  983.     gets(PalavraAux);
  984.    
  985.     while(strcmp(PalavraAux, "\0") != 0)
  986.     {
  987.         PtrPal = fopen("Palavra.dat", "rb");
  988.        
  989.         if(PtrPal == NULL)
  990.         {
  991.             gotoxy(30, 6);
  992.             textcolor(4);
  993.             printf("Arquivo de palavras inexistente");
  994.             textcolor(15);
  995.             fclose(PtrPal);
  996.         }
  997.         else
  998.         {
  999.             Pos = BuscaPalavraPort(PtrPal, PalavraAux);
  1000.            
  1001.             if(Pos == -1)
  1002.             {
  1003.                 gotoxy(30, 6);
  1004.                 textcolor(4);
  1005.                 printf("Palavra inexistente");
  1006.                 textcolor(15);
  1007.                 fclose(PtrPal);
  1008.             }
  1009.             else
  1010.             {
  1011.                 fseek(PtrPal, Pos, 0);
  1012.                 fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1013.                 gotoxy(2, 5);
  1014.                 printf("Dados encontrados:");
  1015.                 ImprimePalavra(Pal, 3);
  1016.                
  1017.                 gotoxy(2, 12);
  1018.                 printf("Confirma exclusao?(S/N)");
  1019.                
  1020.                 if(toupper(getche()) == 'S')
  1021.                 {
  1022.                     FILE *PtrTemp = fopen("Temp.dat", "ab+");
  1023.                    
  1024.                     rewind(PtrPal);
  1025.                    
  1026.                     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1027.                    
  1028.                     while(!feof(PtrPal))
  1029.                     {
  1030.                         if(strcmp(Pal.port, PalavraAux) != 0)
  1031.                             fwrite(&Pal, sizeof(TpPalavra), 1, PtrTemp);
  1032.                            
  1033.                         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1034.                     }
  1035.                    
  1036.                     fclose(PtrPal);
  1037.                     fclose(PtrTemp);
  1038.                    
  1039.                     remove("Palavra.dat");
  1040.                     rename("Temp.dat", "Palavra.dat");
  1041.                    
  1042.                     textcolor(3);
  1043.                     gotoxy(25, 15);
  1044.                     printf("Palavra excluida!");
  1045.                 }
  1046.                 else
  1047.                     fclose(PtrPal);
  1048.             }
  1049.         }
  1050.        
  1051.         getch();
  1052.        
  1053.         system("cls");
  1054.         Cabecalho("Exclusao Fisica de Palavras");
  1055.         gotoxy(2, 4);
  1056.         printf("Palavra a ser excluida:");
  1057.         fflush(stdin);
  1058.         gets(PalavraAux);
  1059.     }
  1060.    
  1061.     getch();
  1062. }
  1063.  
  1064. void ExclusaoLogicaPalavra(FILE *PtrPal)
  1065. {
  1066.     TpPalavra Pal;
  1067.     int Pos;
  1068.    
  1069.     system("cls");
  1070.     Cabecalho("Exclusao Logica de Palavras");
  1071.    
  1072.     PtrPal = fopen("Palavra.dat", "rb+");
  1073.    
  1074.     gotoxy(2, 4);
  1075.     printf("Palavra a ser excluida:");
  1076.     fflush(stdin);
  1077.     gets(Pal.port);
  1078.    
  1079.     while(strcmp(Pal.port, "\0") != 0)
  1080.     {
  1081.         Pos = BuscaPalavraPort(PtrPal, Pal.port);
  1082.        
  1083.         if(Pos == -1)
  1084.         {
  1085.             gotoxy(30, 6);
  1086.             textcolor(4);
  1087.             printf("Palavra inexistente");
  1088.             textcolor(15);
  1089.             fclose(PtrPal);
  1090.         }
  1091.         else
  1092.         {
  1093.             fseek(PtrPal, Pos, 0);
  1094.             fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1095.             gotoxy(2, 5);
  1096.             printf("Dados encontrados:");
  1097.             ImprimePalavra(Pal, 3);
  1098.                
  1099.             gotoxy(2, 12);
  1100.             printf("Confirma exclusao?(S/N)");
  1101.        
  1102.             if(toupper(getche()) == 'S')
  1103.             {
  1104.                 Pal.status = 0;
  1105.                
  1106.                 fseek(PtrPal, Pos, 0);
  1107.                 fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1108.            
  1109.                 textcolor(3);
  1110.                 gotoxy(25, 15);
  1111.                 printf("Palavra excluida!");
  1112.             }
  1113.         }
  1114.        
  1115.         getch();
  1116.        
  1117.         system("cls");
  1118.         Cabecalho("Exclusao Logica de Palavras");
  1119.        
  1120.         gotoxy(2, 4);
  1121.         printf("Palavra a ser excluida:");
  1122.         fflush(stdin);
  1123.         gets(Pal.port);
  1124.     }
  1125.    
  1126.     fclose(PtrPal);
  1127.    
  1128.     getch();
  1129. }
  1130.  
  1131. void CadastraPessoa(FILE *PtrPes)
  1132. {
  1133.     TpPessoa Pes;
  1134.    
  1135.     system("cls");
  1136.     Cabecalho("Cadastro de Pessoas");
  1137.    
  1138.     PtrPes = fopen("Pessoa.dat", "ab+");
  1139.    
  1140.     gotoxy(2, 4);
  1141.     printf("Login a ser cadastrado: ");
  1142.     fflush(stdin);
  1143.     gets(Pes.login);
  1144.    
  1145.     while(strcmp(Pes.login, "\0") != 0)
  1146.     {
  1147.         if(BuscaExaustivaPessoa(PtrPes, Pes.login) >= 0)
  1148.         {
  1149.             gotoxy(30, 6);
  1150.             textcolor(4);
  1151.             printf("Login ja cadastrado");
  1152.             textcolor(15);
  1153.         }
  1154.         else
  1155.         {
  1156.             gotoxy(2, 5);
  1157.             printf("Nome: ");
  1158.             fflush(stdin);
  1159.             gets(Pes.nome);
  1160.            
  1161.             while(strcmp(Pes.nome, "\0") == 0)
  1162.             {
  1163.                 textcolor(4);
  1164.                 gotoxy(2, 6);
  1165.                 printf("Digite um nome valido:");
  1166.                 fflush(stdin);
  1167.                 textcolor(15);
  1168.                 gets(Pes.nome);
  1169.             }
  1170.            
  1171.             gotoxy(2, 7);
  1172.             printf("Senha: "); textcolor(0);
  1173.             scanf("%d", &Pes.senha);
  1174.                        
  1175.             while(Pes.senha <= 0)
  1176.             {
  1177.                 textcolor(4);
  1178.                 gotoxy(2, 8);
  1179.                 printf("Digite uma senha valida:");
  1180.                 textcolor(0);
  1181.                 scanf("%d", &Pes.senha);
  1182.             }
  1183.            
  1184.             textcolor(15);
  1185.            
  1186.             gotoxy(2, 9);
  1187.             printf("Data (dd mm aaaa): ");
  1188.             scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
  1189.    
  1190.             while(Pes.Data.dia <= 0 || Pes.Data.mes <= 0 || Pes.Data.ano <= 0 )
  1191.             {
  1192.                 textcolor(4);
  1193.                 gotoxy(2, 10);
  1194.                 printf("Digite uma data valida: ");
  1195.                 textcolor(15);
  1196.                 scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
  1197.             }
  1198.                
  1199.             Pes.pont = 0;
  1200.             Pes.status = 1;    
  1201.             fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1202.            
  1203.             textcolor(3);
  1204.             gotoxy(25, 15);
  1205.             printf("Pessoa cadastrada!");
  1206.         }
  1207.        
  1208.         getch();
  1209.        
  1210.         system("cls");
  1211.         Cabecalho("Cadastro de Pessoas");
  1212.        
  1213.         gotoxy(2, 4);
  1214.         printf("Login a ser cadastrado: ");
  1215.         fflush(stdin);
  1216.         gets(Pes.login);
  1217.     }
  1218.    
  1219.     fclose(PtrPes);
  1220.    
  1221.     getch();
  1222. }
  1223.  
  1224. void AlteracaoPessoa(FILE *PtrPes)
  1225. {
  1226.     TpPessoa Pes;
  1227.     int Pos;
  1228.     char Op;
  1229.    
  1230.     system("cls");
  1231.     Cabecalho("Alteracao de Pessoas");
  1232.    
  1233.     PtrPes = fopen("Pessoa.dat", "rb+");
  1234.    
  1235.     gotoxy(2, 4);
  1236.     printf("Login da pessoa a ser alterada: ");
  1237.     fflush(stdin);
  1238.     gets(Pes.login);
  1239.    
  1240.     while(strcmp(Pes.login, "\0") != 0)
  1241.     {
  1242.         Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
  1243.        
  1244.         if(Pos == -1)
  1245.         {
  1246.             gotoxy(30, 6);
  1247.             textcolor(4);
  1248.             printf("Login inexistente!");  
  1249.             textcolor(15);
  1250.         }
  1251.         else
  1252.         {
  1253.             fseek(PtrPes, Pos, 0);
  1254.            
  1255.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1256.            
  1257.             Op = MenuAlteraPessoa();
  1258.            
  1259.             while(Op != 27)
  1260.             {
  1261.                 switch(Op)
  1262.                 {
  1263.                     case 'A':
  1264.                         gotoxy(2, 10);
  1265.                         printf("Nome atual: %s\n", Pes.nome);
  1266.                         gotoxy(2, 11);
  1267.                         printf("Novo nome: ");
  1268.                         fflush(stdin);
  1269.                         gets(Pes.nome);
  1270.                        
  1271.                         while(strcmp(Pes.nome, "\0") == 0)
  1272.                         {
  1273.                             textcolor(4);
  1274.                             gotoxy(2, 12);
  1275.                             printf("Digite um nome valido:");
  1276.                             fflush(stdin);
  1277.                             textcolor(15);
  1278.                             gets(Pes.nome);
  1279.                         }
  1280.                        
  1281.                         fseek(PtrPes, Pos, 0);
  1282.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1283.                        
  1284.                         textcolor(3);
  1285.                         gotoxy(25, 15);
  1286.                         printf("Nome alterado!");
  1287.                     break;
  1288.                     case 'B':
  1289.                         gotoxy(2, 10);
  1290.                         printf("Senha atual: %d\n", Pes.senha);
  1291.                         gotoxy(2, 11);
  1292.                         printf("Nova senha: "); textcolor(0);
  1293.                         scanf("%d", &Pes.senha);
  1294.                        
  1295.                         while(Pes.senha <= 0)
  1296.                         {
  1297.                             textcolor(4);
  1298.                             gotoxy(2, 12);
  1299.                             printf("Digite uma senha valida:");
  1300.                             textcolor(0);
  1301.                             scanf("%d", &Pes.senha);
  1302.                         }
  1303.                        
  1304.                         fseek(PtrPes, Pos, 0);
  1305.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1306.                        
  1307.                         textcolor(3);
  1308.                         gotoxy(25, 15);
  1309.                         printf("Senha alterada!");
  1310.                     break;
  1311.                     case 'C':
  1312.                         gotoxy(2, 10);
  1313.                         printf("Data atual: %d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
  1314.                        
  1315.                         gotoxy(2, 11);
  1316.                         printf("Nova data (dd mm aaaa): ");
  1317.                         scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
  1318.                        
  1319.                        
  1320.                         while(Pes.Data.dia <= 0 || Pes.Data.mes <= 0 || Pes.Data.ano <= 0 )
  1321.                         {
  1322.                             textcolor(4);
  1323.                             gotoxy(2, 12);
  1324.                             printf("Digite uma data valida: ");
  1325.                             scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
  1326.                         }
  1327.                        
  1328.                         fseek(PtrPes, Pos, 0);
  1329.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1330.                        
  1331.                         textcolor(3);
  1332.                         gotoxy(25, 15);
  1333.                         printf("Data alterada!");
  1334.                     break;
  1335.                     default:
  1336.                         gotoxy(2, 11);
  1337.                         textcolor(4);
  1338.                         printf("Opcao invalida!");
  1339.                         textcolor(15);
  1340.                     break;
  1341.                 }
  1342.                
  1343.                 getch();
  1344.                 system("cls");
  1345.                 Cabecalho("Alteracao de Pessoas");
  1346.                
  1347.                 Op = MenuAlteraPessoa();
  1348.             }
  1349.         }
  1350.        
  1351.         getch();
  1352.        
  1353.         system("cls");
  1354.         Cabecalho("Alteracao de Pessoas");
  1355.        
  1356.         gotoxy(2, 4);
  1357.         printf("Login da pessoa a ser alterada: ");
  1358.         fflush(stdin);
  1359.         gets(Pes.login);
  1360.     }
  1361.    
  1362.     fclose(PtrPes);
  1363.    
  1364.     getch();
  1365. }
  1366.  
  1367. int BuscaBinariaPessoa(FILE *PtrPes, char loginChave[10])
  1368. {
  1369.     int inicio = 0, meio, fim;
  1370.     TpPessoa R;
  1371.    
  1372.     fseek(PtrPes, 0, 2);
  1373.    
  1374.     fim = ftell(PtrPes) / sizeof(TpPessoa) - 1;
  1375.    
  1376.     meio = fim / 2;
  1377.    
  1378.     fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  1379.     fread(&R, sizeof(TpPessoa), 1, PtrPes);
  1380.    
  1381.     while(inicio < fim && strcmp(loginChave, R.login) != 0)
  1382.     {
  1383.         if(strcmp(loginChave, R.login) > 0)
  1384.             inicio = meio + 1;
  1385.         else
  1386.             fim = meio - 1;
  1387.            
  1388.         meio = (inicio + fim) / 2;
  1389.        
  1390.         fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  1391.         fread(&R, sizeof(TpPessoa), 1, PtrPes);
  1392.     }
  1393.    
  1394.     if(strcmp(loginChave, R.login) == 0)
  1395.         return meio * sizeof(TpPessoa);
  1396.     else
  1397.         return -1;
  1398. }
  1399.  
  1400. int BuscaBinariaPalavra(FILE *PtrPal, char palavraChave[40])
  1401. {
  1402.     TpPalavra Pal;
  1403.     int inicio = 0, meio, fim;
  1404.    
  1405.     fseek(PtrPal, 0, 2);
  1406.    
  1407.     fim = ftell(PtrPal) / sizeof(TpPalavra) - 1;
  1408.    
  1409.     meio = fim / 2;
  1410.    
  1411.     fseek(PtrPal, meio, 0);
  1412.    
  1413.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1414.    
  1415.     while(inicio < fim && stricmp(palavraChave, Pal.port) != 0)
  1416.     {
  1417.         if(stricmp(palavraChave, Pal.port) > 0)
  1418.             inicio = meio + 1;
  1419.         else
  1420.             inicio = meio - 1;
  1421.            
  1422.         meio = (inicio + fim) / 2;
  1423.        
  1424.         fseek(PtrPal, meio, 0);
  1425.        
  1426.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1427.     }
  1428.    
  1429.     if(stricmp(palavraChave, Pal.port) == 0)
  1430.         return meio * sizeof(TpPalavra);
  1431.     else
  1432.         return -1;
  1433. }
  1434.  
  1435. void ConsultaPessoa(FILE *PtrPes)
  1436. {
  1437.     TpPessoa Pes;
  1438.     int Pos;
  1439.    
  1440.     system("cls");
  1441.     Cabecalho("Consulta de pessoas");
  1442.    
  1443.     PtrPes = fopen("Pessoa.dat", "rb");
  1444.    
  1445.     if(PtrPes == NULL)
  1446.     {
  1447.         gotoxy(30, 6);
  1448.         textcolor(4);
  1449.         printf("Arquivo de pessoas inexistente");
  1450.         textcolor(15);
  1451.     }
  1452.     else
  1453.     {
  1454.         gotoxy(2, 4);
  1455.         printf("Login a ser procurado: ");
  1456.         fflush(stdin);
  1457.         gets(Pes.login);
  1458.        
  1459.         while(strcmp(Pes.login, "\0") != 0)
  1460.         {
  1461.             Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
  1462.            
  1463.             if(Pos == -1)
  1464.             {
  1465.                 gotoxy(30, 6);
  1466.                 textcolor(4);
  1467.                 printf("Login inexistente");
  1468.                 textcolor(15);
  1469.             }
  1470.             else
  1471.             {
  1472.                 gotoxy(30, 5);
  1473.                 printf("Dados encontrados:");
  1474.                 fseek(PtrPes, Pos, 0);
  1475.                 fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1476.                 ImprimePessoa(Pes, 3);
  1477.             }
  1478.            
  1479.             getch();
  1480.            
  1481.             system("cls");
  1482.             Cabecalho("Consulta de pessoas");
  1483.                    
  1484.             gotoxy(2, 4);
  1485.             printf("Login a ser procurado: ");
  1486.             fflush(stdin);
  1487.             gets(Pes.login);
  1488.         }
  1489.     }
  1490.    
  1491.     fclose(PtrPes);
  1492.     getch();
  1493. }
  1494.  
  1495. int BuscaPalavraIngles(FILE *PtrPal, char Ing[40])
  1496. {
  1497.     TpPalavra Pal;
  1498.    
  1499.     rewind(PtrPal);
  1500.    
  1501.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1502.    
  1503.     while(!feof(PtrPal) && stricmp(Pal.ing, Ing) != 0)
  1504.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1505.        
  1506.     if(stricmp(Pal.ing, Ing) == 0)
  1507.         return ftell(PtrPal) - sizeof(TpPalavra);
  1508.     else
  1509.         return -1;
  1510. }
  1511.  
  1512. int ELetra(char c)
  1513. {
  1514.     if(toupper(c) >= 65 && toupper(c) <= 92)
  1515.         return 1;
  1516.     else
  1517.         return 0;
  1518. }
  1519.  
  1520. void Tradutor(FILE *PtrPal)
  1521. {
  1522.     TpPalavra Pal;
  1523.     int Pos, i, Aux;
  1524.     char Frase[1000], StrAux[1000], Traducao[1000];
  1525.    
  1526.     system("cls");
  1527.    
  1528.     Cabecalho("Tradutor");
  1529.    
  1530.     PtrPal = fopen("Palavra.dat", "rb");
  1531.    
  1532.     if(PtrPal == NULL)
  1533.     {
  1534.         gotoxy(30, 6);
  1535.         textcolor(4);
  1536.         printf("Arquivo de palavras inexistente");
  1537.         textcolor(15);
  1538.     }
  1539.     else
  1540.     {
  1541.         gotoxy(2, 4);
  1542.         printf("Texto em ingles:");
  1543.         fflush(stdin);
  1544.         gets(Frase);
  1545.        
  1546.         while(strcmp(Frase, "\0") != 0)
  1547.         {
  1548.             strcpy(Traducao, "\0");
  1549.            
  1550.             Aux = 0;
  1551.            
  1552.             for(i = 0; i <= strlen(Frase); i++)
  1553.             {
  1554.                 if(ELetra(Frase[i]) == 1)
  1555.                     StrAux[Aux++] = Frase[i];
  1556.                 else if(Frase[i] == ' ' || Frase[i] == '\0')
  1557.                 {
  1558.                     StrAux[Aux] = '\0';
  1559.                    
  1560.                     Pos = BuscaPalavraIngles(PtrPal, StrAux);
  1561.                    
  1562.                     strcpy(StrAux, "\0");
  1563.                                    
  1564.                     if(Pos == -1)
  1565.                         strcat(Traducao, "? ");
  1566.                     else
  1567.                     {
  1568.                         fseek(PtrPal, Pos, 0);
  1569.                         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1570.                        
  1571.                         strcat(Traducao, Pal.port);
  1572.                         strcat(Traducao, " ");
  1573.                     }
  1574.                    
  1575.                     Aux = 0;
  1576.                 }
  1577.             }
  1578.            
  1579.             gotoxy(2, 5);
  1580.             printf("Traducao: %s", Traducao);
  1581.            
  1582.             getch();
  1583.            
  1584.             system("cls");
  1585.             Cabecalho("Tradutor");
  1586.            
  1587.             gotoxy(2, 4);
  1588.             printf("Texto em ingles:");
  1589.             fflush(stdin);
  1590.             gets(Frase);
  1591.         }
  1592.     }
  1593.    
  1594.     fclose(PtrPal);
  1595. }
  1596.  
  1597. void InsercaoAutomatica(FILE *PtrPes, FILE *PtrPal)
  1598. {
  1599.     int NumRPes, NumRPal;
  1600.     TpPessoa VetPessoa  = {};
  1601.     TpPalavra VetPalavra = {};
  1602. }
  1603.  
  1604.  
  1605. char Menu(void)
  1606. {
  1607.     int i;
  1608.    
  1609.     system("cls");
  1610.    
  1611.     Quadro();
  1612.    
  1613.     textcolor(14);
  1614.    
  1615.     gotoxy(27, 2);
  1616.     printf("ATP 2 - JOGO DA FORCA\n");
  1617.    
  1618.     for(i = 2; i <= 79; i++)
  1619.     {
  1620.         gotoxy(i, 3);
  1621.         printf("%c", 205);
  1622.     }
  1623.    
  1624.     textbackground(4);
  1625.    
  1626.     gotoxy(4, 4);
  1627.     printf("      MENU DE PALAVRAS           ");
  1628.    
  1629.     gotoxy(4, 5);
  1630.     printf("[A] - Cadastrar palavras         ");
  1631.     gotoxy(4, 6);
  1632.     printf("[B] - Relatorio de palavras      ");
  1633.     gotoxy(4, 7);
  1634.     printf("[C] - Alteracao de palavras      ");
  1635.     gotoxy(4, 8);
  1636.     printf("[D] - Consulta de palavras       ");
  1637.     gotoxy(4, 9);
  1638.     printf("[E] - Exclusao Fisica de Palavras");
  1639.     gotoxy(4, 10);
  1640.     printf("[F] - Exclusao Logica de Palavras");
  1641.    
  1642.     gotoxy(40, 4);
  1643.     printf("      MENU DE PESSOAS            ");
  1644.     gotoxy(40, 5);
  1645.     printf("[G] - Cadastrar pessoas          ");
  1646.     gotoxy(40, 6);
  1647.     printf("[H] - Relatorio de pessoas       ");
  1648.     gotoxy(40, 7);
  1649.     printf("[I] - Alteracao de pessoas       ");
  1650.     gotoxy(40, 8);
  1651.     printf("[J] - Consulta de pessoas        ");
  1652.     gotoxy(40, 9);
  1653.     printf("[I] - Exclusao Fisica de Pessoas ");
  1654.     gotoxy(40, 10);
  1655.     printf("[K] - Exclusao Logica de Pessoas ");
  1656.    
  1657.     gotoxy(25, 13);
  1658.     printf("            MENU GERAL            ");
  1659.    
  1660.     gotoxy(4, 15);
  1661.     printf("[L] - JOGAR FORCA                ");
  1662.     gotoxy(40, 15);
  1663.     printf("[M] - Tradutor de frases         ");
  1664.     gotoxy(4, 16);
  1665.     printf("[N] - Insercao Automatica        ");
  1666.     gotoxy(40, 16);
  1667.     printf("[ESC] - Sair                     ");
  1668.    
  1669.     textbackground(0);
  1670.     textcolor(7);
  1671.    
  1672.     return toupper(getche());
  1673. }
  1674.  
  1675. void Executa(void)
  1676. {
  1677.     char Op;
  1678.     FILE *PtrArq, *PtrPes;
  1679.    
  1680.     Op = Menu();
  1681.    
  1682.     while(Op != 27)
  1683.     {
  1684.         switch(Op)
  1685.         {
  1686.             case 'A':
  1687.                 CadastraPalavra(PtrArq);
  1688.             break;
  1689.             case 'B':
  1690.                 RelatorioPalavras(PtrArq);
  1691.             break;
  1692.             case 'C':
  1693.                 AlteracaoPalavra(PtrArq);
  1694.             break;
  1695.             case 'D':
  1696.                 ConsultaPalavras(PtrArq);
  1697.             break;
  1698.             case 'E':
  1699.                 ExclusaoFisicaPalavra(PtrArq);
  1700.             break;
  1701.             case 'F':
  1702.                 RelatorioPessoa(PtrPes);
  1703.             break;
  1704.             case 'G':
  1705.                 CadastraPessoa(PtrPes);
  1706.             break;
  1707.             case 'H':
  1708.                 ConsultaPessoa(PtrPes);
  1709.             break;
  1710.             case 'I':
  1711.                 ExclusaoFisicaPessoa(PtrPes);
  1712.             break;
  1713.             case 'J':
  1714.                 Tradutor(PtrArq);
  1715.             break;
  1716.             default:
  1717.                 printf("Opcao invalida\n");
  1718.                 getch();
  1719.         }
  1720.         Op = Menu();
  1721.     }
  1722.    
  1723.     getch();
  1724. }
  1725.  
  1726. int main(void)
  1727. {
  1728.     Executa();
  1729.    
  1730.     return 1;
  1731. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement