Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 102.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <ctype.h>
  6. #include <cstdlib>
  7. #include <conio.h>
  8. #include <time.h>
  9. #include <windows.h>
  10. #include <locale.h>
  11.  
  12. enum {
  13.     CONST_ART_CHECK,
  14.     CONST_NAME_CHECK,
  15.     CONST_SPECIFIC_CHECK,
  16.     CONST_CPF_CHECK,
  17.     CONST_LOGIN_CHECK,
  18.     CONST_PASSWORD_CHECK
  19. };
  20.  
  21. using namespace std;
  22.  
  23.  
  24. bool edit, pendent, logon;
  25. ifstream file;
  26. ofstream out_file;
  27.  
  28. struct Register {
  29.     char login[13], password[11], name[1000], job[100], CPF[15], key[8], d[3], m[3], y[5], dg[3], mg[3], yg[5];
  30.     int day, month, year, gun_day, gun_month, gun_year, status;
  31.    
  32.     void writeIntoFile();
  33. };
  34.  
  35. struct Cop {
  36.     char name[1000], login[13], password[11], job[100], CPF[15], key[8], birth_date[11], gun[11];
  37.     int age, access, status;
  38.    
  39. };
  40.  
  41. struct Villain {
  42.     int age, status, ID;
  43.     char name[1000], nickname[1000], art[6], specific[51], extra[51];
  44.    
  45.     void writeIntoBadFile();
  46. };
  47.    
  48. void getIndexesBySplittingSentence(char* line, char split_character, int j[]);
  49. int getIndexesSize(char* line, char split_character);
  50. void SetColor(int ForgC);
  51. void writeInColor(const char* phrase, int color);
  52. void adjustName(char name[]);
  53. void toLower(char w[]);
  54. bool isInUse(char login[]);
  55. int getNameOccurrences(char name[]);
  56. int getAccessLevel(const char* vocation);
  57. void correctAndTransferCPF(char CPF[], char old_CPF[]);
  58. void deleteAccount(const char* login);
  59. int getFileLineCount(const char* file);
  60. void RegisterCop();
  61. void RegisterVillain();
  62. void openWebsite(const char* website);
  63. void printByBadArray(int ID[], int count);
  64. void printBadInfoAbout(int ID);
  65. void printInfoAbout(char login[], int access, bool yourself, bool show_new_job);
  66. void printByArray(char *array[], int count, int access, bool show_new_job);
  67. void lookForID();
  68. void lookForArt();
  69. void lookForStatus();
  70. void lookForAge(int access);
  71. void lookForJob(int access);
  72. void lookForName(int access);
  73. int getYesOrNo();
  74. void fillSentence(char line[], int begin, int end, char target[]);
  75. bool compareTwoStrings(char str1[], char str2[]);
  76. void showInfosAboutName(char name[], int access);
  77. void writeColorInfo(const char* art);
  78. bool isInArray(int array[], int size, int element);
  79. Villain getVillainInfo(int ID);
  80. Cop getAccountInfo(char input_login[]);
  81. void getArt(int art, bool open_site);
  82. void updateStatus();
  83. void updateAge();
  84. void updateExtra();
  85. void updateBadLine(const char* line, int start, const char* new_info, int new_ID);
  86. bool isIDValid(int ID);
  87. void showFullVillainRegister();
  88. void showFullRegister(int access);
  89. void changePassword(char login[]);
  90. void changeCargo(char login[]);
  91. void changeDate(char login[]);
  92. void executeDeletion(int access, char login[]);
  93. void showPendentJobs(int count, bool admin);
  94. void showPendentAccounts(int count, bool admin);
  95. void generateSecurityKey(char key[]);
  96. void recoverAccount();
  97. bool isCPFInUse(char CPF[]);
  98. int getAccessLevel(const char * vocation);
  99. void createAdminAccount();
  100. bool isStringValid(char str[], int check_type);
  101. void updateAccount(char login[], int start, char new_value[], bool admin);
  102. void getOldLine(char get_line[]);
  103. bool checkCombination(char login[], char password[]);
  104. int getPendentJobSolicitations();
  105. int getPendentAdmissions();
  106.  
  107. int main()
  108. {
  109.     bool _time = true;
  110.     setlocale(LC_ALL, "Portuguese");
  111.    
  112.     bool program_running = true;
  113.    
  114.     system("color F0");
  115.     cout << "-----------------------------------------------------------------------" << endl;
  116.     cout << "************** BEM VINDO AO SISTEMA DE CONTROLE POLICIAL **************" << endl;
  117.     cout << "-----------------------------------------------------------------------" << endl << endl;
  118.    
  119.     if(getFileLineCount("cop_data.txt") == 0) createAdminAccount();
  120.    
  121.     while(program_running)
  122.     {
  123.         if(!_time) system("CLS");
  124.        
  125.         char action[10];
  126.         cout << "-----------------------------------------------------------------------" << endl;
  127.         cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  128.        
  129.         cout << "       -> ";
  130.         writeInColor("registrar ", 9);
  131.         cout << "no sistema" << endl;
  132.         cout << "       -> ";
  133.         writeInColor("logar ", 9);
  134.         cout << "no sistema" << endl;
  135.         cout << "       -> ";
  136.         writeInColor("recuperar ", 9);
  137.         cout << "sua senha" << endl;
  138.         cout << "       -> ";
  139.         writeInColor("saber ", 9);
  140.         cout << "mais sobre o Sistema de Controle Policial" << endl;
  141.         cout << "       -> ";
  142.         writeInColor("sair ", 9);
  143.         cout << "para finalizar o sistema" << endl << endl;
  144.        
  145.         cout << "-----------------------------------------------------------------------" << endl << endl;
  146.        
  147.         _time = false;
  148.        
  149.         cin.getline(action, 10);
  150.        
  151.         toLower(action);
  152.        
  153.         system("CLS");
  154.        
  155.         if(strcmp(action, "registrar") == 0)
  156.             RegisterCop();
  157.         else if(strcmp(action, "logar") == 0)
  158.         {
  159.             bool continue_login = true, check_login = true;
  160.             char login[13], password[11];
  161.            
  162.             do
  163.             {
  164.                 int input;
  165.                
  166.                 if(!check_login)
  167.                 {
  168.                     cout << "Combinação inválida. (login inexistente ou senha incorreta)" << endl << endl;
  169.                     cout << "Se você esqueceu sua senha, tente recuperá-la através de nosso método por chave de segurança." << endl;
  170.                     cout << "Deseja voltar ao menu de opções?" << endl;
  171.                    
  172.                     input = getYesOrNo();
  173.                    
  174.                     if(input == 0)
  175.                     {
  176.                         continue_login = false;
  177.                         break;
  178.                     }
  179.                    
  180.                     cin.ignore();
  181.                 }
  182.                
  183.                 cout << "-----------------------------" << endl;
  184.                 cout << "********** LOGANDO **********" << endl;
  185.                 cout << "-----------------------------" << endl << endl;
  186.                
  187.                 writeInColor(" Login", 9);
  188.                 cout << ": ";
  189.            
  190.                 cin.getline(login, 13);
  191.                
  192.                 writeInColor(" Senha", 9);
  193.                 cout << ": ";
  194.        
  195.                 int count = 0;
  196.                 while(count <= 10)
  197.                 {      
  198.                     if(count == 10) {password[10] = '\0'; break;}
  199.                    
  200.                     password[count] = _getch();
  201.            
  202.                     if(password[count] == '\n' || password[count] == '\r')
  203.                     {
  204.                         password[count] = '\0';
  205.                         break;
  206.                     }
  207.                    
  208.                     cout << "*";
  209.                     count++;
  210.                 }
  211.                
  212.                 system("CLS");
  213.                 check_login = false;
  214.             } while(!checkCombination(login, password));
  215.            
  216.             if(continue_login)
  217.             {
  218.                 Cop data = getAccountInfo(login);
  219.                
  220.                 if(data.status == -1)
  221.                 {
  222.                     cout << "Esta conta ainda não foi ativada em nosso sistema. Por gentileza, aguarde até um oficial autorizá-la.";
  223.                     cout << endl << endl << "Pressione qualquer tecla para voltar ao menu de opções." << endl;
  224.                     getch();
  225.                    
  226.                     system("CLS");
  227.                 }
  228.                 else
  229.                 {
  230.                     char new_action[10];
  231.                     logon = true;
  232.                     time_t t = time(NULL);
  233.                     tm* timePtr = localtime(&t);
  234.                    
  235.                     int k[getIndexesSize(data.birth_date, '-')];
  236.                     getIndexesBySplittingSentence(data.birth_date, '-', k);
  237.                    
  238.                     char day_str[3], mon_str[3], year_str[5];
  239.                    
  240.                     fillSentence(data.birth_date, -1, k[0], day_str);
  241.                     fillSentence(data.birth_date, k[0], k[1], mon_str);
  242.                     fillSentence(data.birth_date, k[1], strlen(data.birth_date), year_str);
  243.                    
  244.                     int day = atoi(day_str), month = atoi(mon_str), year = atoi(year_str);
  245.                    
  246.                     if(timePtr->tm_mday == day && timePtr->tm_mon + 1 == month)
  247.                         cout << "FELIZ ANIVERSÁRIO, " << data.name << "!" << endl << endl;
  248.                     else
  249.                     {
  250.                         if(timePtr->tm_hour >= 19 || timePtr->tm_hour < 6)
  251.                         cout << "Boa noite, ";
  252.                         else if(timePtr->tm_hour >= 6 || timePtr->tm_hour < 12)
  253.                             cout << "Bom dia, ";
  254.                         else
  255.                             cout << "Boa tarde, ";
  256.                        
  257.                         cout << data.name << "." << endl << endl;
  258.                     }
  259.                    
  260.                     int g[getIndexesSize(data.gun, '-')];
  261.                     getIndexesBySplittingSentence(data.gun, '-', g);
  262.                    
  263.                     int gday_size = g[0], gmon_size = g[1] - g[0] - 1, gyear_size = strlen(data.gun) - g[1] - 1;
  264.                    
  265.                     char gday_str[gday_size], gmon_str[gmon_size], gyear_str[gyear_size];
  266.                    
  267.                     fillSentence(data.gun, -1, g[0], gday_str);
  268.                     fillSentence(data.gun, g[0], g[1], gmon_str);
  269.                     fillSentence(data.gun, g[1], strlen(data.gun), gyear_str);
  270.                    
  271.                     day = atoi(gday_str);
  272.                     month = atoi(gmon_str);
  273.                     year = atoi(gyear_str);
  274.                    
  275.                     int time_diff = (year + 5) - (timePtr->tm_year + 1900);
  276.                    
  277.                     if(time_diff <= 1)
  278.                     {
  279.                         if(timePtr->tm_mday > day && timePtr->tm_mon + 1 >= month)
  280.                             cout << "-> Seu documento de registro de arma expirou. Por favor, renove-o o mais rápido possível e atualize seus dados no sistema." << endl << endl << endl;
  281.                         else if(month - timePtr->tm_mon + 1 <= 6)
  282.                             cout << "-> Seu documento de registro de arma está próximo da validade. Não esqueça de renová-lo e atualizar seus dados no sistema." << endl << endl << endl;
  283.                     }
  284.                    
  285.                     bool new_time = true;
  286.                    
  287.                     while(logon)
  288.                     {
  289.                         data = getAccountInfo(login);
  290.                        
  291.                         if(!new_time) system("CLS");
  292.                        
  293.                         cout << "-----------------------------------------------------------------------" << endl;
  294.                        
  295.                         cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  296.                    
  297.                         cout << "       -> ";
  298.                         writeInColor("policia ", 9);
  299.                         cout << "para verificar o banco de dados policial" << endl;
  300.                        
  301.                         cout << "       -> ";
  302.                         writeInColor("criminoso ", 9);
  303.                         cout << "para verificar o banco de dados de criminosos" << endl;
  304.                        
  305.                         cout << "       -> ";
  306.                         writeInColor("pessoal ", 9);
  307.                         cout << "para verificar suas informações pessoais" << endl;
  308.                        
  309.                         if(strcmp(data.key, "-1") == 0)
  310.                         {
  311.                             cout << "       -> ";
  312.                             writeInColor("chave ", 9);
  313.                             cout << "para gerar uma chave de segurança" << endl;
  314.                         }
  315.                        
  316.                         if(data.access > 9)
  317.                         {
  318.                             cout << "       -> ";
  319.                             writeInColor("pendente ", 9);
  320.                             cout << "para checar as autorizações pendentes no sistema" << endl;
  321.                         }
  322.                        
  323.                         cout << "       -> ";
  324.                         writeInColor("sair ", 9);
  325.                         cout << "para deslogar do sistema" << endl << endl;
  326.                        
  327.                         cout << "-----------------------------------------------------------------------" << endl << endl;
  328.                        
  329.                         new_time = false;
  330.                        
  331.                         cin.getline(new_action, 10);
  332.                        
  333.                         toLower(new_action);
  334.                        
  335.                         if(strcmp(new_action, "policia") == 0)
  336.                         {
  337.                             bool searching = true;
  338.                             char action_cop[9];
  339.                            
  340.                             while(searching)
  341.                             {
  342.                                 system("CLS");
  343.                                
  344.                                 cout << "-----------------------------------------------------------------------" << endl;
  345.                                
  346.                                 cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  347.                        
  348.                                 cout << "       -> ";
  349.                                 writeInColor("procurar ", 9);
  350.                                 cout << "para procurar registro(s) no sistema" << endl;
  351.                                
  352.                                 cout << "       -> ";
  353.                                 writeInColor("todos ", 9);
  354.                                 cout << "para receber o registro policial completo do sistema" << endl;
  355.                                    
  356.                                 if(data.access > 9)
  357.                                 {
  358.                                     cout << "       -> ";
  359.                                     writeInColor("remover ", 9);
  360.                                     cout << "para remover algum policial do sistema" << endl;
  361.                                 }
  362.                                
  363.                                 cout << "       -> ";
  364.                                 writeInColor("voltar ", 9);
  365.                                 cout << "para voltar ao menu de opções" << endl << endl;
  366.                                
  367.                                 cout << "-----------------------------------------------------------------------" << endl << endl;
  368.                                
  369.                                 cin.getline(action_cop, 9);
  370.                                
  371.                                 toLower(action_cop);
  372.                                
  373.                                 system("CLS");
  374.                                
  375.                                 if(strcmp(action_cop, "procurar") == 0)
  376.                                 {
  377.                                     int n_action;
  378.                                    
  379.                                     cout << "-----------------------------------------------------------------------" << endl;
  380.                                     cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  381.                                     cout << "       -> (";
  382.                                     writeInColor("1", 9);
  383.                                     cout << ") para procurar por nome" << endl;
  384.                                    
  385.                                     cout << "       -> (";
  386.                                     writeInColor("2", 9);
  387.                                     cout << ") para procurar por cargo" << endl;
  388.                                    
  389.                                     cout << "       -> (";
  390.                                     writeInColor("3", 9);
  391.                                     cout << ") para procurar por idade" << endl << endl;
  392.                                    
  393.                                     cout << "-----------------------------------------------------------------------" << endl << endl;
  394.                                    
  395.                                     cin >> n_action;
  396.                                    
  397.                                     system("CLS");
  398.                                    
  399.                                     switch(n_action)
  400.                                     {
  401.                                         case 1:
  402.                                             lookForName(data.access);
  403.                                             break;
  404.                                         case 2:
  405.                                             lookForJob(data.access);
  406.                                             break;
  407.                                         case 3:
  408.                                             lookForAge(data.access);
  409.                                             break;
  410.                                         default:
  411.                                             cout << " Opção inválida." << endl;
  412.                                             cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  413.                                             _getch();
  414.                                        
  415.                                     }
  416.                                    
  417.                                 }
  418.                                 else if(strcmp(action_cop, "todos") == 0)
  419.                                     showFullRegister(data.access);
  420.                                 else if(strcmp(action_cop, "remover") == 0 && data.access > 9)
  421.                                     executeDeletion(data.access, data.login);
  422.                                 else if(strcmp(action_cop, "voltar") == 0) searching = false;
  423.                             }
  424.                         }
  425.                         else if(strcmp(new_action, "criminoso") == 0)
  426.                         {
  427.                             bool villain = true;
  428.                             char bad_action[10];
  429.                            
  430.                             while(villain)
  431.                             {
  432.                                 system("CLS");
  433.                                
  434.                                 cout << "-----------------------------------------------------------------------" << endl;
  435.                                 cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  436.                        
  437.                                 cout << "       -> {";
  438.                                 writeInColor("registrar", 4);
  439.                                 cout << "} para registrar criminosos no sistema" << endl;
  440.                                
  441.                                 cout << "       -> {";
  442.                                 writeInColor("procurar", 4);
  443.                                 cout << "} para procurar por registro(s) de criminosos no sistema" << endl;
  444.                                
  445.                                 cout << "       -> {";
  446.                                 writeInColor("todos", 4);
  447.                                 cout << "} para ver o registro completo dos criminosos no sistema" << endl;
  448.                                
  449.                                 cout << "       -> {";
  450.                                 writeInColor("atualizar", 4);
  451.                                 cout << "} para atualizar registros de criminosos no sistema" << endl;
  452.                                
  453.                                 cout << "       -> {";
  454.                                 writeInColor("voltar", 9);
  455.                                 cout << "} para voltar ao menu de opcoes" << endl << endl;
  456.                                
  457.                                 cout << "-----------------------------------------------------------------------" << endl << endl;
  458.                                
  459.                                 cin.getline(bad_action, 10);
  460.                                 toLower(bad_action);
  461.                                
  462.                                 system("CLS");
  463.                                
  464.                                 if(strcmp(bad_action, "registrar") == 0)
  465.                                     RegisterVillain();
  466.                                 else if(strcmp(bad_action, "procurar") == 0)
  467.                                 {
  468.                                     bool searching = true;
  469.                                     char action_cop[9];
  470.                                    
  471.                                     while(searching)
  472.                                     {
  473.                                         system("CLS");
  474.                                        
  475.                                         cout << "-----------------------------------------------------------------------" << endl;
  476.                                         cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  477.                                
  478.                                         cout << "       -> (";
  479.                                         writeInColor("ID", 9);
  480.                                         cout << ") para procurar por uma identificao especifica" << endl;
  481.                                         cout << "       -> (";
  482.                                         writeInColor("artigo", 9);
  483.                                         cout << ") para procurar por registro(s) de artigo especifico" << endl;
  484.                                         cout << "       -> (";
  485.                                         writeInColor("estado", 9);
  486.                                         cout << ") para procurar por registro(s) com estado especifico" << endl;
  487.                                         cout << "       -> (";
  488.                                         writeInColor("voltar", 9);
  489.                                         cout << ") para voltar ao menu anterior" << endl;
  490.                                        
  491.                                         cout << "-----------------------------------------------------------------------" << endl << endl;
  492.                                        
  493.                                         cin.getline(action_cop, 9);
  494.                                
  495.                                         toLower(action_cop);
  496.                                        
  497.                                         if(strcmp(action_cop, "id") == 0)
  498.                                             lookForID();
  499.                                         else if(strcmp(action_cop, "artigo") == 0)
  500.                                             lookForArt();
  501.                                         else if(strcmp(action_cop, "estado") == 0)
  502.                                             lookForStatus();
  503.                                         else if(strcmp(action_cop, "voltar") == 0) searching = false;
  504.                                     }
  505.                                    
  506.                                 }
  507.                                 else if(strcmp(bad_action, "atualizar") == 0)
  508.                                 {
  509.                                     bool updating = true;
  510.                                     char action_update[8];
  511.                                    
  512.                                     while(updating)
  513.                                     {
  514.                                         system("CLS");
  515.                                        
  516.                                         cout << "-----------------------------------------------------------------------" << endl;
  517.                                        
  518.                                         cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  519.                                
  520.                                         cout << "       -> (";
  521.                                         writeInColor("status", 9);
  522.                                         cout << ") para atualizar o estado do criminoso." << endl;
  523.                                        
  524.                                         cout << "       -> (";
  525.                                         writeInColor("idade", 9);
  526.                                         cout << ") para atualizar a idade do criminoso." << endl;
  527.                                        
  528.                                         cout << "       -> (";
  529.                                         writeInColor("extra", 9);
  530.                                         cout << ") para atualizar a informacao extra do criminoso." << endl;
  531.                                        
  532.                                         cout << "       -> (";
  533.                                         writeInColor("voltar", 9);
  534.                                         cout << ") para voltar ao menu anterior" << endl;
  535.                                        
  536.                                         cout << "-----------------------------------------------------------------------" << endl << endl;
  537.                                        
  538.                                         cin.getline(action_update, 8);
  539.                                
  540.                                         toLower(action_update);
  541.                                        
  542.                                         system("CLS");
  543.                                        
  544.                                         if(strcmp(action_update, "status") == 0)
  545.                                             updateStatus();
  546.                                         else if(strcmp(action_update, "idade") == 0)
  547.                                             updateAge();
  548.                                         else if(strcmp(action_update, "extra") == 0)
  549.                                             updateExtra();
  550.                                         else if(strcmp(action_update, "voltar") == 0) updating = false;
  551.                                     }
  552.                                 }
  553.                                 else if(strcmp(bad_action, "todos") == 0)
  554.                                     showFullVillainRegister();
  555.                                 else if(strcmp(bad_action, "voltar") == 0) villain = false;
  556.                             }
  557.                         }
  558.                         else if(strcmp(new_action, "pessoal") == 0)
  559.                         {          
  560.                             edit = true;
  561.                             char yourself[8];
  562.                            
  563.                             while(edit)
  564.                             {  
  565.                                 system("CLS");
  566.                                 printInfoAbout(data.login, data.access, true, false);
  567.                                
  568.                                 cout << "-----------------------------------------------------------------------" << endl;
  569.                                
  570.                                 cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  571.                                
  572.                                 cout << "       -> (";
  573.                                 writeInColor("senha", 9);
  574.                                 cout << ") para mudar sua senha" << endl;
  575.                                
  576.                                 cout << "       -> (";
  577.                                 writeInColor("cargo", 9);
  578.                                 cout << ") para alterar seu cargo" << endl;
  579.                                
  580.                                 cout << "       -> (";
  581.                                 writeInColor("data", 9);
  582.                                 cout << ") para atualizar a data de emissão do documento de porte de arma" << endl;
  583.                                
  584.                                 cout << "       -> (";
  585.                                 writeInColor("voltar", 9);
  586.                                 cout << ") para voltar ao menu anterior" << endl;
  587.                                
  588.                                 cout << "-----------------------------------------------------------------------" << endl << endl;
  589.                                
  590.                                 cin.getline(yourself, 8);
  591.                        
  592.                                 toLower(yourself);
  593.                                
  594.                                 system("CLS");
  595.                                
  596.                                 if(strcmp(yourself, "senha") == 0)
  597.                                     changePassword(data.login);
  598.                                 else if(strcmp(yourself, "cargo") == 0)
  599.                                     changeCargo(data.login);
  600.                                 else if(strcmp(yourself, "data") == 0)
  601.                                     changeDate(data.login);
  602.                                 else if(strcmp(yourself, "voltar") == 0) edit = false;
  603.                             }
  604.                         }
  605.                         else if(strcmp(new_action, "pendente") == 0 && data.access > 9)
  606.                         {
  607.                             pendent = true;
  608.                             char pendent_action[7];
  609.                            
  610.                             while(pendent)
  611.                             {  
  612.                                 system("CLS");
  613.                            
  614.                                 cout << "-----------------------------------------------------------------------" << endl;
  615.                                 cout << "          ************* OPÇÕES DE AÇÃO *************" << endl << endl;
  616.                                
  617.                                 cout << "       -> (";
  618.                                 writeInColor("cargo", 9);
  619.                                 cout << ") para aprovar alterações pendentes de cargos" << endl;
  620.                                
  621.                                 cout << "       -> (";
  622.                                 writeInColor("conta", 9);
  623.                                 cout << ") para autorizar novas contas no sistema" << endl;
  624.                            
  625.                                 cout << "       -> (";
  626.                                 writeInColor("voltar", 9);
  627.                                 cout << ") para voltar ao menu anterior" << endl;
  628.                                
  629.                                 cout << "-----------------------------------------------------------------------" << endl << endl;
  630.                            
  631.                                 cin.getline(pendent_action, 7);
  632.                        
  633.                                 toLower(pendent_action);
  634.                                
  635.                                 if(strcmp(pendent_action, "cargo") == 0)
  636.                                 {
  637.                                     int pendent_job = getPendentJobSolicitations();
  638.                                     system("CLS");
  639.                                    
  640.                                     if(pendent_job == 0)
  641.                                     {
  642.                                         cout << "-> Não há solicitações pendentes de mudança de cargo." << endl << endl;
  643.                                         cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  644.                                         _getch();
  645.                                     }
  646.                                     else
  647.                                         showPendentJobs(pendent_job, data.status == 2 ? true : false);
  648.                                    
  649.                                 }
  650.                                 else if(strcmp(pendent_action, "conta") == 0)
  651.                                 {
  652.                                     int pendent_account = getPendentAdmissions();
  653.                                     system("CLS");
  654.                                    
  655.                                     if(pendent_account == 0)
  656.                                     {
  657.                                         cout << "-> Não há contas pendentes para admitir no sistema." << endl << endl;
  658.                                         cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  659.                                         _getch();
  660.                                     }
  661.                                     else
  662.                                         showPendentAccounts(pendent_account, data.status == 2 ? true : false);
  663.                                 }
  664.                                 else if(strcmp(pendent_action, "voltar") == 0) pendent = false;
  665.                             }  
  666.                         }
  667.                         else if(strcmp(new_action, "chave") == 0 && strcmp(data.key, "-1") == 0)
  668.                         {
  669.                             system("CLS");
  670.  
  671.                             generateSecurityKey(data.key);
  672.                            
  673.                             cout << "-> Chave de segurança gerada. Guarde-a em segurança!" << endl;
  674.                             cout << "Sua chave: ";
  675.                             writeInColor(data.key, 9);
  676.                             cout << endl << endl;
  677.                            
  678.                             updateAccount(data.login, 6, data.key, false);
  679.                            
  680.                             cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  681.                             getch();
  682.                         }
  683.                         else if(strcmp(new_action, "sair") == 0) logon = false;
  684.                     }      
  685.                 }      
  686.             }  
  687.         }
  688.         else if(strcmp(action, "recuperar") == 0)
  689.             recoverAccount();
  690.         else if(strcmp(action, "saber") == 0)
  691.         {
  692.             int option;
  693.            
  694.             cout << "O ";
  695.             writeInColor("Sistema de Controle Policial ", 9);
  696.             cout << "é, como o próprio nome sugere, um sistema de controle e manipulação de informações referentes a Polícia Militar." << endl;
  697.             cout << "Através de uma interface simples e prática, é possível, dentre várias funcionalidades:" << endl;
  698.             cout << "  -->  controle da entrada de policiais" << endl;
  699.             cout << "  -->  controle do banco de dados policial" << endl;
  700.             cout << "  -->  controle do banco de dados criminal" << endl;
  701.             cout << "  -->  alterações de cargo, requerindo-se permissão proveniente de patentes maiores" << endl;
  702.             cout << "  -->  avisos antecedentes sobre a data de expiração do documento de porte de armas" << endl << endl;
  703.            
  704.             cout << "Para saber mais sobre a PM e artigos penais, você pode acessar os seguintes links:" << endl;
  705.             cout << "     -> (";
  706.             writeInColor("1", 9);
  707.             cout << ") Polícia Militar de Minas Gerais" << endl;
  708.             cout << "     -> (";
  709.             writeInColor("2", 9);
  710.             cout << ") Código Penal" << endl;
  711.             cout << "     -> (";
  712.             writeInColor("3", 9);
  713.             cout << ") Crime" << endl << endl;
  714.            
  715.             cout << "Se deseja voltar ao menu, entre com qualquer outro dígito." << endl << endl;
  716.            
  717.             cin >> option;
  718.            
  719.             switch(option)
  720.             {
  721.                 case 1:
  722.                     openWebsite("https://www.policiamilitar.mg.gov.br/portal-pm/principal.action");
  723.                     break;
  724.                 case 2:
  725.                     openWebsite("http://www.planalto.gov.br/ccivil_03/decreto-lei/Del2848compilado.htm");
  726.                     break;
  727.                 case 3:
  728.                     openWebsite("https://pt.wikipedia.org/wiki/Crime");
  729.                     break;
  730.             }
  731.         }
  732.         else if(strcmp(action, "sair") == 0) program_running = false;
  733.     }
  734. }
  735.  
  736. bool isInUse(char login[])
  737. {
  738.     file.open("cop_data.txt");
  739.     char line[2000];
  740.  
  741.     while(file.getline(line, 2000))
  742.     {
  743.         int i[getIndexesSize(line, '/')];
  744.         getIndexesBySplittingSentence(line, '/', i);
  745.        
  746.         int login_size = i[3] - i[2] - 1;
  747.         char login_now[login_size];
  748.  
  749.         fillSentence(line, i[2], i[3], login_now);
  750.        
  751.         if(strcmp(login_now, login) == 0)
  752.         {
  753.             file.close();
  754.             return true;
  755.         }
  756.        
  757.     }
  758.            
  759.     file.close();
  760.     return false;
  761. }
  762.  
  763. int getNameOccurrences(char name[])
  764. {
  765.     file.open("cop_data.txt");
  766.     char line[2000];
  767.     int count_name = 0;
  768.  
  769.     while(file.getline(line, 2000))
  770.     {
  771.         int i[getIndexesSize(line, '/')];
  772.         getIndexesBySplittingSentence(line, '/', i);
  773.        
  774.         int name_size = i[1] - i[0] - 1;
  775.         char name_now[name_size];
  776.  
  777.         fillSentence(line, i[0], i[1], name_now);
  778.        
  779.         if(strcmp(name_now, name) == 0) count_name++;
  780.        
  781.     }
  782.        
  783.     file.close();
  784.     return count_name;
  785. }
  786.  
  787. int getAccessLevel(const char * vocation)
  788. {
  789.     char lower[strlen(vocation) + 1];
  790.    
  791.     strcpy(lower, vocation);
  792.     toLower(lower);
  793.    
  794.     if(strcmp(lower, "coronel") == 0)
  795.         return 13;
  796.     else if(strcmp(lower, "tenente-coronel") == 0)
  797.         return 12;
  798.     else if(strcmp(lower, "major") == 0)
  799.         return 11;
  800.     else if(strcmp(lower, "capitao") == 0)
  801.         return 10;
  802.     else if(strcmp(lower, "1 tenente") == 0)
  803.         return 9;
  804.     else if(strcmp(lower, "2 tenente") == 0)
  805.         return 8;
  806.     else if(strcmp(lower, "aspirante a oficial") == 0)
  807.         return 7;
  808.     else if(strcmp(lower, "subtenente") == 0)
  809.         return 6;
  810.     else if(strcmp(lower, "1 sargento") == 0)
  811.         return 5;
  812.     else if(strcmp(lower, "2 sargento") == 0)
  813.         return 4;
  814.     else if(strcmp(lower, "3 sargento") == 0)
  815.         return 3;
  816.     else if(strcmp(lower, "cabo") == 0)
  817.         return 2;
  818.     else if(strcmp(lower, "soldado") == 0)
  819.         return 1;
  820.     else
  821.         return 0;
  822.    
  823. }
  824.  
  825. void correctAndTransferCPF(char CPF[], char old_CPF[])
  826. {
  827.     int count = 0;
  828.  
  829.     for(int i = 0; i < 14; i++)
  830.     {
  831.         if(i == 3 || i == 7)
  832.             CPF[i] = '.';
  833.         else if(i == 11)
  834.             CPF[i] = '-';
  835.         else
  836.             CPF[i] = old_CPF[count++];
  837.     }
  838.    
  839.     CPF[14] = '\0';
  840.    
  841. }
  842.  
  843. void Register::writeIntoFile()
  844. {
  845.     out_file.open("cop_data.txt", ios_base::app | ios_base::out);
  846.    
  847.     out_file << "Nome:/" << this->name << "/";
  848.     out_file << "Login:/" << this->login << "/";
  849.     out_file << "Senha:/" << this->password << "/";
  850.     out_file << "Chave:/" << this->key << "/";
  851.     out_file << "Nascimento:/" << this->d << "-" << this->m << "-" << this->y << "/";
  852.     out_file << "Cargo:/" << this->job << "/";
  853.     out_file << "Data de registro da arma:/" << this->dg << "-" << this->mg << "-" << this->yg << "/";
  854.     out_file << "CPF:/" << this->CPF << "/";
  855.     out_file << "Status:/" << this->status << "/" << endl;
  856.    
  857.     out_file.close();
  858. }
  859.  
  860. int getFileLineCount(const char* file_name)
  861. {
  862.     file.open(file_name);
  863.     int count = 0;
  864.     char line[2000];
  865.    
  866.     while(file.getline(line, 2000)) count++;
  867.     file.close();
  868.    
  869.     return count;
  870. }
  871.  
  872. bool compareTwoStrings(char str1[], char str2[])
  873. {
  874.     char cpystr1[strlen(str1) + 1], cpystr2[strlen(str2) + 1];
  875.    
  876.     strcpy(cpystr1, str1);
  877.     strcpy(cpystr2, str2);
  878.    
  879.     toLower(cpystr1);
  880.     toLower(cpystr2);
  881.    
  882.     return strcmp(cpystr1, cpystr2) < 0 ? false : true;
  883. }
  884.  
  885. void lookForName(int access)
  886. {
  887.     cin.ignore();
  888.     char name[1000];
  889.                                    
  890.     system("CLS");
  891.     cout << "-> Digite o nome do policial." << endl << endl;
  892.    
  893.     cout << " Nome: ";
  894.     cin.getline(name, 1000);
  895.    
  896.     adjustName(name);
  897.    
  898.     int occurrences = getNameOccurrences(name);
  899.    
  900.     system("CLS");
  901.    
  902.     if(occurrences == 0)
  903.     {
  904.         cout << "Este nome não está registrado no sistema." << endl << endl;
  905.         cout << "Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  906.         _getch();
  907.     }
  908.     else
  909.     {
  910.         char n[10];
  911.        
  912.         itoa(occurrences, n, 10);
  913.        
  914.         cout << "Há (";
  915.         writeInColor(n, 9);
  916.         cout << ") ocorrência(s) deste nome no sistema" << endl << endl;
  917.         showInfosAboutName(name, access);
  918.         cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  919.         _getch();
  920.        
  921.     }
  922. }
  923.  
  924. void printByBadArray(int ID[], int count)
  925. {
  926.     int tmp;
  927.    
  928.     for(int i = 0; i < count; i++)
  929.     {
  930.         for(int j = 0; j < count; j++)
  931.         {
  932.             Villain cmp1 = getVillainInfo(ID[i]), cmp2 = getVillainInfo(ID[j]);
  933.    
  934.             if(!compareTwoStrings(cmp1.name, cmp2.name))
  935.             {
  936.                 tmp = ID[j];
  937.                 ID[j] = ID[i];
  938.                 ID[i] = tmp;
  939.             }
  940.         }
  941.     }
  942.    
  943.     for(int i = 0; i < count; i++)
  944.         printBadInfoAbout(ID[i]);
  945.    
  946. }
  947.  
  948. void printByArray(char *array[], int count, int access, bool show_new_job)
  949. {
  950.     char tmp[13];
  951.    
  952.     for(int i = 0; i < count; i++)
  953.     {
  954.         for(int j = 0; j < count; j++)
  955.         {
  956.             Cop cmp1 = getAccountInfo(array[i]), cmp2 = getAccountInfo(array[j]);
  957.            
  958.             if(!compareTwoStrings(cmp1.name, cmp2.name))
  959.             {
  960.                 strcpy(tmp, array[j]);
  961.                 strcpy(array[j], array[i]);
  962.                 strcpy(array[i], tmp);
  963.             }
  964.         }
  965.     }
  966.    
  967.     for(int i = 0; i < count; i++)
  968.     {
  969.         printInfoAbout(array[i], access, false, show_new_job);
  970.         delete array[i];
  971.     }
  972. }
  973.  
  974. void lookForJob(int access)
  975. {
  976.     cin.ignore();
  977.     char job[100];
  978.     bool check_job = false;
  979.     int count = 0;
  980.                                    
  981.     system("CLS");
  982.     cout << "-> Digite o cargo." << endl << endl;
  983.    
  984.     do
  985.     {
  986.         if(check_job)
  987.             cout << "Cargo invalido." << endl << endl;
  988.        
  989.         cout << " Cargo: ";
  990.         cin.getline(job, 100);
  991.         adjustName(job);
  992.         check_job = true;
  993.         system("CLS");
  994.     } while(getAccessLevel(job) == 0);
  995.    
  996.     ifstream tmp("cop_data.txt");
  997.     char line[2000], *login[getFileLineCount("cop_data.txt")];
  998.    
  999.     while(tmp.getline(line, 2000))
  1000.     {
  1001.         int i[getIndexesSize(line, '/')];
  1002.         getIndexesBySplittingSentence(line, '/', i);
  1003.        
  1004.         int job_size = i[11] - i[10] - 1;
  1005.         char job_now[job_size];
  1006.  
  1007.         fillSentence(line, i[10], i[11], job_now);
  1008.        
  1009.         char job_cmp[100];
  1010.        
  1011.         if(strchr(job_now, ':') != NULL)
  1012.         {
  1013.             int k[getIndexesSize(job_now, ':')];
  1014.             getIndexesBySplittingSentence(job_now, ':', k);
  1015.            
  1016.             int now_job = k[1] - k[0] - 1;
  1017.             char tmp_job[now_job];
  1018.            
  1019.             fillSentence(job_now, k[0], k[1], tmp_job);
  1020.             strcpy(job_cmp, tmp_job);
  1021.         }
  1022.         else
  1023.             strcpy(job_cmp, job_now);
  1024.        
  1025.         if(strcmp(job, job_cmp) == 0)
  1026.         {
  1027.             int login_size = i[3] - i[2] - 1;
  1028.             char login_now[login_size];
  1029.    
  1030.             fillSentence(line, i[2], i[3], login_now);
  1031.            
  1032.             login[count] = new char[login_size];
  1033.             strcpy(login[count], login_now);   
  1034.             count++;
  1035.         }
  1036.     }
  1037.    
  1038.     tmp.close();
  1039.  
  1040.     if(count == 0)
  1041.         cout << "Não há registro de policiais com este cargo." << endl << endl;
  1042.     else
  1043.     {
  1044.         char n[10];
  1045.        
  1046.         itoa(count, n, 10);
  1047.        
  1048.         cout << "Há (";
  1049.         writeInColor(n, 9);
  1050.         cout << ") ocorrência(s) com este cargo no sistema" << endl << endl;
  1051.        
  1052.         printByArray(login, count, access, false);
  1053.     }
  1054.    
  1055.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  1056.     _getch();
  1057. }
  1058.  
  1059. void lookForArt()
  1060. {
  1061.     bool check_art = false;
  1062.     int count = 0;
  1063.     char art[6];
  1064.    
  1065.     system("CLS");
  1066.     cout << "-> Digite o artigo." << endl;
  1067.    
  1068.     do
  1069.     {
  1070.         writeColorInfo("33");
  1071.         cout << " - Tráfico de drogas" << endl;
  1072.         writeColorInfo("121");
  1073.         cout << " - Homicídio" << endl;
  1074.         writeColorInfo("129");
  1075.         cout << " - Lesão Corporal" << endl;
  1076.         writeColorInfo("155");
  1077.         cout << " - Furto" << endl;
  1078.         writeColorInfo("157");
  1079.         cout << " - Roubo ou Latrocínio" << endl;
  1080.         writeColorInfo("158");
  1081.         cout << " - Extorsão" << endl;
  1082.         writeColorInfo("171");
  1083.         cout << " - Fraude ou Estelionato" << endl;
  1084.         writeColorInfo("213");
  1085.         cout << " - Estupro" << endl;
  1086.         writeColorInfo("216");
  1087.         cout << " - Assédio Sexual" << endl;
  1088.         writeColorInfo("250");
  1089.         cout << " - Incêndio" << endl;
  1090.         writeColorInfo("256");
  1091.         cout << " - Desmoronamento/desabamento" << endl;
  1092.         writeColorInfo("outro");
  1093.         cout << " - Outro" << endl << endl;
  1094.        
  1095.         if(check_art)
  1096.             cout << "Artigo inválido." << endl << endl;
  1097.        
  1098.         writeInColor(" Artigo", 9);
  1099.         cout << ": ";
  1100.         cin.getline(art, 6);
  1101.         check_art = true;
  1102.         system("CLS");
  1103.     } while(!isStringValid(art, CONST_ART_CHECK));
  1104.    
  1105.     ifstream file_now("bad_data.txt");
  1106.     int ID[getFileLineCount("bad_data.txt")];
  1107.     char line[2000];
  1108.    
  1109.     while(file_now.getline(line, 2000))
  1110.     {
  1111.         int i[getIndexesSize(line, '/')];
  1112.         getIndexesBySplittingSentence(line, '/', i);
  1113.        
  1114.         int art_size = i[9] - i[8] - 1;
  1115.         char art_now[art_size];
  1116.        
  1117.         fillSentence(line, i[8], i[9], art_now);
  1118.        
  1119.         if(strcmp(art_now, art) == 0)
  1120.         {
  1121.             int ID_size = i[1] - i[0] - 1;
  1122.             char ID_now[ID_size];
  1123.    
  1124.             fillSentence(line, i[0], i[1], ID_now);
  1125.            
  1126.             ID[count] = atoi(ID_now);
  1127.             count++;
  1128.         }
  1129.     }
  1130.    
  1131.     file_now.close();
  1132.    
  1133.     if(count == 0)
  1134.         cout << "Não há registro de criminosos com este artigo." << endl << endl;
  1135.     else
  1136.     {
  1137.         int resp;
  1138.        
  1139.         char n[3];
  1140.        
  1141.         itoa(count, n, 10);
  1142.         cout << "  (";
  1143.         writeInColor(n, 9);
  1144.         cout << ") ocorrência(s) com este artigo." << endl << endl;
  1145.        
  1146.         printByBadArray(ID, count);
  1147.        
  1148.         if(strcmp(art, "outro") != 0)
  1149.         {
  1150.             cout << " Deseja saber mais sobre tal artigo?" << endl;
  1151.             resp = getYesOrNo();
  1152.            
  1153.             if(resp == 0)
  1154.                 getArt(atoi(art), true);
  1155.         }
  1156.     }
  1157.    
  1158.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  1159.     _getch();
  1160. }
  1161.        
  1162. void lookForStatus()   
  1163. {
  1164.     bool check_status = false;
  1165.     int input_status, count = 0;
  1166.                                    
  1167.     system("CLS");
  1168.     cout << "-> Digite o estado." << endl;
  1169.     writeColorInfo("0");
  1170.     cout << " - Preso" << endl;
  1171.     writeColorInfo("1");
  1172.     cout << " - Foragido" << endl;
  1173.     writeColorInfo("2");
  1174.     cout << " - Livre" << endl;
  1175.     writeColorInfo("3");
  1176.     cout << " - Condicional" << endl;
  1177.     writeColorInfo("4");
  1178.     cout << " - Morto" << endl << endl;
  1179.    
  1180.     do
  1181.     {
  1182.         if(check_status)
  1183.             cout << "Estado inválido." << endl << endl;
  1184.        
  1185.         writeInColor(" Status", 9);
  1186.         cout << ": ";
  1187.         cin >> input_status;
  1188.         check_status = true;
  1189.         system("CLS");
  1190.     } while(input_status < 0 || input_status > 4);
  1191.    
  1192.     ifstream file_now("bad_data.txt");
  1193.     int ID[getFileLineCount("bad_data.txt")];
  1194.     char line[2000];
  1195.    
  1196.     while(file_now.getline(line, 2000))
  1197.     {
  1198.         int i[getIndexesSize(line, '/')];
  1199.         getIndexesBySplittingSentence(line, '/', i);
  1200.        
  1201.         int stat_size = i[13] - i[12] - 1;
  1202.         char status_now[stat_size];
  1203.        
  1204.         fillSentence(line, i[12], i[13], status_now);
  1205.        
  1206.         if(atoi(status_now) == input_status)
  1207.         {
  1208.             int ID_size = i[1] - i[0] - 1;
  1209.             char ID_now[ID_size];
  1210.    
  1211.             fillSentence(line, i[0], i[1], ID_now);
  1212.            
  1213.             ID[count] = atoi(ID_now);
  1214.             count++;
  1215.         }
  1216.     }  
  1217.    
  1218.     file_now.close();
  1219.    
  1220.     if(count == 0)
  1221.         cout << "Não há registro de criminosos neste estado." << endl << endl;
  1222.     else
  1223.     {
  1224.         char n[3];
  1225.        
  1226.         itoa(count, n, 10);
  1227.         cout << "  (";
  1228.         writeInColor(n, 9);
  1229.         cout << ") ocorrência(s) com este estado." << endl << endl;
  1230.        
  1231.         printByBadArray(ID, count);
  1232.     }
  1233.    
  1234.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  1235.     _getch();
  1236. }
  1237.  
  1238. void lookForID()
  1239. {
  1240.     bool check_ID = false, found_ID = false;
  1241.     int input_ID;
  1242.                                    
  1243.     system("CLS");
  1244.     cout << "-> Digite a identificação." << endl << endl;
  1245.    
  1246.     do
  1247.     {
  1248.         if(check_ID)
  1249.             cout << "Identificação inválida." << endl << endl;
  1250.        
  1251.         writeInColor(" ID", 9);
  1252.         cout << ": ";
  1253.         cin >> input_ID;
  1254.         check_ID = true;
  1255.         system("CLS");
  1256.     } while(input_ID <= 0);
  1257.    
  1258.     ifstream file_now("bad_data.txt");
  1259.     char line[2000];
  1260.    
  1261.     while(file_now.getline(line, 2000))
  1262.     {
  1263.         int i[getIndexesSize(line, '/')];
  1264.         getIndexesBySplittingSentence(line, '/', i);
  1265.        
  1266.         int ID_size = i[1] - i[0] - 1, cmp_ID;
  1267.         char ID_now[ID_size];
  1268.  
  1269.         fillSentence(line, i[0], i[1], ID_now);
  1270.        
  1271.         cmp_ID = atoi(ID_now);
  1272.    
  1273.         if(cmp_ID == input_ID)
  1274.         {
  1275.             printBadInfoAbout(input_ID);
  1276.             found_ID = true;
  1277.             break;
  1278.         }
  1279.     }
  1280.    
  1281.     file_now.close();
  1282.    
  1283.     if(!found_ID)
  1284.         cout << "Não foi encontrado nenhum registro com esta identificação." << endl << endl;
  1285.  
  1286.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  1287.     _getch();  
  1288. }
  1289.  
  1290. void lookForAge(int access)
  1291. {
  1292.     bool check_age = false;
  1293.     int age, count = 0;
  1294.                                    
  1295.     system("CLS");
  1296.     cout << "-> Digite a idade." << endl << endl;
  1297.    
  1298.     do
  1299.     {
  1300.         if(check_age)
  1301.             cout << "Idade inválida." << endl << endl;
  1302.        
  1303.         cout << " Idade: ";
  1304.         cin >> age;
  1305.         check_age = true;
  1306.         system("CLS");
  1307.     } while(age <= 0);
  1308.    
  1309.     ifstream tmp("cop_data.txt");
  1310.     char line[2000], *login[getFileLineCount("cop_data.txt")]; 
  1311.    
  1312.     Cop get_info;
  1313.    
  1314.     while(tmp.getline(line, 2000))
  1315.     {
  1316.         int i[getIndexesSize(line, '/')];
  1317.         getIndexesBySplittingSentence(line, '/', i);
  1318.        
  1319.         int login_size = i[3] - i[2] - 1;
  1320.         char login_now[login_size];
  1321.  
  1322.         fillSentence(line, i[2], i[3], login_now);
  1323.        
  1324.         get_info = getAccountInfo(login_now);
  1325.        
  1326.         if(get_info.age == age)
  1327.         {
  1328.             login[count] = new char[login_size];
  1329.             strcpy(login[count], login_now);   
  1330.             count++;
  1331.         }
  1332.     }
  1333.        
  1334.     tmp.close();
  1335.    
  1336.     if(count == 0)
  1337.         cout << "Não há registro de policiais com esta idade." << endl << endl;
  1338.     else
  1339.     {
  1340.         char n[10];
  1341.        
  1342.         itoa(count, n, 10);
  1343.        
  1344.         cout << "Há (";
  1345.         writeInColor(n, 9);
  1346.         cout << ") ocorrência(s) com esta idade no sistema" << endl << endl;
  1347.        
  1348.         printByArray(login, count, access, false);
  1349.     }
  1350.    
  1351.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  1352.     _getch();
  1353. }
  1354.  
  1355. void showInfosAboutName(char name[], int access)
  1356. {
  1357.     file.open("cop_data.txt");
  1358.     char line[2000];
  1359.    
  1360.     while(file.getline(line, 2000))
  1361.     {
  1362.         int i[getIndexesSize(line, '/')];
  1363.         getIndexesBySplittingSentence(line, '/', i);
  1364.        
  1365.         int name_size = i[1] - i[0] - 1;
  1366.         char name_now[name_size];
  1367.  
  1368.         fillSentence(line, i[0], i[1], name_now);
  1369.        
  1370.         if(strcmp(name_now, name) == 0)
  1371.         {  
  1372.             int login_size = i[3] - i[2] - 1;
  1373.             char login[login_size];
  1374.            
  1375.             fillSentence(line, i[2], i[3], login);
  1376.            
  1377.             Cop info = getAccountInfo(login);
  1378.                
  1379.             cout << "  -> Nome: " << info.name << endl;
  1380.            
  1381.             if(access > 9)
  1382.                 cout << "  -> Login: " << login << endl;
  1383.            
  1384.             cout << "  -> Idade: " << info.age << endl;
  1385.            
  1386.             char job_cmp[100];
  1387.            
  1388.             if(strchr(info.job, ':') != NULL)
  1389.             {
  1390.                 int k[getIndexesSize(info.job, ':')];
  1391.                 getIndexesBySplittingSentence(info.job, ':', k);
  1392.                
  1393.                 int now_job = k[1] - k[0] - 1;
  1394.                 char tmp_job[now_job];
  1395.                
  1396.                 fillSentence(info.job, k[0], k[1], tmp_job);
  1397.                 strcpy(job_cmp, tmp_job);
  1398.             }
  1399.             else
  1400.                 strcpy(job_cmp, info.job);
  1401.                
  1402.             cout << "  -> Cargo: " << job_cmp << endl;
  1403.             cout << "  -> Data de nascimento: " << info.birth_date << endl;
  1404.             cout << "  -> Data de registro da arma: " << info.gun << endl << endl;
  1405.         }
  1406.        
  1407.     }
  1408.        
  1409.     file.close();
  1410.    
  1411. }
  1412.  
  1413. int getYesOrNo()
  1414. {
  1415.     int ret;
  1416.    
  1417.     cout << "  (";
  1418.     writeInColor("0", 9);
  1419.     cout << ") - sim" << endl;
  1420.     cout << "  (";
  1421.     writeInColor("1", 9);
  1422.     cout << ") - nao" << endl;
  1423.    
  1424.     do
  1425.     {
  1426.         cin >> ret;
  1427.         system("CLS");
  1428.     } while(ret != 0 && ret != 1);
  1429.    
  1430.     return ret;
  1431. }
  1432.  
  1433. void writeColorInfo(const char* art)
  1434. {
  1435.     cout << "    (";
  1436.     writeInColor(art, 4);
  1437.     cout << ")";
  1438. }
  1439.  
  1440. bool isStringValid(char str[], int check_type) 
  1441. {
  1442.     if(check_type == CONST_NAME_CHECK)
  1443.     {
  1444.         bool check_name_logic = false;
  1445.        
  1446.         if(strlen(str) < 5)
  1447.         {
  1448.             cout << "-> Nome muito curto!" << endl;
  1449.             return false;
  1450.         }
  1451.        
  1452.         for(unsigned int i = 0; i < strlen(str); i++)
  1453.         {
  1454.             if(isalpha(str[i]))
  1455.                 check_name_logic = true;
  1456.             else if(!isspace(str[i])) return false;
  1457.         }
  1458.        
  1459.         if(!check_name_logic) return false;
  1460.     }
  1461.     else if(check_type == CONST_ART_CHECK)
  1462.     {
  1463.         int arts[] = {33, 121, 129, 155, 157, 158, 171, 213, 216, 250, 256};
  1464.         bool check_str = false;
  1465.        
  1466.         for(unsigned int i = 0; i < strlen(str); i++)
  1467.             if(!isdigit(str[i]))
  1468.             {
  1469.                 check_str = true;
  1470.                 break;
  1471.             }
  1472.        
  1473.         if(check_str)
  1474.             return strcmp(str, "outro") == 0 ? true : false;
  1475.         else
  1476.         {
  1477.             for(unsigned int i = 0; i < sizeof(arts); i++)
  1478.                 if(arts[i] == atoi(str))
  1479.                     return true;
  1480.                
  1481.             return false;
  1482.         }
  1483.     }
  1484.     else if(check_type == CONST_SPECIFIC_CHECK)
  1485.     {
  1486.         bool check_name_logic = false;
  1487.        
  1488.         for(unsigned int i = 0; i < strlen(str); i++)
  1489.         {
  1490.             if(isalnum(str[i]))
  1491.                 check_name_logic = true;
  1492.             else
  1493.             {
  1494.                 if(!isspace(str[i]) && str[i] != '.' && str[i] != ',' && str[i] != ';') return false;
  1495.             }
  1496.         }
  1497.        
  1498.         if(!check_name_logic) return false;
  1499.        
  1500.     }
  1501.     else if(check_type == CONST_CPF_CHECK)
  1502.     {
  1503.         if(strlen(str) != 11) return false;
  1504.        
  1505.         for(unsigned int i = 0; i < strlen(str); i++)
  1506.             if(!isdigit(str[i]))
  1507.                 return false;
  1508.     }  
  1509.     else
  1510.     {
  1511.         unsigned int max = check_type == CONST_LOGIN_CHECK ? 12 : 10;
  1512.    
  1513.         if(strlen(str) < 4 || strlen(str) > max) return false;
  1514.        
  1515.         for(unsigned int i = 0; i < strlen(str); i++)
  1516.             if(!isalpha(str[i]) && !isdigit(str[i]))
  1517.                 return false;
  1518.     }
  1519.        
  1520.     return true;
  1521. }
  1522.  
  1523. void RegisterVillain()
  1524. {
  1525.     Villain info;
  1526.    
  1527.     cout << "              Muito bem, comecemos o registro do criminoso em questão." << endl << endl;
  1528.    
  1529.     cout << "-> O nome é conhecido?" << endl;
  1530.    
  1531.     int OP = getYesOrNo();
  1532.    
  1533.     if(OP == 1)
  1534.         strcpy(info.name, "-1");
  1535.     else
  1536.     {
  1537.         int resp;
  1538.    
  1539.         do
  1540.         {
  1541.             cin.ignore();
  1542.             bool check_name = true;
  1543.            
  1544.             do
  1545.             {
  1546.                 if(!check_name)
  1547.                     cout << "Nome inválido. Por gentileza, reentre com o dado correto." << endl << endl;
  1548.                
  1549.                 writeInColor(" Nome completo", 4);
  1550.                 cout << ": ";
  1551.                
  1552.                 cin.getline(info.name, 1000);
  1553.                 check_name = false;
  1554.                 system("CLS");
  1555.             } while(!isStringValid(info.name, CONST_NAME_CHECK));
  1556.            
  1557.             adjustName(info.name);
  1558.            
  1559.             cout << "-> Nome registrado: " << info.name << endl << endl;
  1560.             cout << "Este nome está correto?" << endl;
  1561.             resp = getYesOrNo();
  1562.             system("CLS");
  1563.            
  1564.         } while(resp == 1);
  1565.     }
  1566.    
  1567.     if(strcmp(info.name, "-1") != 0)
  1568.         cout << "-> " << info.name << " possui um apelido?" << endl << endl;
  1569.     else
  1570.         cout << "-> Este criminoso possui um apelido?" << endl << endl;
  1571.    
  1572.     OP = getYesOrNo();
  1573.    
  1574.     if(OP == 1)
  1575.         strcpy(info.nickname, "-1");
  1576.     else
  1577.     {
  1578.         int resp;
  1579.        
  1580.         do
  1581.         {
  1582.             cin.ignore();
  1583.             bool check_nick = true;
  1584.            
  1585.             do
  1586.             {
  1587.                 if(!check_nick)
  1588.                     cout << "Apelido inválido. Por gentileza, reentre com o dado correto." << endl << endl;
  1589.                
  1590.                 writeInColor(" Apelido", 4);
  1591.                 cout << ": ";
  1592.                
  1593.                 cin.getline(info.nickname, 1000);
  1594.                 check_nick = false;
  1595.                 system("CLS");
  1596.             } while(!isStringValid(info.nickname, CONST_NAME_CHECK));
  1597.            
  1598.             adjustName(info.nickname);
  1599.            
  1600.             cout << "-> Apelido registrado: " << info.nickname << endl << endl;
  1601.             cout << "Este apelido está correto?" << endl;
  1602.             resp = getYesOrNo();
  1603.             system("CLS");
  1604.            
  1605.         } while(resp == 1);
  1606.     }
  1607.    
  1608.     cout << "-> Há alguma ideia quanto a idade deste criminoso?" << endl;
  1609.  
  1610.     OP = getYesOrNo();
  1611.    
  1612.     if(OP == 1)
  1613.         info.age = -1;
  1614.     else
  1615.     {
  1616.         int resp;
  1617.    
  1618.         do
  1619.         {
  1620.             bool check_age = true;
  1621.            
  1622.             do
  1623.             {
  1624.                 if(!check_age)
  1625.                     cout << "Idade inválida. Por gentileza, reentre com o dado correto." << endl << endl;
  1626.                
  1627.                 writeInColor(" Idade", 4);
  1628.                 cout << ": ";
  1629.                
  1630.                 cin >> info.age;
  1631.                 check_age = false;
  1632.                 system("CLS");
  1633.             } while(info.age <= 0);
  1634.            
  1635.             cout << "-> Idade registrada: " << info.age << endl << endl;
  1636.             cout << "Esta idade está correta?" << endl;
  1637.             resp = getYesOrNo();
  1638.             system("CLS");
  1639.            
  1640.         } while(resp == 1);
  1641.     }
  1642.    
  1643.     cout << "-> Qual artigo mais se encaixa no crime?" << endl;
  1644.    
  1645.     int resp;
  1646.    
  1647.     do
  1648.     {
  1649.         bool check_art = true;
  1650.        
  1651.         cin.ignore();
  1652.        
  1653.         do
  1654.         {
  1655.             writeColorInfo("33");
  1656.             cout << " - Tráfico de drogas" << endl;
  1657.             writeColorInfo("121");
  1658.             cout << " - Homicídio" << endl;
  1659.             writeColorInfo("129");
  1660.             cout << " - Lesão Corporal" << endl;
  1661.             writeColorInfo("155");
  1662.             cout << " - Furto" << endl;
  1663.             writeColorInfo("157");
  1664.             cout << " - Roubo ou Latrocínio" << endl;
  1665.             writeColorInfo("158");
  1666.             cout << " - Extorsão" << endl;
  1667.             writeColorInfo("171");
  1668.             cout << " - Fraude ou Estelionato" << endl;
  1669.             writeColorInfo("213");
  1670.             cout << " - Estupro" << endl;
  1671.             writeColorInfo("216");
  1672.             cout << " - Assédio Sexual" << endl;
  1673.             writeColorInfo("250");
  1674.             cout << " - Incêndio" << endl;
  1675.             writeColorInfo("256");
  1676.             cout << " - Desmoronamento/desabamento" << endl;
  1677.             writeColorInfo("outro");
  1678.             cout << " - Outro" << endl << endl;
  1679.            
  1680.             if(!check_art)
  1681.                 cout << "Artigo inválido. Por gentileza, reentre com o dado correto." << endl << endl;
  1682.                
  1683.             writeInColor(" Artigo", 4);
  1684.             cout << ": ";
  1685.            
  1686.             cin.getline(info.art, 6);
  1687.             check_art = false;
  1688.             system("CLS");
  1689.         } while(!isStringValid(info.art, CONST_ART_CHECK));
  1690.        
  1691.         cout << "-> Artigo registrado: ";
  1692.         getArt(atoi(info.art), false);
  1693.         cout << "." << endl << endl;
  1694.         cout << "Este artigo está correto?" << endl;
  1695.         resp = getYesOrNo();
  1696.         system("CLS");
  1697.        
  1698.     } while(resp == 1);
  1699.    
  1700.     if(strcmp(info.art, "outro") != 0)
  1701.         strcpy(info.specific, "no_specific");
  1702.     else
  1703.     {
  1704.         int resp;
  1705.         cout << "-> Especifique o crime." << endl;
  1706.        
  1707.         do
  1708.         {
  1709.             cin.ignore();
  1710.             bool check_specific = true;
  1711.        
  1712.             cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
  1713.            
  1714.             do
  1715.             {
  1716.                 if(!check_specific)
  1717.                     cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
  1718.                
  1719.                 writeInColor(" Especificação", 4);
  1720.                 cout << ": ";
  1721.                
  1722.                 cin.getline(info.specific, 51);
  1723.                 check_specific = false;
  1724.                 system("CLS");
  1725.             } while(!isStringValid(info.specific, CONST_SPECIFIC_CHECK));
  1726.            
  1727.             cout << "-> Informação registrada: " << info.specific << endl << endl;
  1728.             cout << "Esta informação está correta?" << endl;
  1729.             resp = getYesOrNo();
  1730.             system("CLS");
  1731.            
  1732.         } while(resp == 1);
  1733.        
  1734.     }
  1735.    
  1736.     cout << "Qual a situação atual deste criminoso?" << endl;
  1737.    
  1738.     do
  1739.     {
  1740.         bool check_status = true;
  1741.        
  1742.         do
  1743.         {
  1744.             writeColorInfo("0");
  1745.             cout << " - Preso" << endl;
  1746.             writeColorInfo("1");
  1747.             cout << " - Foragido" << endl;
  1748.             writeColorInfo("2");
  1749.             cout << " - Livre" << endl;
  1750.             writeColorInfo("3");
  1751.             cout << " - Condicional" << endl;
  1752.             writeColorInfo("4");
  1753.             cout << " - Morto" << endl << endl;
  1754.            
  1755.             if(!check_status)
  1756.                 cout << "Estado inválido. Por favor, reentre com esta informação." << endl << endl;
  1757.            
  1758.             writeInColor(" Estado", 4);
  1759.             cout << ": ";
  1760.            
  1761.             cin >> info.status;
  1762.             check_status = false;
  1763.             system("CLS");
  1764.         } while(info.status < 0 || info.status > 4);
  1765.        
  1766.         cout << "-> Estado registrado: ";
  1767.        
  1768.         switch(info.status)
  1769.         {
  1770.             case 0:
  1771.                 cout << "preso." << endl << endl;
  1772.                 break;
  1773.             case 1:
  1774.                 cout << "foragido." << endl << endl;
  1775.                 break;
  1776.             case 2:
  1777.                 cout << "livre." << endl << endl;
  1778.                 break;
  1779.             case 3:
  1780.                 cout << "em condicional." << endl << endl;
  1781.                 break;
  1782.             case 4:
  1783.                 cout << "falecido." << endl << endl;
  1784.                 break;
  1785.         }
  1786.        
  1787.         cout << "Este estado está correto?" << endl;
  1788.         resp = getYesOrNo();
  1789.         system("CLS");
  1790.        
  1791.     } while(resp == 1);
  1792.    
  1793.     if(info.status == 0 || info.status == 3)
  1794.     {
  1795.         cout << "-> Qual a identificação do prisioneiro?" << endl << endl;
  1796.        
  1797.         int resp;
  1798.    
  1799.         do
  1800.         {
  1801.             bool check_ID = true;
  1802.            
  1803.             do
  1804.             {
  1805.                 if(!check_ID)
  1806.                     cout << "Identifição inválida ou repetida. Por favor, reentre com esta informação." << endl << endl;
  1807.                
  1808.                 writeInColor(" ID", 4);
  1809.                 cout << ": ";
  1810.                
  1811.                 cin >> info.ID;
  1812.                 check_ID = false;
  1813.                 system("CLS");
  1814.             } while(info.ID <= 0 || !isIDValid(info.ID));
  1815.            
  1816.             cout << "-> Identifição registrada: " << info.ID << endl << endl;
  1817.             cout << "Esta identificação está correta?" << endl;
  1818.             resp = getYesOrNo();
  1819.             system("CLS");
  1820.            
  1821.         } while(resp == 1);
  1822.     }
  1823.     else
  1824.     {
  1825.         info.ID = -(getFileLineCount("bad_data.txt"));
  1826.        
  1827.         while(!isIDValid(info.ID))
  1828.             info.ID--;
  1829.     }
  1830.    
  1831.     cout << "-> Deseja acrescentar alguma informação extra?" << endl;
  1832.    
  1833.     OP = getYesOrNo();
  1834.    
  1835.     if(OP == 1)
  1836.         strcpy(info.extra, "Nada a acrescentar.");
  1837.     else
  1838.     {
  1839.         int resp;
  1840.        
  1841.         do
  1842.         {
  1843.             cin.ignore();
  1844.             bool check_extra = true;
  1845.        
  1846.             cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
  1847.            
  1848.             do
  1849.             {
  1850.                 if(!check_extra)
  1851.                     cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
  1852.                
  1853.                 writeInColor(" Extra", 4);
  1854.                 cout << ": ";
  1855.                
  1856.                 cin.getline(info.extra, 51);
  1857.                 check_extra = false;
  1858.                 system("CLS");
  1859.             } while(!isStringValid(info.extra, CONST_SPECIFIC_CHECK));
  1860.            
  1861.             cout << "-> Informação extra registrada: " << info.extra << endl << endl;
  1862.             cout << "Esta informação está correta?" << endl;
  1863.             resp = getYesOrNo();
  1864.         } while(resp == 1);
  1865.     }
  1866.    
  1867.     info.writeIntoBadFile();
  1868.     cout << "  -> Registro completo!" << endl << endl;
  1869.     cout << "As informações deste criminoso foram armazenadas com sucesso no sistema." << endl;
  1870.     cout << "Pressione qualquer tecla para continuar." << endl;
  1871.     getch();
  1872.     system("CLS");
  1873. }
  1874.  
  1875. void Villain::writeIntoBadFile()
  1876. {
  1877.     out_file.open("bad_data.txt", ios_base::app | ios_base::out);
  1878.    
  1879.     out_file << "ID:/" << this->ID << "/";
  1880.     out_file << "Nome:/" << this->name << "/";
  1881.     out_file << "Apelido:/" << this->nickname << "/";
  1882.     out_file << "Idade:/" << this->age << "/";
  1883.     out_file << "Artigo:/" << this->art << "/";
  1884.     out_file << "Outro:/" << this->specific << "/";
  1885.     out_file << "Status:/" << this->status << "/";
  1886.     out_file << "Extra:/" << this->extra << "/" << endl;
  1887.    
  1888.     out_file.close();
  1889. }
  1890.  
  1891. void RegisterCop()
  1892. {
  1893.     Register info;
  1894.            
  1895.     cout << "              Muito bem, comecemos o processo de registro de conta." << endl << endl;
  1896.    
  1897.     cout << "-> Primeiramente, entre com o login que deseja utilizar." << endl;
  1898.     cout << "MIN. 4 MÁX. 12 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
  1899.    
  1900.     bool check_login = true;
  1901.    
  1902.     char login[13];
  1903.    
  1904.     do
  1905.     {
  1906.         if(!check_login)
  1907.         {
  1908.             cout << "Login inválido." << endl;
  1909.             cout << "MIN. 4 MÁX. 12 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
  1910.         }
  1911.        
  1912.         writeInColor(" Login", 9);
  1913.         cout << ": ";
  1914.        
  1915.         cin >> login;
  1916.         strcpy(info.login, login);
  1917.         check_login = false;
  1918.         system("CLS");
  1919.        
  1920.         while(isInUse(login))
  1921.         {
  1922.             cout << "Login em uso! Escolha outro, por gentileza." << endl;
  1923.            
  1924.             writeInColor(" Login", 9);
  1925.             cout << ": ";
  1926.            
  1927.             cin >> login;
  1928.             strcpy(info.login, login);
  1929.             system("CLS");
  1930.         }
  1931.        
  1932.     } while(!isStringValid(info.login, CONST_LOGIN_CHECK));
  1933.    
  1934.     cout << "-> Passemos agora para a senha." << endl;
  1935.     cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
  1936.    
  1937.     bool same_passwords = true;
  1938.    
  1939.     do
  1940.     {
  1941.         if(!same_passwords)
  1942.             cout << "Senhas diferentes. Por favor, reentre com este dado." << endl << endl;
  1943.        
  1944.        
  1945.         bool check_password = true;
  1946.    
  1947.         do
  1948.         {
  1949.             if(!check_password)
  1950.             {
  1951.                 cout << "Senha inválida." << endl;
  1952.                 cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
  1953.             }
  1954.            
  1955.             int count = 0;
  1956.            
  1957.             writeInColor(" Senha", 9);
  1958.             cout << ": ";
  1959.    
  1960.             while(count <= 10)
  1961.             {      
  1962.                 if(count == 10) {info.password[10] = '\0'; break;}
  1963.                
  1964.                 info.password[count] = _getch();
  1965.        
  1966.                 if(info.password[count] == '\n' || info.password[count] == '\r')
  1967.                 {
  1968.                     info.password[count] = '\0';
  1969.                     break;
  1970.                 }
  1971.                
  1972.                 cout << "*";
  1973.                 count++;
  1974.             }
  1975.            
  1976.             check_password = false;
  1977.             system("CLS");
  1978.         } while(!isStringValid(info.password, CONST_PASSWORD_CHECK));
  1979.        
  1980.         char repeat_password[11];
  1981.        
  1982.         cout << "-> Repita a senha." << endl;
  1983.        
  1984.         int count = 0;
  1985.            
  1986.         writeInColor(" Senha", 9);
  1987.         cout << ": ";
  1988.  
  1989.         while(count <= 10)
  1990.         {      
  1991.             if(count == 10) {repeat_password[10] = '\0'; break;}
  1992.            
  1993.             repeat_password[count] = _getch();
  1994.            
  1995.             if(repeat_password[count] == '\n' || repeat_password[count] == '\r')
  1996.             {
  1997.                 repeat_password[count] = '\0';
  1998.                 break;
  1999.             }
  2000.            
  2001.             cout << "*";
  2002.             count++;
  2003.         }
  2004.        
  2005.         same_passwords = strcmp(info.password, repeat_password) == 0 ? true : false;
  2006.         system("CLS");
  2007.     } while(!same_passwords);
  2008.    
  2009.     writeInColor(" Login", 9);
  2010.     cout << ": " << info.login << endl;
  2011.     writeInColor(" Senha", 9);
  2012.     cout << ": " << info.password << endl << endl;
  2013.     cout << "-> Pressione qualquer tecla para continuar o registro." << endl;
  2014.     getch();
  2015.    
  2016.     system("CLS");
  2017.    
  2018.     cout << "-> Por gentileza, informe-nos agora seu nome completo." << endl;
  2019.    
  2020.     bool check_name = true;
  2021.    
  2022.     cin.ignore();
  2023.    
  2024.     do
  2025.     {
  2026.         if(!check_name)
  2027.             cout << "Nome inválido. Por gentileza, reentre com o dado correto." << endl << endl;
  2028.        
  2029.         writeInColor(" Nome completo", 9);
  2030.         cout << ": ";
  2031.        
  2032.         cin.getline(info.name, 1000);
  2033.         check_name = false;
  2034.         system("CLS");
  2035.     } while(!isStringValid(info.name, CONST_NAME_CHECK));
  2036.    
  2037.     adjustName(info.name);
  2038.    
  2039.     cout << "Nome registrado: " << info.name << endl << endl;
  2040.     cout << "-> Pressione qualquer tecla para continuar o registro." << endl;
  2041.     getch();
  2042.    
  2043.     bool _continue = true;
  2044.    
  2045.     if(getNameOccurrences(info.name) > 0)
  2046.     {
  2047.         char resp[10];
  2048.        
  2049.         cout << endl;
  2050.         cout << "Parece que há " << getNameOccurrences(info.name) << " ocorrência(s) desse nome em nosso sistema." << endl;
  2051.         cout << endl;
  2052.        
  2053.         cout << "   -> Se você já tiver se registrado anteriormente no sistema, recomendamos-lhe tentar recuperar sua conta por meio do método de chave de segurança ou contatar um oficial de maior posto." << endl;
  2054.         cout << "   -> Se for apenas uma coincidência, então entre com ";
  2055.         writeInColor("continuar", 9);
  2056.         cout << ". Qualquer outra entrada resultará em uma interrupção no registro." << endl;
  2057.        
  2058.         cin.getline(resp, 10);
  2059.        
  2060.         _continue = strcmp(resp, "continuar") == 0 ? true : false;
  2061.     }
  2062.    
  2063.     system("CLS");
  2064.    
  2065.     if(!_continue) return;
  2066.    
  2067.     cout << "Login, senha e nome confirmados." << endl << endl;
  2068.    
  2069.     cout << "-> Entre agora com seu dia de nascimento." << endl << endl;
  2070.    
  2071.     bool check_day = true;
  2072.    
  2073.     do
  2074.     {
  2075.         if(!check_day)
  2076.             cout << "Dia inválido. Por gentileza, reentre com este dado." << endl << endl;
  2077.        
  2078.         writeInColor(" Dia de nascimento", 9);
  2079.         cout << ": ";
  2080.        
  2081.         cin >> info.day;
  2082.         check_day = false;
  2083.         system("CLS");
  2084.     } while(info.day < 1 || info.day > 31);
  2085.    
  2086.     cout << "-> Entre agora com seu mês de nascimento." << endl << endl;
  2087.    
  2088.     bool check_month = true;
  2089.     do
  2090.     {
  2091.         if(!check_month)
  2092.         {
  2093.             cout << "Mês inválido. Por gentileza, reentre com este dado." << endl;
  2094.             cout << endl;
  2095.         }
  2096.        
  2097.         writeInColor(" Mês de nascimento", 9);
  2098.         cout << ": ";
  2099.        
  2100.         cin >> info.month;
  2101.         check_month = false;
  2102.         system("CLS");
  2103.        
  2104.     } while(info.month < 1 || info.month > 12);
  2105.    
  2106.     while(info.day > 29 && info.month == 2)
  2107.     {
  2108.         cout << "Combinação de data inválida." << endl;
  2109.    
  2110.         cout << "-> Entre agora com seu dia de nascimento." << endl << endl;
  2111.        
  2112.         bool check_day = true;
  2113.        
  2114.         do
  2115.         {
  2116.             if(!check_day)
  2117.                 cout << "Dia inválido. Por gentileza, reentre com este dado." << endl << endl;
  2118.            
  2119.             writeInColor(" Dia de nascimento", 9);
  2120.             cout << ": ";
  2121.            
  2122.             cin >> info.day;
  2123.             check_day = false;
  2124.             system("CLS");
  2125.            
  2126.         } while(info.day < 1 || info.day > 31);
  2127.        
  2128.         cout << "-> Entre agora com seu mês de nascimento." << endl << endl;
  2129.        
  2130.         bool check_month = true;
  2131.        
  2132.         do
  2133.         {
  2134.             if(!check_month)
  2135.                 cout << "Mês inválido. Por gentileza, reentre com este dado." << endl << endl;
  2136.            
  2137.             writeInColor(" Mês de nascimento", 9);
  2138.             cout << ": ";
  2139.            
  2140.             cin >> info.month;
  2141.             check_month = false;
  2142.             system("CLS");
  2143.            
  2144.         } while(info.month < 1 || info.month > 12);
  2145.     }
  2146.  
  2147.     cout << "-> Entre agora com seu ano de nascimento." << endl << endl;
  2148.    
  2149.     time_t t = time(NULL);
  2150.     tm* timePtr = localtime(&t);
  2151.    
  2152.     int year_now = timePtr->tm_year + 1900;
  2153.     bool check_year = true;
  2154.    
  2155.     do
  2156.     {
  2157.         if(!check_year)
  2158.                 cout << "Ano inválido. Por gentileza, reentre com este dado." << endl << endl;
  2159.            
  2160.         writeInColor(" Ano de nascimento", 9);
  2161.         cout << ": ";
  2162.        
  2163.         cin >> info.year;
  2164.         check_year = false;
  2165.         system("CLS");
  2166.        
  2167.     } while(info.year < 1910 || info.year > year_now);
  2168.    
  2169.     char add_d[3] = "0", add_m[3] = "0";
  2170.    
  2171.     itoa(info.day, info.d, 10);
  2172.     itoa(info.month, info.m, 10);
  2173.     itoa(info.year, info.y, 10);
  2174.    
  2175.     if(info.day < 10)
  2176.     {
  2177.         strcat(add_d, info.d);
  2178.         strcpy(info.d, add_d);
  2179.     }
  2180.    
  2181.     if(info.month < 10)
  2182.     {
  2183.         strcat(add_m, info.m);
  2184.         strcpy(info.m, add_m);
  2185.     }
  2186.    
  2187.     cout << "Data de nascimento salva. [" << info.d << "-" << info.m << "-" << info.y << "]" << endl << endl;
  2188.    
  2189.     cout << "-> Agora, informe seu cargo." << endl;
  2190.     cout << "As opções de cargo aceitas são as seguintes:" << endl << endl;
  2191.     cout << "   -> ";
  2192.     writeInColor("Coronel", 4);
  2193.     cout << endl << "   -> ";
  2194.     writeInColor("Tenente-Coronel", 4);
  2195.     cout << endl << "   -> ";
  2196.     writeInColor("Major", 4);
  2197.     cout << endl << "   -> ";
  2198.     writeInColor("Capitao", 4);
  2199.     cout << endl << "   -> ";
  2200.     writeInColor("1 Tenente", 4);
  2201.     cout << endl << "   -> ";
  2202.     writeInColor("2 Tenente", 4);
  2203.     cout << endl << "   -> ";
  2204.     writeInColor("Aspirante a Oficial", 4);
  2205.     cout << endl << "   -> ";
  2206.     writeInColor("Subtenente", 4);
  2207.     cout << endl << "   -> ";
  2208.     writeInColor("1 Sargento", 4);
  2209.     cout << endl << "   -> ";
  2210.     writeInColor("2 Sargento", 4);
  2211.     cout << endl << "   -> ";
  2212.     writeInColor("3 Sargento", 4);
  2213.     cout << endl << "   -> ";
  2214.     writeInColor("Cabo", 4);
  2215.     cout << endl << "   -> ";
  2216.     writeInColor("Soldado", 4);
  2217.     cout << endl << endl;
  2218.    
  2219.     bool is_valid = true;
  2220.    
  2221.     cin.ignore();
  2222.    
  2223.     do
  2224.     {      
  2225.         if(!is_valid)
  2226.             cout << "Este cargo não é válido em nosso sistema. Por favor, entre com outro." << endl << endl;
  2227.        
  2228.         writeInColor(" Cargo", 9);
  2229.         cout << ": ";
  2230.        
  2231.         cin.getline(info.job, 100);
  2232.         adjustName(info.job);
  2233.         is_valid = false;
  2234.         system("CLS");
  2235.     } while(getAccessLevel(info.job) == 0);
  2236.    
  2237.     cout << "Seu cargo foi definido como " << info.job << "." << endl << endl;
  2238.     cout << "-> Agora, você deverá entrar com a data de emissão do seu documento de porte de arma." << endl;
  2239.     cout << "O processo é o mesmo do registro de sua data de nascimento." << endl << endl;
  2240.    
  2241.     bool check_gday = true, check_gmonth = true, check_gyear = true;
  2242.    
  2243.     cout << "-> Entre com o dia." << endl << endl;
  2244.    
  2245.     do
  2246.     {
  2247.         if(!check_gday)
  2248.             cout << "Dia inválido." << endl << endl;
  2249.        
  2250.         writeInColor(" Dia", 9);
  2251.         cout << ": ";
  2252.        
  2253.         cin >> info.gun_day;
  2254.         check_gday = false;
  2255.         system("CLS");
  2256.     } while(info.gun_day < 1 || info.gun_day > 31);
  2257.    
  2258.     cout << "-> Entre agora com o mês." << endl << endl;
  2259.    
  2260.     do
  2261.     {
  2262.         if(!check_gmonth)
  2263.             cout << "Mês inválido." << endl << endl;
  2264.        
  2265.         writeInColor(" Mês", 9);
  2266.         cout << ": ";
  2267.        
  2268.         cin >> info.gun_month;
  2269.         check_gmonth = false;
  2270.         system("CLS");
  2271.     } while(info.gun_month < 1 || info.gun_month > 12);
  2272.    
  2273.     while(info.gun_day > 29 && info.gun_month == 2)
  2274.     {
  2275.         cout << "Combinacão de data inválida." << endl;
  2276.         cout << "Por gentileza, reentre com os dados." << endl;
  2277.        
  2278.         bool check_day_in_scope = true, check_month_in_scope = true;
  2279.        
  2280.         cout << "-> Entre com o dia." << endl << endl;
  2281.        
  2282.         do
  2283.         {
  2284.             if(!check_day_in_scope)
  2285.                 cout << "Dia invalido." << endl << endl;
  2286.        
  2287.             writeInColor(" Dia", 9);
  2288.             cout << ": ";
  2289.            
  2290.             cin >> info.gun_day;
  2291.             check_day_in_scope = false;
  2292.             system("CLS");
  2293.         } while(info.gun_day < 1 || info.gun_day > 31);
  2294.        
  2295.         cout << "-> Entre agora com o mês." << endl << endl;
  2296.        
  2297.         do
  2298.         {
  2299.             if(!check_month_in_scope)
  2300.                 cout << "Mês inválido." << endl << endl;
  2301.            
  2302.             writeInColor(" Mês", 9);
  2303.             cout << ": ";
  2304.            
  2305.             cin >> info.gun_month;
  2306.             check_month_in_scope = false;
  2307.             system("CLS");
  2308.         } while(info.gun_month < 1 || info.gun_month > 12);
  2309.     }
  2310.  
  2311.     cout << "-> Entre agora com o ano." << endl << endl;
  2312.    
  2313.     do
  2314.     {
  2315.         if(!check_gyear)
  2316.             cout << "Ano inválido." << endl << endl;
  2317.        
  2318.         writeInColor(" Ano", 9);
  2319.         cout << ": ";
  2320.        
  2321.         cin >> info.gun_year;
  2322.         check_gyear = false;
  2323.         system("CLS");
  2324.     } while(info.gun_year < (year_now - 5)  || info.gun_year > year_now);
  2325.                
  2326.     char add_dg[3] = "0", add_mg[3] = "0";
  2327.    
  2328.     itoa(info.gun_day, info.dg, 10);
  2329.     itoa(info.gun_month, info.mg, 10);
  2330.     itoa(info.gun_year, info.yg, 10);
  2331.    
  2332.     if(info.gun_day < 10)
  2333.     {
  2334.         strcat(add_dg, info.dg);
  2335.         strcpy(info.dg, add_dg);
  2336.     }
  2337.    
  2338.     if(info.gun_month < 10)
  2339.     {
  2340.         strcat(add_mg, info.mg);
  2341.         strcpy(info.mg, add_mg);
  2342.     }
  2343.    
  2344.     cout << "A data de emissão do seu documento de porte de arma foi salva. [" << info.dg << "-" << info.mg << "-" << info.yg << "]" << endl;
  2345.     cout << "-> Agora, entre com seu cadastro de pessoa física (CPF)." << endl;
  2346.     cout << " APENAS OS CARACTERES NÚMERICOS." << endl << endl;
  2347.    
  2348.     cin.ignore();
  2349.    
  2350.     bool check_CPF = true;
  2351.     char generic_CPF[12];
  2352.    
  2353.     do
  2354.     {
  2355.         do
  2356.         {
  2357.             if(!check_CPF)
  2358.                 cout << "CPF inválido ou em uso. Lembre-se: o CPF possui 11 caracteres NÚMERICOS." << endl << endl;
  2359.            
  2360.             writeInColor(" CPF", 9);
  2361.             cout << ": ";
  2362.            
  2363.             cin.getline(generic_CPF, 12);
  2364.             check_CPF = false;
  2365.             system("CLS");
  2366.         } while(!isStringValid(generic_CPF, CONST_CPF_CHECK));
  2367.        
  2368.         correctAndTransferCPF(info.CPF, generic_CPF);
  2369.     } while(isCPFInUse(info.CPF));
  2370.    
  2371.     cout << "Seu CPF foi registrado com sucesso. [" << info.CPF << "]" << endl;
  2372.     cout << "-> Pressione qualquer tecla para finalizar o registro." << endl;
  2373.    
  2374.     getch();
  2375.    
  2376.     strcpy(info.key, "-1");
  2377.     info.status = -1;
  2378.    
  2379.     info.writeIntoFile();
  2380.    
  2381.     system("CLS");
  2382.     cout << "  -> Registro completo!" << endl << endl;
  2383.     cout << "Suas informações foram com sucesso salvas em nosso banco de dados." << endl;
  2384.     cout << "Seu ingresso no sistema deve agora ser autorizado por algum oficial de maior ordem. Por gentileza, aguarde pacientemente" << endl << endl;
  2385.     cout << "Pressione qualquer tecla para continuar." << endl;
  2386.     getch();
  2387.     system("CLS");
  2388. }
  2389.  
  2390. void printInfoAbout(char login[], int access, bool yourself, bool show_new_job)
  2391. {
  2392.     Cop info = getAccountInfo(login);
  2393.    
  2394.     cout << "  -> Nome: " << info.name << endl;
  2395.            
  2396.     if(access > 9 || yourself)
  2397.         cout << "  -> Login: " << login << endl;
  2398.    
  2399.     if(yourself)
  2400.         cout << "  -> Senha: " << info.password << endl;
  2401.    
  2402.     if(yourself && strcmp(info.key, "-1") != 0)
  2403.         cout << "  -> Chave: " << info.key << endl;
  2404.    
  2405.     if(yourself)
  2406.         cout << "  -> CPF: " << info.CPF << endl;
  2407.    
  2408.     cout << "  -> Idade: " << info.age << endl;
  2409.    
  2410.     char job_cmp[100], new_job[100];
  2411.            
  2412.     if(strchr(info.job, ':') != NULL)
  2413.     {
  2414.         int k[getIndexesSize(info.job, ':')];
  2415.         getIndexesBySplittingSentence(info.job, ':', k);
  2416.        
  2417.         int now_job = k[0] - 1;
  2418.         char tmp_job[now_job];
  2419.        
  2420.         fillSentence(info.job, -1, k[0], tmp_job);
  2421.         strcpy(job_cmp, tmp_job);
  2422.        
  2423.         if(show_new_job)
  2424.         {  
  2425.             int new_job_size = strlen(info.job) - k[0] - 1;
  2426.             char new_job_here[new_job_size];
  2427.            
  2428.             fillSentence(info.job, k[0], strlen(info.job), new_job_here);
  2429.             strcpy(new_job, new_job_here);
  2430.         }
  2431.     }
  2432.     else
  2433.         strcpy(job_cmp, info.job);
  2434.        
  2435.     cout << "  -> Cargo: " << job_cmp << endl;
  2436.    
  2437.     if(show_new_job)
  2438.         cout << "  -> Cargo solicitado: " << new_job << endl;
  2439.        
  2440.     cout << "  -> Data de nascimento: " << info.birth_date << endl;
  2441.     cout << "  -> Data de registro da arma: " << info.gun << endl << endl;
  2442. }
  2443.  
  2444. Cop getAccountInfo(char input_login[])
  2445. {
  2446.     ifstream file_now("cop_data.txt");
  2447.    
  2448.     Cop ret;
  2449.    
  2450.     time_t t = time(NULL);
  2451.     tm* timePtr = localtime(&t);
  2452.    
  2453.     strcpy(ret.login, input_login);
  2454.    
  2455.     char line[2000];
  2456.    
  2457.     while(file_now.getline(line, 2000))
  2458.     {  
  2459.         int i[getIndexesSize(line, '/')];
  2460.         getIndexesBySplittingSentence(line, '/', i);
  2461.    
  2462.         int login_size = i[3] - i[2] - 1;
  2463.         char login[login_size];
  2464.        
  2465.         fillSentence(line, i[2], i[3], login);
  2466.    
  2467.         if(strcmp(input_login, login) == 0)
  2468.         {  
  2469.             int name_size = i[1] - i[0] - 1, pass_size = i[5] - i[4] - 1, key_size = 8;
  2470.             int age, birth_date_size = i[9] - i[8] - 1, year_now = timePtr->tm_year + 1900, month_now = timePtr->tm_mon + 1, day_now = timePtr->tm_mday;
  2471.             int job_size = i[11] - i[10] - 1, gun_size = i[13] - i[12] - 1, CPF_size = i[15] - i[14] - 1, status_size = i[17] - i[16] - 1;
  2472.             char name_now[name_size], password[pass_size], key[key_size], birth_date[birth_date_size], job_now[job_size], gun[gun_size], CPF[CPF_size], status[status_size];
  2473.    
  2474.             fillSentence(line, i[0], i[1], name_now);
  2475.             fillSentence(line, i[4], i[5], password);
  2476.             fillSentence(line, i[6], i[7], key);
  2477.             fillSentence(line, i[8], i[9], birth_date);
  2478.             fillSentence(line, i[10], i[11], job_now);
  2479.             fillSentence(line, i[12], i[13], gun);
  2480.             fillSentence(line, i[14], i[15], CPF);
  2481.             fillSentence(line, i[16], i[17], status);
  2482.            
  2483.             int g[getIndexesSize(birth_date, '-')];
  2484.             getIndexesBySplittingSentence(birth_date, '-', g);
  2485.            
  2486.             int day_size = g[0], mon_size = g[1] - g[0] - 1, year_size = strlen(birth_date) - g[1] - 1;
  2487.            
  2488.             char day_str[day_size], mon_str[mon_size], year_str[year_size];
  2489.            
  2490.             fillSentence(birth_date, -1, g[0], day_str);
  2491.             fillSentence(birth_date, g[0], g[1], mon_str);
  2492.             fillSentence(birth_date, g[1], strlen(birth_date), year_str);
  2493.            
  2494.             int day = atoi(day_str);
  2495.             int month = atoi(mon_str);
  2496.             int year = atoi(year_str);
  2497.            
  2498.             age = year_now - year;
  2499.            
  2500.             if(month_now < month || (month_now == month && day_now < day))
  2501.                 age--;
  2502.            
  2503.             strcpy(ret.name, name_now);
  2504.             strcpy(ret.password, password);
  2505.             strcpy(ret.key, key);
  2506.             strcpy(ret.birth_date, birth_date);
  2507.             strcpy(ret.job, job_now);
  2508.             strcpy(ret.gun, gun);
  2509.             strcpy(ret.CPF, CPF);
  2510.            
  2511.             ret.status = atoi(status);
  2512.             ret.age = age;
  2513.             ret.access = getAccessLevel(ret.job);
  2514.            
  2515.             break;
  2516.         }
  2517.     }
  2518.    
  2519.     file_now.close();
  2520.    
  2521.     return ret;
  2522. }
  2523.  
  2524. void fillSentence(char line[], int begin, int end, char target[])
  2525. {
  2526.     int count = 0;
  2527.    
  2528.     for(int i = begin + 1; i < end; i++)
  2529.         target[count++] = line[i];
  2530.    
  2531.     target[end - begin - 1] = '\0';
  2532. }
  2533.  
  2534. void deleteAccount(const char* input_login)
  2535. {
  2536.     file.open("cop_data.txt");
  2537.     out_file.open("tmp.txt", ios_base::app | ios_base::out);
  2538.    
  2539.     char line[2000];
  2540.    
  2541.     while(file.getline(line, 2000))
  2542.     {
  2543.         int i[getIndexesSize(line, '/')];
  2544.         getIndexesBySplittingSentence(line, '/', i);
  2545.    
  2546.         int login_size = i[3] - i[2] - 1;
  2547.         char login[login_size];
  2548.        
  2549.         fillSentence(line, i[2], i[3], login);
  2550.    
  2551.         if(strcmp(input_login, login) != 0)
  2552.             out_file << line << endl;
  2553.     }
  2554.    
  2555.     file.close();
  2556.     out_file.close();
  2557.     remove("cop_data.txt");
  2558.     rename("tmp.txt", "cop_data.txt");
  2559. }
  2560.  
  2561. void openWebsite(const char* website){ShellExecute(NULL, "open", website, NULL, NULL, SW_SHOWNORMAL);}
  2562.  
  2563. void createAdminAccount()
  2564. {
  2565.     Register admin;
  2566.    
  2567.     strcpy(admin.login, "admin");
  2568.     strcpy(admin.password, "admin");
  2569.     strcpy(admin.name, "Administrador");
  2570.     strcpy(admin.job, "Coronel");
  2571.     strcpy(admin.CPF, "000.000.000-00");
  2572.     strcpy(admin.key, "0");
  2573.     strcpy(admin.d, "30");
  2574.     strcpy(admin.m, "04");
  2575.     strcpy(admin.y, "1999");
  2576.     strcpy(admin.dg, "30");
  2577.     strcpy(admin.mg, "04");
  2578.     strcpy(admin.yg, "3000");
  2579.    
  2580.     admin.status = 2;
  2581.    
  2582.     admin.writeIntoFile();
  2583. }
  2584.  
  2585. bool isCPFInUse(char CPF[])
  2586. {  
  2587.     file.open("cop_data.txt");
  2588.    
  2589.     char line[2000];
  2590.    
  2591.     while(file.getline(line, 2000))
  2592.     {
  2593.         int i[getIndexesSize(line, '/')];
  2594.         getIndexesBySplittingSentence(line, '/', i);
  2595.    
  2596.         int CPF_size = i[15] - i[14] - 1;
  2597.         char CPF_check[CPF_size];
  2598.        
  2599.         fillSentence(line, i[14], i[15], CPF_check);
  2600.        
  2601.         if(strcmp(CPF, CPF_check) == 0)
  2602.         {
  2603.             file.close();
  2604.             return true;
  2605.         }
  2606.     }
  2607.    
  2608.     file.close();
  2609.     return false;
  2610. }
  2611.  
  2612. void recoverAccount()
  2613. {
  2614.     char login[13], key[8];
  2615.    
  2616.     cout << "-> Entre com o login da conta que deseja recuperar." << endl << endl;
  2617.    
  2618.     writeInColor(" Login", 9);
  2619.     cout << ": ";
  2620.     cin.getline(login, 13);
  2621.     system("CLS");
  2622.    
  2623.     if(!isInUse(login))
  2624.     {
  2625.         cout << "-> Login inválido." << endl << endl;
  2626.         cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  2627.         _getch();
  2628.         return;
  2629.     }
  2630.    
  2631.     Cop info = getAccountInfo(login);
  2632.    
  2633.     cout << "-> Entre com a chave de segurança desta conta." << endl;
  2634.    
  2635.     writeInColor(" Chave", 9);
  2636.     cout << ": ";
  2637.     cin.getline(key, 8);
  2638.     system("CLS");
  2639.    
  2640.     if(strcmp(info.key, "-1") == 0 || strcmp(info.key, key) != 0)
  2641.     {
  2642.         cout << "-> Combinação inválida." << endl << endl;
  2643.         cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  2644.         _getch();
  2645.         return;
  2646.     }
  2647.    
  2648.     cout << "-> A senha desta conta é: ";
  2649.     writeInColor(info.password, 9);
  2650.     cout << endl << endl;
  2651.    
  2652.     cout << "Pressione qualquer tecla para voltar ao menu." << endl;
  2653.     _getch();
  2654. }
  2655.  
  2656. bool isInArray(int array[], int size, int element)
  2657. {
  2658.     for(int i = 0; i < size; i++)
  2659.         if(element == array[i])
  2660.             return true;
  2661.  
  2662.     return false;
  2663. }
  2664.  
  2665. void generateSecurityKey(char key[])
  2666. {
  2667.     const char options[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2668.                            "abcdefghijklmnopqrstuvwxyz"
  2669.                            "0123456789";
  2670.          
  2671.     int size = sizeof(options) - 1;
  2672.    
  2673.     srand(time(NULL));            
  2674.     for(int i = 0; i < 7; i++)
  2675.         key[i] = options[rand() % size];
  2676.    
  2677.     key[7] = '\0';
  2678. }
  2679.  
  2680. void showPendentAccounts(int count, bool admin)
  2681. {
  2682.     file.open("cop_data.txt");
  2683.     int c = 0;
  2684.     char *login[count], line[2000];
  2685.    
  2686.     while(file.getline(line, 2000))
  2687.     {
  2688.         int i[getIndexesSize(line, '/')];
  2689.         getIndexesBySplittingSentence(line, '/', i);
  2690.        
  2691.         int status_size = i[17] - i[16] - 1;
  2692.         char status[status_size];
  2693.  
  2694.         fillSentence(line, i[16], i[17], status);
  2695.        
  2696.         if(atoi(status) == -1)
  2697.         {
  2698.             int login_size = i[3] - i[2] - 1;
  2699.             char login_now[login_size];
  2700.    
  2701.             fillSentence(line, i[2], i[3], login_now);
  2702.                
  2703.             login[c] = new char[login_size];
  2704.             strcpy(login[c], login_now);
  2705.             c++;
  2706.         }
  2707.     }
  2708.    
  2709.     file.close();
  2710.    
  2711.     char tmp_n[4];
  2712.     itoa(count, tmp_n, 10);
  2713.    
  2714.     cout << "    *** Há (";
  2715.     writeInColor(tmp_n, 9);
  2716.     cout << ") conta(s) para admitir. ***" << endl << endl;
  2717.    
  2718.     printByArray(login, count, 10, false);
  2719.    
  2720.     char look_for_login[13];
  2721.     bool check_login = true;
  2722.    
  2723.     do
  2724.     {
  2725.         if(!check_login)
  2726.             cout << " Login inválido. Se desejar voltar ao menu, digite 1." << endl;
  2727.        
  2728.         writeInColor(" Login", 9);
  2729.         cout << ": ";
  2730.        
  2731.         cin.getline(look_for_login, 13);
  2732.         check_login = false;
  2733.         system("CLS");
  2734.     } while(!isInUse(look_for_login) && strcmp(look_for_login, "1") != 0);
  2735.    
  2736.     if(strcmp(look_for_login, "1") == 0) return;
  2737.    
  2738.     char num[] = "1";
  2739.    
  2740.     updateAccount(look_for_login, 16, num, admin);
  2741.     cout << "-> Conta admitida." << endl << endl;
  2742.     cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  2743.     _getch();
  2744. }
  2745.  
  2746. void showPendentJobs(int count, bool admin)
  2747. {
  2748.     file.open("cop_data.txt");
  2749.     char *login[count], line[2000];
  2750.     int counting = 0;
  2751.    
  2752.     while(file.getline(line, 2000))
  2753.     {
  2754.         int i[getIndexesSize(line, '/')];
  2755.         getIndexesBySplittingSentence(line, '/', i);
  2756.        
  2757.         int job_size = i[11] - i[10] - 1;
  2758.         char job_now[job_size];
  2759.  
  2760.         fillSentence(line, i[10], i[11], job_now);
  2761.        
  2762.         if(strchr(job_now, ':') != NULL)
  2763.         {  
  2764.             int login_size = i[3] - i[2] - 1;
  2765.             char login_now[login_size];
  2766.    
  2767.             fillSentence(line, i[2], i[3], login_now);
  2768.            
  2769.             login[counting] = new char[login_size];
  2770.             strcpy(login[counting], login_now);
  2771.             counting++;
  2772.         }
  2773.     }
  2774.    
  2775.     file.close();
  2776.  
  2777.     char tmp_n[4];
  2778.     itoa(count, tmp_n, 10);
  2779.    
  2780.     cout << "    *** Há (";
  2781.     writeInColor(tmp_n, 9);
  2782.     cout << ") solicitação(ões) de mudança de cargo. ***" << endl << endl;
  2783.        
  2784.     printByArray(login, count, 10, true);
  2785.    
  2786.     char look_for_login[13];
  2787.     bool check_login = true;
  2788.    
  2789.     do
  2790.     {
  2791.         if(!check_login)
  2792.             cout << endl << " Login inválido. Se desejar voltar ao menu, digite 1." << endl;
  2793.        
  2794.         writeInColor(" Login", 9);
  2795.         cout << ": ";
  2796.        
  2797.         cin.getline(look_for_login, 13);
  2798.         check_login = false;
  2799.         system("CLS");
  2800.     } while(!isInUse(look_for_login) && strcmp(look_for_login, "1") != 0);
  2801.    
  2802.     system("CLS");
  2803.    
  2804.     if(strcmp(look_for_login, "1") == 0) return;
  2805.    
  2806.     Cop info = getAccountInfo(look_for_login);
  2807.    
  2808.     int k[getIndexesSize(info.job, ':')];
  2809.     getIndexesBySplittingSentence(info.job, ':', k);
  2810.    
  2811.     int new_job_size = strlen(info.job) - k[0] - 1;
  2812.     char new_job[new_job_size];
  2813.        
  2814.     fillSentence(info.job, k[0], strlen(info.job), new_job);
  2815.    
  2816.     updateAccount(look_for_login, 10, new_job, admin);
  2817.     cout << "-> Cargo da referida conta atualizado com sucesso para " << new_job << "." << endl << endl;
  2818.     cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  2819.     _getch();
  2820. }
  2821.  
  2822. int getPendentAdmissions()
  2823. {
  2824.     file.open("cop_data.txt");
  2825.     char line[2000];
  2826.     int count = 0;
  2827.    
  2828.     while(file.getline(line, 2000))
  2829.     {
  2830.         int i[getIndexesSize(line, '/')];
  2831.         getIndexesBySplittingSentence(line, '/', i);
  2832.        
  2833.         int status_size = i[17] - i[16] - 1;
  2834.         char status[status_size];
  2835.  
  2836.         fillSentence(line, i[16], i[17], status);
  2837.        
  2838.         if(atoi(status) == -1) count++;
  2839.     }
  2840.    
  2841.     file.close();
  2842.    
  2843.     return count;
  2844. }
  2845.  
  2846. int getPendentJobSolicitations()
  2847. {
  2848.     file.open("cop_data.txt");
  2849.     int count = 0;
  2850.     char line[2000];
  2851.    
  2852.     while(file.getline(line, 2000))
  2853.     {
  2854.         int i[getIndexesSize(line, '/')];
  2855.         getIndexesBySplittingSentence(line, '/', i);
  2856.        
  2857.         int job_size = i[11] - i[10] - 1;
  2858.         char job_now[job_size];
  2859.  
  2860.         fillSentence(line, i[10], i[11], job_now);
  2861.        
  2862.         if(strchr(job_now, ':') != NULL) count++;
  2863.     }
  2864.    
  2865.     file.close();
  2866.  
  2867.     return count;
  2868. }
  2869.        
  2870. void executeDeletion(int access, char login_input[])
  2871. {
  2872.     char login[13];
  2873.                                    
  2874.     system("CLS");
  2875.    
  2876.     cout << "-> Digite o login do policial que será removido." << endl << endl;
  2877.     writeInColor(" Login", 9);
  2878.     cout << ": ";
  2879.    
  2880.     cin.getline(login, 13);
  2881.    
  2882.     system("CLS");
  2883.    
  2884.     if(strcmp(login_input, login) == 0)
  2885.     {
  2886.         cout << " Você não pode deletar sua própria conta." << endl << endl;
  2887.         cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  2888.         _getch();
  2889.     }
  2890.     else if(!isInUse(login))
  2891.     {
  2892.         cout << " Este nome de usuário não está registrado no sistema. Por gentileza, verifique-o novamente." << endl << endl;
  2893.         cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  2894.         _getch();
  2895.        
  2896.     }
  2897.     else
  2898.     {
  2899.         char name[1000];
  2900.        
  2901.         cout << "-> Digite o nome do policial para confirmar o processo." << endl << endl;
  2902.        
  2903.         int resp, check_name = true;
  2904.        
  2905.         do
  2906.         {
  2907.             do
  2908.             {
  2909.                 if(!check_name)
  2910.                     cout << " Nome inválido. Por gentileza, reentre com o dado correto. (1 para voltar ao menu de pesquisa)" << endl << endl;
  2911.                
  2912.                 writeInColor(" Nome completo", 9);
  2913.                 cout << ": ";
  2914.                
  2915.                 cin.getline(name, 1000);
  2916.                 check_name = false;
  2917.                 system("CLS");
  2918.             } while(!isStringValid(name, 2) && atoi(name) != 1);
  2919.            
  2920.             if(atoi(name) == 1)
  2921.                 resp = 1;
  2922.             else
  2923.             {
  2924.                 cout << " O nome " << name << " está correto?" << endl;
  2925.                 resp = getYesOrNo();
  2926.             }
  2927.            
  2928.         } while(resp == 1);
  2929.        
  2930.         if(atoi(name) != 1)
  2931.         {
  2932.             Cop target = getAccountInfo(login);
  2933.            
  2934.             adjustName(name);
  2935.            
  2936.             if(strcmp(target.name, name) != 0)
  2937.             {
  2938.                 cout << " O nome entrado é diferente do nome do dono da conta." << endl << endl;
  2939.                 cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  2940.                 _getch();
  2941.             }
  2942.             else if(target.access > access)
  2943.             {
  2944.                 cout << " Você possui um nível de acesso inferior ao da conta." << endl << endl;
  2945.                 cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  2946.                 _getch();
  2947.             }
  2948.             else
  2949.             {
  2950.                 deleteAccount(login);
  2951.                 cout << " Conta deletada com sucesso." << endl << endl;
  2952.                 cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  2953.                 _getch();
  2954.             }
  2955.         }  
  2956.     }
  2957. }
  2958.  
  2959. void getArt(int art, bool open_site)
  2960. {
  2961.     switch(art)
  2962.     {
  2963.         case 33:
  2964.             if(open_site)
  2965.                 openWebsite("https://www.jusbrasil.com.br/topicos/10636569/artigo-33-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
  2966.             else
  2967.                 cout << "Tráfico de drogas";
  2968.             break;
  2969.         case 121:
  2970.             if(open_site)
  2971.                 openWebsite("https://pt.wikipedia.org/wiki/Homic%C3%ADdio");
  2972.             else
  2973.                 cout << "Homicídio";
  2974.             break;
  2975.         case 129:
  2976.             if(open_site)
  2977.                 openWebsite("https://pt.wikipedia.org/wiki/Les%C3%A3o_corporal");
  2978.             else
  2979.                 cout << "Lesão Corporal";
  2980.             break;
  2981.         case 155:
  2982.             if(open_site)
  2983.                 openWebsite("https://pt.wikipedia.org/wiki/Furto");
  2984.             else
  2985.                 cout << "Furto";
  2986.             break;
  2987.         case 157:
  2988.             if(open_site)
  2989.                 openWebsite("https://pt.wikipedia.org/wiki/Roubo");
  2990.             else
  2991.                 cout << "Roubo ou Latrocínio";
  2992.             break;
  2993.         case 158:
  2994.             if(open_site)
  2995.                 openWebsite("https://pt.wikipedia.org/wiki/Extors%C3%A3o");
  2996.             else
  2997.                 cout << "Extorsão";
  2998.             break;
  2999.         case 171:
  3000.             if(open_site)
  3001.                 openWebsite("https://www.jusbrasil.com.br/topicos/10617301/artigo-171-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
  3002.             else
  3003.                 cout << "Fraude ou Estelionato";
  3004.             break;
  3005.         case 213:
  3006.             if(open_site)
  3007.                 openWebsite("https://leonardocastro2.jusbrasil.com.br/artigos/121943503/legislacao-comentada-artigo-213-do-cp-estupro");
  3008.             else
  3009.                 cout << "Estupro";
  3010.             break;
  3011.         case 216:
  3012.             if(open_site)
  3013.                 openWebsite("https://vicentemaggio.jusbrasil.com.br/artigos/121942480/o-crime-de-assedio-sexual");
  3014.             else
  3015.                 cout << "Assédio Sexual";
  3016.             break;
  3017.         case 250:
  3018.             if(open_site)
  3019.                 openWebsite("https://www.jusbrasil.com.br/topicos/10607060/artigo-250-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
  3020.             else
  3021.                 cout << "Incêndio";
  3022.             break;
  3023.         case 256:
  3024.             if(open_site)
  3025.                 openWebsite("https://www.jusbrasil.com.br/topicos/10606196/artigo-256-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
  3026.             else
  3027.                 cout << "Desmoronamento/desabamento";
  3028.             break;
  3029.         default:
  3030.             cout << "Outro";
  3031.     }
  3032. }
  3033.  
  3034. void updateAccount(char login[], int start, char new_value[], bool admin)
  3035. {
  3036.     Cop info = getAccountInfo(login);
  3037.     Register new_info;
  3038.    
  3039.     ifstream old_file("cop_data.txt");
  3040.     out_file.open("tmp.txt", ios_base::app | ios_base::out);
  3041.     char line[2000], old_line[2000];
  3042.    
  3043.     while(old_file.getline(line, 2000))
  3044.     {
  3045.         int i[getIndexesSize(line, '/')];
  3046.         getIndexesBySplittingSentence(line, '/', i);
  3047.    
  3048.         int login_size = i[3] - i[2] - 1;
  3049.         char login_now[login_size];
  3050.        
  3051.         fillSentence(line, i[2], i[3], login_now);
  3052.    
  3053.         if(strcmp(login_now, login) == 0)
  3054.             strcpy(old_line, line);
  3055.         else
  3056.             out_file << line << endl;
  3057.     }
  3058.    
  3059.     old_file.close();
  3060.     out_file.close();
  3061.     remove("cop_data.txt");
  3062.     rename("tmp.txt", "cop_data.txt");
  3063.    
  3064.     strcpy(new_info.name, info.name);
  3065.     strcpy(new_info.login, login);
  3066.    
  3067.     if(start == 4)
  3068.         strcpy(new_info.password, new_value);
  3069.     else
  3070.         strcpy(new_info.password, info.password);
  3071.    
  3072.     if(start == 6)
  3073.         strcpy(new_info.key, new_value);
  3074.     else
  3075.         strcpy(new_info.key, info.key);
  3076.    
  3077.     int k[getIndexesSize(info.birth_date, '-')];
  3078.     getIndexesBySplittingSentence(info.birth_date, '-', k);
  3079.    
  3080.     char day[3], mon[3], year[5];
  3081.    
  3082.     fillSentence(info.birth_date, -1, k[0], day);
  3083.     fillSentence(info.birth_date, k[0], k[1], mon);
  3084.     fillSentence(info.birth_date, k[1], strlen(info.birth_date), year);
  3085.    
  3086.     new_info.day = atoi(day);
  3087.     new_info.month = atoi(mon);
  3088.     new_info.year = atoi(year);
  3089.    
  3090.     strcpy(new_info.d, day);
  3091.     strcpy(new_info.m, mon);
  3092.     strcpy(new_info.y, year);
  3093.    
  3094.     strcpy(new_info.job, info.job);
  3095.    
  3096.     if(start == 10)
  3097.     {
  3098.         if(strchr(new_info.job, ':') != NULL)
  3099.             strcpy(new_info.job, new_value);
  3100.         else
  3101.         {
  3102.             strcat(new_info.job, ":");
  3103.             strcat(new_info.job, new_value);
  3104.         }
  3105.     }
  3106.    
  3107.     char gday[3], gmon[3], gyear[5];
  3108.    
  3109.     if(start == 12)
  3110.     {
  3111.         int j[getIndexesSize(new_value, '-')];
  3112.         getIndexesBySplittingSentence(new_value, '-', j);
  3113.        
  3114.         fillSentence(new_value, -1, j[0], gday);
  3115.         fillSentence(new_value, j[0], j[1], gmon);
  3116.         fillSentence(new_value, j[1], strlen(new_value), gyear);
  3117.        
  3118.         new_info.gun_day = atoi(gday);
  3119.         new_info.gun_month = atoi(gmon);
  3120.         new_info.gun_year = atoi(gyear);
  3121.        
  3122.         strcpy(new_info.dg, gday);
  3123.         strcpy(new_info.mg, gmon);
  3124.         strcpy(new_info.yg, gyear);
  3125.        
  3126.     }
  3127.     else
  3128.     {
  3129.         int j[getIndexesSize(info.gun, '-')];
  3130.         getIndexesBySplittingSentence(info.gun, '-', j);
  3131.        
  3132.         fillSentence(info.gun, -1, j[0], gday);
  3133.         fillSentence(info.gun, j[0], j[1], gmon);
  3134.         fillSentence(info.gun, j[1], strlen(info.gun), gyear);
  3135.        
  3136.         new_info.gun_day = atoi(gday);
  3137.         new_info.gun_month = atoi(gmon);
  3138.         new_info.gun_year = atoi(gyear);
  3139.        
  3140.         strcpy(new_info.dg, gday);
  3141.         strcpy(new_info.mg, gmon);
  3142.         strcpy(new_info.yg, gyear);
  3143.     }
  3144.    
  3145.     strcpy(new_info.CPF, info.CPF);
  3146.    
  3147.     if(start == 16)
  3148.         new_info.status = atoi(new_value);
  3149.     else
  3150.         new_info.status = info.status;
  3151.    
  3152.     if(admin && getAccessLevel(new_info.job) > 9)
  3153.     {
  3154.         deleteAccount("admin");
  3155.         pendent = false;
  3156.         edit = false;
  3157.         logon = false;
  3158.     }
  3159.    
  3160.     new_info.writeIntoFile();
  3161. }
  3162.  
  3163. void changeDate(char login[])
  3164. {
  3165.     system("CLS");
  3166.    
  3167.     cout << "-> Informe a nova data de emissão do documento de porte de armas." << endl;
  3168.    
  3169.     int new_day, new_month, new_year;
  3170.     bool check_day = true, check_month = true, check_year = true;
  3171.        
  3172.     do
  3173.     {
  3174.         if(!check_day)
  3175.             cout << "Dia inválido." << endl << endl;
  3176.        
  3177.         writeInColor(" Dia", 9);
  3178.         cout << ": ";
  3179.        
  3180.         cin >> new_day;
  3181.         check_day = false;
  3182.         system("CLS");
  3183.     } while(new_day < 1 || new_day > 31);
  3184.    
  3185.     cout << "-> Informe o novo mês de emissão do documento de porte de armas." << endl;
  3186.    
  3187.     do
  3188.     {
  3189.         if(!check_month)
  3190.             cout << "Mês inválido." << endl << endl;
  3191.        
  3192.         writeInColor(" Mês", 9);
  3193.         cout << ": ";
  3194.        
  3195.         cin >> new_month;
  3196.         check_month = false;
  3197.         system("CLS");
  3198.     } while(new_month < 1 || new_month > 12);
  3199.    
  3200.     while(new_day > 29 && new_month == 2)
  3201.     {
  3202.         cout << "Combinação de data inválida." << endl;
  3203.         cout << "Por gentileza, reentre com os dados." << endl;
  3204.        
  3205.         bool check_day_in_scope = true, check_month_in_scope = true;
  3206.         cout << "-> Informe a nova data de emissão do documento de porte de armas." << endl;
  3207.        
  3208.         do
  3209.         {
  3210.             if(!check_day_in_scope)
  3211.                 cout << "Dia inválido." << endl << endl;
  3212.        
  3213.             writeInColor(" Dia", 9);
  3214.             cout << ": ";
  3215.            
  3216.             cin >> new_day;
  3217.             check_day_in_scope = false;
  3218.             system("CLS");
  3219.         } while(new_day < 1 || new_day > 31);
  3220.        
  3221.         cout << "-> Informe o novo mês de emissão do documento de porte de armas." << endl;
  3222.        
  3223.         do
  3224.         {
  3225.             if(!check_month_in_scope)
  3226.                 cout << "Mês inválido." << endl << endl;
  3227.            
  3228.             writeInColor(" Mês", 9);
  3229.             cout << ": ";
  3230.            
  3231.             cin >> new_month;
  3232.             check_month_in_scope = false;
  3233.             system("CLS");
  3234.         } while(new_month < 1 || new_month > 12);
  3235.     }
  3236.  
  3237.     time_t t = time(NULL);
  3238.     tm* timePtr = localtime(&t);
  3239.     int year_now = timePtr->tm_year + 1900;
  3240.            
  3241.     cout << "-> Informe o novo ano de emissão do documento de porte de armas." << endl;
  3242.        
  3243.     do
  3244.     {
  3245.         if(!check_year)
  3246.             cout << "Ano inválido." << endl << endl;
  3247.        
  3248.         writeInColor(" Ano", 9);
  3249.         cout << ": ";
  3250.        
  3251.         cin >> new_year;
  3252.         check_year = false;
  3253.         system("CLS");
  3254.     } while(new_year < (year_now - 5)  || new_year > year_now);
  3255.    
  3256.     char date[11], d[3], m[3], y[5], add_dg[3] = "0", add_mg[3] = "0";
  3257.    
  3258.     itoa(new_day, d, 10);
  3259.     itoa(new_month, m, 10);
  3260.     itoa(new_year, y, 10);
  3261.    
  3262.     if(new_day < 10)
  3263.     {
  3264.         strcat(add_dg, d);
  3265.         strcpy(d, add_dg);
  3266.     }
  3267.    
  3268.     if(new_month < 10)
  3269.     {
  3270.         strcat(add_mg, m);
  3271.         strcpy(m, add_mg);
  3272.     }
  3273.    
  3274.     strcpy(date, d);
  3275.     strcat(date, "-");
  3276.     strcat(date, m);
  3277.     strcat(date, "-");
  3278.     strcat(date, y);
  3279.                
  3280.     updateAccount(login, 12, date, false);
  3281.    
  3282.     cout << "-> Data de emissao atualizada." << endl << endl;
  3283.     cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  3284.     _getch();
  3285. }
  3286.  
  3287. void changeCargo(char login[])
  3288. {  
  3289.     Cop info = getAccountInfo(login);
  3290.    
  3291.     if(getIndexesSize(info.job, ':') != 0)
  3292.     {
  3293.         cout << "Esta conta já solicitou por uma mudança de cargo." << endl << endl;
  3294.        
  3295.         cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  3296.         _getch();
  3297.         return;
  3298.     }
  3299.    
  3300.    
  3301.     char new_job[100];
  3302.    
  3303.     system("CLS");
  3304.    
  3305.     cout << "-> Informe seu novo cargo." << endl;
  3306.     cout << "As opções de cargo aceitas são as seguintes:" << endl << endl;
  3307.    
  3308.     cout << "   -> ";
  3309.     writeInColor("Coronel", 4);
  3310.     cout << endl;
  3311.    
  3312.     cout << "   -> ";
  3313.     writeInColor("Tenente-Coronel", 4);
  3314.     cout << endl;
  3315.    
  3316.     cout << "   -> ";
  3317.     writeInColor("Major", 4);
  3318.     cout << endl;
  3319.    
  3320.     cout << "   -> ";
  3321.     writeInColor("Capitao", 4);
  3322.     cout << endl;
  3323.    
  3324.     cout << "   -> ";
  3325.     writeInColor("1 Tenente", 4);
  3326.     cout << endl;
  3327.    
  3328.     cout << "   -> ";
  3329.     writeInColor("2 Tenente", 4);
  3330.     cout << endl;
  3331.    
  3332.     cout << "   -> ";
  3333.     writeInColor("Aspirante a Oficial", 4);
  3334.     cout << endl;
  3335.    
  3336.     cout << "   -> ";
  3337.     writeInColor("Subtenente", 4);
  3338.     cout << endl;
  3339.    
  3340.     cout << "   -> ";
  3341.     writeInColor("1 Sargento", 4);
  3342.     cout << endl;
  3343.    
  3344.     cout << "   -> ";
  3345.     writeInColor("2 Sargento", 4);
  3346.     cout << endl;
  3347.    
  3348.     cout << "   -> ";
  3349.     writeInColor("3 Sargento", 4);
  3350.     cout << endl;
  3351.    
  3352.     cout << "   -> ";
  3353.     writeInColor("Cabo", 4);
  3354.     cout << endl;
  3355.    
  3356.     cout << "   -> ";
  3357.     writeInColor("Soldado", 4);
  3358.     cout << endl << endl;
  3359.    
  3360.     bool is_valid = true;
  3361.    
  3362.     do
  3363.     {
  3364.         if(!is_valid)
  3365.             cout << "Este cargo não é válido em nosso sistema. Por favor, reentre com este dado." << endl << endl;
  3366.        
  3367.         writeInColor(" Cargo", 9);
  3368.         cout << ": ";
  3369.         cin.getline(new_job, 100);
  3370.         adjustName(new_job);
  3371.         is_valid = false;
  3372.         system("CLS");
  3373.     } while(getAccessLevel(new_job) == 0);
  3374.    
  3375.     updateAccount(login, 10, new_job, false);
  3376.    
  3377.     cout << "-> Mudança de cargo solicitada." << endl << endl;
  3378.     cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  3379.     _getch();
  3380. }
  3381.  
  3382. void changePassword(char login[])
  3383. {
  3384.     char new_password[11];
  3385.    
  3386.     system("CLS");
  3387.    
  3388.     cout << "-> Entre com a nova senha." << endl;
  3389.     cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
  3390.    
  3391.     bool same_passwords = true;
  3392.    
  3393.     do
  3394.     {
  3395.         if(!same_passwords)
  3396.             cout << "Senhas diferentes. Por favor, reentre com este dado." << endl << endl;
  3397.        
  3398.        
  3399.         bool check_password = true;
  3400.    
  3401.         do
  3402.         {
  3403.             if(!check_password)
  3404.             {
  3405.                 system("CLS");
  3406.                 cout << "Senha inválida." << endl;
  3407.                 cout << "MIN. 4 MAX. 10 caracteres. APENAS LETRAS E NUMEROS!" << endl << endl;
  3408.             }
  3409.            
  3410.             int count = 0;
  3411.            
  3412.             writeInColor(" Senha", 9);
  3413.             cout << ": ";
  3414.    
  3415.             while(count <= 10)
  3416.             {      
  3417.                 if(count == 10) {new_password[10] = '\0'; break;}
  3418.                
  3419.                 new_password[count] = _getch();
  3420.        
  3421.                 if(new_password[count] == '\n' || new_password[count] == '\r')
  3422.                 {
  3423.                     new_password[count] = '\0';
  3424.                     break;
  3425.                 }
  3426.                
  3427.                 cout << "*";
  3428.                 count++;
  3429.             }
  3430.            
  3431.             system("CLS");
  3432.         } while(!isStringValid(new_password, CONST_PASSWORD_CHECK));
  3433.        
  3434.         char repeat_password[11];
  3435.        
  3436.         cout << "-> Repita a nova senha." << endl;
  3437.        
  3438.         int count = 0;
  3439.            
  3440.         writeInColor(" Senha", 9);
  3441.         cout << ": ";
  3442.  
  3443.         while(count <= 10)
  3444.         {      
  3445.             if(count == 10) {repeat_password[10] = '\0'; break;}
  3446.            
  3447.             repeat_password[count] = _getch();
  3448.            
  3449.             if(repeat_password[count] == '\n' || repeat_password[count] == '\r')
  3450.             {
  3451.                 repeat_password[count] = '\0';
  3452.                 break;
  3453.             }
  3454.            
  3455.             cout << "*";
  3456.             count++;
  3457.         }
  3458.        
  3459.         same_passwords = strcmp(new_password, repeat_password) == 0 ? true : false;
  3460.         system("CLS");
  3461.     } while(!same_passwords);
  3462.    
  3463.     updateAccount(login, 4, new_password, false);
  3464.    
  3465.     cout << "-> Senha alterada com sucesso!" << endl << endl;
  3466.     cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
  3467.     _getch();
  3468. }
  3469.  
  3470. void showFullRegister(int access)
  3471. {
  3472.     int total = getFileLineCount("cop_data.txt"), count = 0;
  3473.     file.open("cop_data.txt");
  3474.     char line[2000], *login[total];
  3475.    
  3476.     while(file.getline(line, 2000))
  3477.     {
  3478.         int i[getIndexesSize(line, '/')];
  3479.         getIndexesBySplittingSentence(line, '/', i);
  3480.        
  3481.         int login_size = i[3] - i[2] - 1;
  3482.         char login_now[login_size];
  3483.  
  3484.         fillSentence(line, i[2], i[3], login_now);
  3485.        
  3486.         login[count] = new char[login_size];
  3487.         strcpy(login[count], login_now);
  3488.         count++;   
  3489.     }
  3490.        
  3491.     file.close();
  3492.    
  3493.     if(total == 0)
  3494.         cout << "Não há registro de policiais no sistema." << endl << endl;
  3495.     else
  3496.     {
  3497.         char to_ch[5];
  3498.        
  3499.         itoa(total, to_ch, 10);
  3500.        
  3501.         cout << "  (";
  3502.         writeInColor(to_ch, 9);
  3503.         cout << ") registro(s) no sistema." << endl << endl;
  3504.        
  3505.         printByArray(login, total, access, false);
  3506.     }
  3507.    
  3508.     cout << "-> Pressione qualquer tecla para voltar ao menu anterior." << endl;
  3509.     _getch();
  3510. }
  3511.  
  3512. void showFullVillainRegister()
  3513. {
  3514.     int total = getFileLineCount("bad_data.txt"), count = 0;
  3515.     int ID[total];
  3516.     file.open("bad_data.txt");
  3517.     char line[2000];   
  3518.    
  3519.     while(file.getline(line, 2000))
  3520.     {
  3521.         int i[getIndexesSize(line, '/')];
  3522.         getIndexesBySplittingSentence(line, '/', i);
  3523.        
  3524.         int ID_size = i[1] - i[0] - 1;
  3525.         char ID_now[ID_size];
  3526.  
  3527.         fillSentence(line, i[0], i[1], ID_now);
  3528.        
  3529.         ID[count] = atoi(ID_now);
  3530.         count++;
  3531.     }  
  3532.    
  3533.     file.close();
  3534.    
  3535.     if(total == 0)
  3536.         cout << "Não há registro de criminosos." << endl << endl;
  3537.     else
  3538.     {
  3539.         char n[3];
  3540.        
  3541.         itoa(count, n, 10);
  3542.         cout << "  (";
  3543.         writeInColor(n, 9);
  3544.         cout << ") registro(s) de criminoso(s)." << endl << endl;
  3545.        
  3546.         printByBadArray(ID, total);
  3547.     }
  3548.    
  3549.     cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
  3550.     _getch();
  3551. }
  3552.  
  3553. bool isIDValid(int ID)
  3554. {
  3555.     char line[2000];
  3556.    
  3557.     ifstream file_now("bad_data.txt");
  3558.        
  3559.     while(file_now.getline(line, 2000))
  3560.     {
  3561.         int i[getIndexesSize(line, '/')];
  3562.         getIndexesBySplittingSentence(line, '/', i);
  3563.        
  3564.         int ID_size = i[1] - i[0] - 1, cmp_ID;
  3565.         char ID_now[ID_size];
  3566.  
  3567.         fillSentence(line, i[0], i[1], ID_now);
  3568.        
  3569.         cmp_ID = atoi(ID_now);
  3570.        
  3571.         if(cmp_ID == ID)
  3572.         {
  3573.             file_now.close();
  3574.             return false;
  3575.         }
  3576.     }
  3577.  
  3578.     file_now.close();
  3579.    
  3580.     return true;
  3581. }
  3582.  
  3583. void getOldLine(char get_line[])
  3584. {
  3585.     int resp, cmpID = 0;
  3586.     char line[2000];
  3587.    
  3588.     ifstream file_tmp("bad_data.txt");
  3589.    
  3590.     cout << "-> O criminoso em questão possui um número de identifição?" << endl;
  3591.     resp = getYesOrNo();
  3592.    
  3593.     if(resp == 0)
  3594.     {
  3595.         do
  3596.         {
  3597.             bool check_ID = true;
  3598.            
  3599.             do
  3600.             {
  3601.                 if(!check_ID)
  3602.                     cout << "Identifição inválida. Por favor, reentre com esta informação." << endl << endl;
  3603.                
  3604.                 cout << "-> Entre com a identificação." << endl;
  3605.                 writeInColor(" ID", 9);
  3606.                 cout << ": ";
  3607.                
  3608.                 cin >> cmpID;
  3609.                 check_ID = false;
  3610.                 system("CLS");
  3611.             } while(cmpID <= 0);
  3612.            
  3613.             cout << "Identifição registrada: " << cmpID << endl << endl;
  3614.             cout << "Esta identificação está correta?" << endl;
  3615.             resp = getYesOrNo();
  3616.             system("CLS");
  3617.            
  3618.         } while(resp == 1);
  3619.        
  3620.         while(file_tmp.getline(line, 2000))
  3621.         {
  3622.             int i[getIndexesSize(line, '/')];
  3623.             getIndexesBySplittingSentence(line, '/', i);
  3624.            
  3625.             int ID_size = i[1] - i[0] - 1, ID_to_number;
  3626.             char ID_now[ID_size];
  3627.    
  3628.             fillSentence(line, i[0], i[1], ID_now);
  3629.            
  3630.             ID_to_number = atoi(ID_now);
  3631.        
  3632.             if(ID_to_number == cmpID)
  3633.             {
  3634.                 strcpy(get_line, line);
  3635.                 break;
  3636.             }
  3637.         }
  3638.     }
  3639.     else
  3640.     {
  3641.         int line_count = 0, count = 0, wanted_line, all_options[getFileLineCount("bad_data.txt")];
  3642.        
  3643.         while(file_tmp.getline(line, 2000))
  3644.         {
  3645.             line_count++;
  3646.             int i[getIndexesSize(line, '/')];
  3647.             getIndexesBySplittingSentence(line, '/', i);
  3648.            
  3649.             int ID_size = i[1] - i[0] - 1, ID_to_number;
  3650.             char ID_now[ID_size];
  3651.    
  3652.             fillSentence(line, i[0], i[1], ID_now);
  3653.            
  3654.             ID_to_number = atoi(ID_now);
  3655.        
  3656.             if(ID_to_number <= 0)
  3657.             {
  3658.                 char n[3];
  3659.                
  3660.                 itoa(line_count, n, 10);
  3661.                 cout << "  OPÇÃO (";
  3662.                 writeInColor(n, 9);
  3663.                 cout << "): " << endl;
  3664.                 all_options[count++] = line_count;
  3665.                 printBadInfoAbout(ID_to_number);
  3666.             }
  3667.         }
  3668.        
  3669.         cout << "-> Entre com a opção desejada." << endl;
  3670.        
  3671.         int file_size = getFileLineCount("bad_data.txt");
  3672.        
  3673.         do
  3674.         {
  3675.             bool check_line = true;
  3676.            
  3677.             do
  3678.             {
  3679.                 if(!check_line)
  3680.                 {
  3681.                     cout << "-> Opção inválida." << endl;
  3682.                     cout << " Opções: " << endl << " ";
  3683.                    
  3684.                     for(int i = 0; i < count; i++)
  3685.                     {
  3686.                         cout << all_options[i];
  3687.                        
  3688.                         if(i != count - 1)
  3689.                             cout << ", ";
  3690.                     }
  3691.                    
  3692.                     cout << "." << endl << endl;
  3693.                 }
  3694.                
  3695.                 writeInColor(" Opção", 9);
  3696.                 cout << ": ";
  3697.                 cin >> wanted_line;
  3698.                 check_line = false;
  3699.                 system("CLS");
  3700.             } while(wanted_line <= 0 || wanted_line > file_size || !isInArray(all_options, count, wanted_line));
  3701.            
  3702.             cout << "Opção escolhida: " << wanted_line << endl << endl;
  3703.             cout << "Esta informação está correta?" << endl;
  3704.             resp = getYesOrNo();
  3705.            
  3706.         } while(resp == 1);
  3707.        
  3708.         file_tmp.close();
  3709.         file_tmp.open("bad_data.txt");
  3710.        
  3711.         line_count = 0;
  3712.        
  3713.         while(file_tmp.getline(line, 2000))
  3714.         {
  3715.             line_count++;
  3716.             if(line_count == wanted_line)
  3717.             {
  3718.                 strcpy(get_line, line);
  3719.                 break;
  3720.             }
  3721.         }
  3722.     }
  3723.    
  3724.     file_tmp.close();
  3725. }
  3726.  
  3727. void updateStatus()
  3728. {
  3729.     char old_line[2000];
  3730.     getOldLine(old_line);
  3731.    
  3732.     cout << "-> Entre com o novo estado do criminoso." << endl;
  3733.     writeColorInfo("0");
  3734.     cout << " - Preso" << endl;
  3735.     writeColorInfo("1");
  3736.     cout << " - Foragido" << endl;
  3737.     writeColorInfo("2");
  3738.     cout << " - Livre" << endl;
  3739.     writeColorInfo("3");
  3740.     cout << " - Condicional" << endl;
  3741.     writeColorInfo("4");
  3742.     cout << " - Morto" << endl << endl;
  3743.    
  3744.     int input_status, resp;
  3745.     bool check_status = false;
  3746.    
  3747.     do
  3748.     {
  3749.         do
  3750.         {
  3751.             if(check_status)
  3752.                 cout << "Estado inválido." << endl << endl;
  3753.            
  3754.             writeInColor(" Status", 9);
  3755.             cout << ": ";
  3756.             cin >> input_status;
  3757.             check_status = true;
  3758.             system("CLS");
  3759.         } while(input_status < 0 || input_status > 4);
  3760.        
  3761.         cout << "Estado escolhido: " << input_status << endl << endl;
  3762.         cout << "Esta informação está correta?" << endl;
  3763.         resp = getYesOrNo();
  3764.     } while(resp == 1);
  3765.    
  3766.     int ID = 0;
  3767.    
  3768.     if(input_status == 0)
  3769.     {
  3770.         cout << "-> Qual a identificação do prisioneiro?" << endl << endl;
  3771.    
  3772.         do
  3773.         {
  3774.             bool check_ID = true;
  3775.            
  3776.             do
  3777.             {
  3778.                 if(!check_ID)
  3779.                     cout << "Identifição inválida ou repetida. Por favor, reentre com esta informação." << endl << endl;
  3780.                
  3781.                 writeInColor(" ID", 9);
  3782.                 cout << ": ";
  3783.                
  3784.                 cin >> ID;
  3785.                 check_ID = false;
  3786.                 system("CLS");
  3787.             } while(ID <= 0 || !isIDValid(ID));
  3788.            
  3789.             cout << "-> Identifição registrada: " << ID << endl << endl;
  3790.             cout << "Esta identificação está correta?" << endl;
  3791.             resp = getYesOrNo();
  3792.             system("CLS");
  3793.         } while(resp == 1);
  3794.        
  3795.     }
  3796.    
  3797.     char v[2];
  3798.     itoa(input_status, v, 10);
  3799.    
  3800.     updateBadLine(old_line, 12, v, ID);
  3801.    
  3802.     cout << "  -> Atualização completa!" << endl << endl;
  3803.     cout << "O estado deste criminoso foi atualizado com sucesso." << endl;
  3804.     cout << "Pressione qualquer tecla para continuar." << endl;
  3805.     getch();
  3806. }
  3807.  
  3808. void updateAge()
  3809. {
  3810.     char old_line[2000];
  3811.     getOldLine(old_line);
  3812.    
  3813.     int resp, age;
  3814.    
  3815.     do
  3816.     {
  3817.         bool check_age = true;
  3818.        
  3819.         do
  3820.         {
  3821.             if(!check_age)
  3822.                 cout << "Idade inválida. Por gentileza, reentre com o dado correto." << endl << endl;
  3823.            
  3824.             cout << "-> Entre com a nova idade." << endl;  
  3825.             writeInColor(" Idade", 9);
  3826.             cout << ": ";
  3827.            
  3828.             cin >> age;
  3829.             check_age = false;
  3830.             system("CLS");
  3831.         } while(age <= 0);
  3832.        
  3833.         cout << "Idade registrada: " << age << endl;
  3834.         cout << "Esta idade está correta?" << endl;
  3835.         resp = getYesOrNo();
  3836.         system("CLS");
  3837.        
  3838.     } while(resp == 1);
  3839.    
  3840.     char v[1000];
  3841.     itoa(age, v, 10);
  3842.    
  3843.     updateBadLine(old_line, 6, v, 0);
  3844.    
  3845.     cout << "  -> Atualização completa!" << endl << endl;
  3846.     cout << "A idade deste criminoso foi atualizada com sucesso." << endl;
  3847.     cout << "Pressione qualquer tecla para continuar." << endl;
  3848.     getch();
  3849. }
  3850.  
  3851. void updateExtra()
  3852. {
  3853.     char old_line[2000], extra[51];
  3854.     getOldLine(old_line);
  3855.    
  3856.     cout << "-> Entre com a nova informação extra." << endl;
  3857.    
  3858.     int resp;
  3859.        
  3860.     do
  3861.     {
  3862.         cin.ignore();
  3863.         bool check_extra = true;
  3864.    
  3865.         cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
  3866.        
  3867.         do
  3868.         {
  3869.             if(!check_extra)
  3870.                 cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
  3871.            
  3872.             writeInColor(" Extra", 9);
  3873.             cout << ": ";
  3874.            
  3875.             cin.getline(extra, 51);
  3876.             check_extra = false;
  3877.             system("CLS");
  3878.         } while(!isStringValid(extra, CONST_SPECIFIC_CHECK));
  3879.        
  3880.         cout << "Informação extra registrada: " << extra << endl;
  3881.         cout << "Esta informação está correta?" << endl;
  3882.         resp = getYesOrNo();
  3883.         system("CLS");
  3884.        
  3885.     } while(resp == 1);
  3886.    
  3887.     updateBadLine(old_line, 14, extra, 0);
  3888.    
  3889.     cout << "  -> Atualização completa!" << endl << endl;
  3890.     cout << "A informação adicional deste criminoso foi atualizada com sucesso." << endl;
  3891.     cout << "Pressione qualquer tecla para continuar." << endl;
  3892.     getch();
  3893. }
  3894.  
  3895. void updateBadLine(const char* input_line, int start, const char* new_input, int new_ID)
  3896. {
  3897.     char old_line[2000], line[2000];
  3898.     strcpy(old_line, input_line);
  3899.    
  3900.     ifstream file_now("bad_data.txt");
  3901.     out_file.open("tmp.txt", ios_base::app | ios_base::out);
  3902.    
  3903.     while(file_now.getline(line, 2000))
  3904.     {
  3905.         if(strcmp(line, old_line) != 0)
  3906.             out_file << line << endl;
  3907.     }
  3908.    
  3909.     file_now.close();
  3910.     out_file.close();
  3911.     remove("bad_data.txt");
  3912.     rename("tmp.txt", "bad_data.txt");
  3913.    
  3914.     int i[getIndexesSize(old_line, '/')];
  3915.     getIndexesBySplittingSentence(old_line, '/', i);
  3916.    
  3917.     int ID_size = i[1] - i[0] - 1, name_size = i[3] - i[2] - 1, nick_size = i[5] - i[4] - 1, age_size = i[7] - i[6] - 1;
  3918.     int art_size = i[9] - i[8] - 1, specific_size = i[11] - i[10] - 1, status_size = i[13] - i[12] - 1, extra_size = i[15] - i[14] - 1;
  3919.    
  3920.     char get_ID[ID_size], name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
  3921.     char status[status_size], extra[extra_size];
  3922.        
  3923.     fillSentence(old_line, i[0], i[1], get_ID);
  3924.     fillSentence(old_line, i[2], i[3], name);
  3925.     fillSentence(old_line, i[4], i[5], nick);
  3926.     fillSentence(old_line, i[6], i[7], age);
  3927.     fillSentence(old_line, i[8], i[9], art);
  3928.     fillSentence(old_line, i[10], i[11], specific);
  3929.     fillSentence(old_line, i[12], i[13], status);
  3930.     fillSentence(old_line, i[14], i[15], extra);
  3931.    
  3932.     Villain new_info;
  3933.    
  3934.     if(new_ID != 0)
  3935.         new_info.ID = new_ID;
  3936.     else
  3937.         new_info.ID = atoi(get_ID);
  3938.    
  3939.     if(start == 6)
  3940.         new_info.age = atoi(new_input);
  3941.     else
  3942.         new_info.age = atoi(age);
  3943.    
  3944.     if(start == 12)
  3945.         new_info.status = atoi(new_input);
  3946.     else
  3947.         new_info.status = atoi(status);
  3948.  
  3949.     if(start == 14)
  3950.         strcpy(new_info.extra, new_input);
  3951.     else
  3952.         strcpy(new_info.extra, extra);
  3953.  
  3954.     strcpy(new_info.name, name);
  3955.     strcpy(new_info.nickname, nick);
  3956.     strcpy(new_info.art, art);
  3957.     strcpy(new_info.specific, specific);
  3958.    
  3959.     new_info.writeIntoBadFile();
  3960. }
  3961.  
  3962. Villain getVillainInfo(int ID)
  3963. {
  3964.     Villain ret;
  3965.    
  3966.     ret.ID = ID;
  3967.    
  3968.     ifstream file_now("bad_data.txt");
  3969.     char line[2000];
  3970.    
  3971.     while(file_now.getline(line, 2000))
  3972.     {
  3973.         int i[getIndexesSize(line, '/')];
  3974.         getIndexesBySplittingSentence(line, '/', i);
  3975.        
  3976.         int ID_size = i[1] - i[0] - 1, cmp_ID;
  3977.         char ID_now[ID_size];
  3978.  
  3979.         fillSentence(line, i[0], i[1], ID_now);
  3980.        
  3981.         cmp_ID = atoi(ID_now);
  3982.    
  3983.         if(cmp_ID == ID)
  3984.         {
  3985.             int name_size = i[3] - i[2] - 1, nick_size = i[5] - i[4] - 1, age_size = i[7] - i[6] - 1;
  3986.             int art_size = i[9] - i[8] - 1, specific_size = i[11] - i[10] - 1, status_size = i[13] - i[12] - 1, extra_size = i[15] - i[14] - 1;
  3987.            
  3988.             char name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
  3989.             char status[status_size], extra[extra_size];
  3990.            
  3991.             fillSentence(line, i[2], i[3], name);
  3992.             fillSentence(line, i[4], i[5], nick);
  3993.             fillSentence(line, i[6], i[7], age);
  3994.             fillSentence(line, i[8], i[9], art);
  3995.             fillSentence(line, i[10], i[11], specific);
  3996.             fillSentence(line, i[12], i[13], status);
  3997.             fillSentence(line, i[14], i[15], extra);
  3998.            
  3999.             strcpy(ret.name, name);
  4000.             strcpy(ret.nickname, nick);
  4001.             ret.age = atoi(age);
  4002.             strcpy(ret.art, art);
  4003.             strcpy(ret.specific, specific);
  4004.             ret.status = atoi(status);
  4005.             strcpy(ret.extra, extra);
  4006.            
  4007.             break;
  4008.         }
  4009.     }
  4010.    
  4011.     file_now.close();
  4012.    
  4013.     return ret;
  4014. }
  4015.  
  4016. void printBadInfoAbout(int ID)
  4017. {
  4018.     ifstream file_now("bad_data.txt");
  4019.     char line[2000];
  4020.    
  4021.     while(file_now.getline(line, 2000))
  4022.     {
  4023.         int i[getIndexesSize(line, '/')];
  4024.         getIndexesBySplittingSentence(line, '/', i);
  4025.        
  4026.         int ID_size = i[1] - i[0] - 1, cmp_ID;
  4027.         char ID_now[ID_size];
  4028.  
  4029.         fillSentence(line, i[0], i[1], ID_now);
  4030.        
  4031.         cmp_ID = atoi(ID_now);
  4032.    
  4033.         if(cmp_ID == ID)
  4034.         {
  4035.             int name_size = i[3] - i[2] - 1, nick_size = i[5] - i[4] - 1, age_size = i[7] - i[6] - 1;
  4036.             int art_size = i[9] - i[8] - 1, specific_size = i[11] - i[10] - 1, status_size = i[13] - i[12] - 1, extra_size = i[15] - i[14] - 1;
  4037.            
  4038.             char name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
  4039.             char status[status_size], extra[extra_size];
  4040.            
  4041.             fillSentence(line, i[2], i[3], name);
  4042.             fillSentence(line, i[4], i[5], nick);
  4043.             fillSentence(line, i[6], i[7], age);
  4044.             fillSentence(line, i[8], i[9], art);
  4045.             fillSentence(line, i[10], i[11], specific);
  4046.             fillSentence(line, i[12], i[13], status);
  4047.             fillSentence(line, i[14], i[15], extra);
  4048.    
  4049.             if(strcmp(name, "-1") == 0)
  4050.                 cout << "  -> Nome: desconhecido." << endl;
  4051.             else
  4052.                 cout << "  -> Nome: " << name << endl;
  4053.            
  4054.             if(strcmp(nick, "-1") == 0)
  4055.                 cout << "  -> Apelido: desconhecido." << endl;
  4056.             else
  4057.                 cout << "  -> Apelido: " << nick << endl;
  4058.            
  4059.             if(ID > 0)
  4060.                 cout << "  -> ID: " << ID << endl;
  4061.            
  4062.             if(atoi(age) == -1)
  4063.                 cout << "  -> Idade: desconhecida." << endl;
  4064.             else
  4065.                 cout << "  -> Idade: " << age << endl;
  4066.            
  4067.             if(strcmp(art, "outro") != 0)
  4068.             {
  4069.                 cout << "  -> Artigo: ";
  4070.                 getArt(atoi(art), false);
  4071.                 cout << "." << endl;
  4072.             }
  4073.             else
  4074.             {
  4075.                 cout << "  -> Artigo: outro." << endl;
  4076.                 cout << "  -> Especificação: " << specific << endl;
  4077.             }
  4078.            
  4079.             cout << "  -> Status: ";
  4080.             switch(atoi(status))
  4081.             {
  4082.                 case 0:
  4083.                     writeInColor("preso", 4);
  4084.                     break;
  4085.                 case 1:
  4086.                     writeInColor("foragido", 4);
  4087.                     break;
  4088.                 case 2:
  4089.                     writeInColor("livre", 4);
  4090.                     break;
  4091.                 case 3:
  4092.                     writeInColor("em condicional", 4);
  4093.                     break;
  4094.                 case 4:
  4095.                     writeInColor("morto", 4);
  4096.                     break;
  4097.             }
  4098.            
  4099.             cout << "." << endl;
  4100.        
  4101.             cout << "  -> Informação extra: " << extra << endl << endl;
  4102.             break;
  4103.         }
  4104.     }
  4105.    
  4106.     file_now.close();
  4107. }
  4108.  
  4109. int getIndexesSize(char* line, char split_character)
  4110. {
  4111.     int size = strlen(line) + 1, count = 0;
  4112.     bool continue_func = false;
  4113.    
  4114.     for(unsigned int i = 0; i < strlen(line); i++)
  4115.     {
  4116.         if(line[i] == split_character)
  4117.         {
  4118.             continue_func = true;
  4119.             break;
  4120.         }
  4121.     }
  4122.        
  4123.     if(!continue_func) return count;
  4124.    
  4125.     if(line[0] != split_character && line[strlen(line)] != split_character)
  4126.         size += 2;
  4127.    
  4128.     char working_on[size];
  4129.    
  4130.     if((unsigned int) size == strlen(line) + 1)
  4131.         strcpy(working_on, line);
  4132.     else
  4133.     {
  4134.         working_on[0] = ' ';
  4135.         working_on[size - 2] = ' ';
  4136.        
  4137.         for(int k = 1; k < size - 2; k++)
  4138.             working_on[k] = line[k - 1];
  4139.        
  4140.         working_on[size - 1] = '\0';
  4141.        
  4142.     }
  4143.    
  4144.     for(unsigned int i = 0; i <= strlen(working_on); i++)
  4145.         if(working_on[i] == split_character)
  4146.             count++;
  4147.        
  4148.     return count;
  4149. }
  4150.  
  4151. void SetColor(int ForgC)
  4152. {
  4153.     WORD wColor;
  4154.    
  4155.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  4156.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  4157.    
  4158.     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  4159.     {
  4160.         wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
  4161.         SetConsoleTextAttribute(hStdOut, wColor);
  4162.     }
  4163.    
  4164.     return;
  4165. }
  4166.  
  4167. void writeInColor(const char* phrase, int color)
  4168. {
  4169.     SetColor(color);
  4170.     cout << phrase;
  4171.     SetColor(0);
  4172. }
  4173.  
  4174. void getIndexesBySplittingSentence(char* line, char split_character, int j[])
  4175. {  
  4176.     int size = strlen(line) + 1, count = 0;
  4177.    
  4178.     if(line[0] != split_character && line[strlen(line)] != split_character && split_character == ' ')
  4179.         size += 2;
  4180.    
  4181.     char working_on[size];
  4182.    
  4183.     if((unsigned int) size == strlen(line) + 1)
  4184.         strcpy(working_on, line);
  4185.     else
  4186.     {
  4187.         working_on[0] = ' ';
  4188.         working_on[size - 1] = ' ';
  4189.        
  4190.         for(int k = 1; k < size - 2; k++)
  4191.             working_on[k] = line[k - 1];
  4192.        
  4193.         working_on[size] = '\0';
  4194.     }
  4195.    
  4196.     for(unsigned int i = 0; i <= strlen(working_on); i++)
  4197.         if(working_on[i] == split_character)
  4198.             j[count++] = i;
  4199.  
  4200. }
  4201.  
  4202. void adjustName(char name[])
  4203. {
  4204.     int size = getIndexesSize(name, ' ');
  4205.     cout << "";
  4206.    
  4207.     if(size == 0)
  4208.         name[0] = toupper(name[0]);
  4209.     else
  4210.     {
  4211.         int index[size];
  4212.         getIndexesBySplittingSentence(name, ' ', index);
  4213.        
  4214.         for(int i = 0; i < size - 1; i++)
  4215.         {
  4216.             int size = i[index + 1] - i[index] - 1, count = 0;
  4217.             char part[size];
  4218.            
  4219.             for(int j = index[i]; j < index[i + 1]; j++)
  4220.                 part[count++] = name[j];
  4221.            
  4222.             part[sizeof(part)] = '\0';
  4223.            
  4224.             if(strcmp(part, "de") != 0 && strcmp(part, "do") != 0 && strcmp(part, "a") != 0 && strcmp(part, "da") != 0 && strcmp(part, "di") != 0 && strcmp(part, "du") != 0)
  4225.                 name[index[i]] = toupper(name[index[i]]);
  4226.            
  4227.         }
  4228.     }
  4229. }
  4230.  
  4231. void toLower(char w[])
  4232. {
  4233.     for(unsigned int i = 0; i < strlen(w); i++)
  4234.         w[i] = tolower(w[i]);
  4235. }
  4236.  
  4237. bool checkCombination(char login[], char password[])
  4238. {
  4239.     bool var;
  4240.    
  4241.     Cop info = getAccountInfo(login);
  4242.    
  4243.     var = strcmp(info.password, password) == 0 ? true : false;
  4244.    
  4245.     return var;
  4246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement