Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <fstream>
- #include <ctime>
- #include <ctype.h>
- #include <cstdlib>
- #include <conio.h>
- #include <time.h>
- #include <windows.h>
- #include <locale.h>
- enum {
- CONST_ART_CHECK,
- CONST_NAME_CHECK,
- CONST_SPECIFIC_CHECK,
- CONST_CPF_CHECK,
- CONST_LOGIN_CHECK,
- CONST_PASSWORD_CHECK
- };
- using namespace std;
- bool edit, pendent, logon;
- ifstream file;
- ofstream out_file;
- struct Register {
- 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];
- int day, month, year, gun_day, gun_month, gun_year, status;
- void writeIntoFile();
- };
- struct Cop {
- char name[1000], login[13], password[11], job[100], CPF[15], key[8], birth_date[11], gun[11];
- int age, access, status;
- };
- struct Villain {
- int age, status, ID;
- char name[1000], nickname[1000], art[6], specific[51], extra[51];
- void writeIntoBadFile();
- };
- void getIndexesBySplittingSentence(char* line, char split_character, int j[]);
- int getIndexesSize(char* line, char split_character);
- void SetColor(int ForgC);
- void writeInColor(const char* phrase, int color);
- void adjustName(char name[]);
- void toLower(char w[]);
- bool isInUse(char login[]);
- int getNameOccurrences(char name[]);
- int getAccessLevel(const char* vocation);
- void correctAndTransferCPF(char CPF[], char old_CPF[]);
- void deleteAccount(const char* login);
- int getFileLineCount(const char* file);
- void RegisterCop();
- void RegisterVillain();
- void openWebsite(const char* website);
- void printByBadArray(int ID[], int count);
- void printBadInfoAbout(int ID);
- void printInfoAbout(char login[], int access, bool yourself, bool show_new_job);
- void printByArray(char *array[], int count, int access, bool show_new_job);
- void lookForID();
- void lookForArt();
- void lookForStatus();
- void lookForAge(int access);
- void lookForJob(int access);
- void lookForName(int access);
- int getYesOrNo();
- void fillSentence(char line[], int begin, int end, char target[]);
- bool compareTwoStrings(char str1[], char str2[]);
- void showInfosAboutName(char name[], int access);
- void writeColorInfo(const char* art);
- bool isInArray(int array[], int size, int element);
- Villain getVillainInfo(int ID);
- Cop getAccountInfo(char input_login[]);
- void getArt(int art, bool open_site);
- void updateStatus();
- void updateAge();
- void updateExtra();
- void updateBadLine(const char* line, int start, const char* new_info, int new_ID);
- bool isIDValid(int ID);
- void showFullVillainRegister();
- void showFullRegister(int access);
- void changePassword(char login[]);
- void changeCargo(char login[]);
- void changeDate(char login[]);
- void executeDeletion(int access, char login[]);
- void showPendentJobs(int count, bool admin);
- void showPendentAccounts(int count, bool admin);
- void generateSecurityKey(char key[]);
- void recoverAccount();
- bool isCPFInUse(char CPF[]);
- int getAccessLevel(const char * vocation);
- void createAdminAccount();
- bool isStringValid(char str[], int check_type);
- void updateAccount(char login[], int start, char new_value[], bool admin);
- void getOldLine(char get_line[]);
- bool checkCombination(char login[], char password[]);
- int getPendentJobSolicitations();
- int getPendentAdmissions();
- int main()
- {
- bool _time = true;
- setlocale(LC_ALL, "Portuguese");
- bool program_running = true;
- system("color F0");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << "************** BEM VINDO AO SISTEMA DE CONTROLE POLICIAL **************" << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- if(getFileLineCount("cop_data.txt") == 0) createAdminAccount();
- while(program_running)
- {
- if(!_time) system("CLS");
- char action[10];
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> ";
- writeInColor("registrar ", 9);
- cout << "no sistema" << endl;
- cout << " -> ";
- writeInColor("logar ", 9);
- cout << "no sistema" << endl;
- cout << " -> ";
- writeInColor("recuperar ", 9);
- cout << "sua senha" << endl;
- cout << " -> ";
- writeInColor("saber ", 9);
- cout << "mais sobre o Sistema de Controle Policial" << endl;
- cout << " -> ";
- writeInColor("sair ", 9);
- cout << "para finalizar o sistema" << endl << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- _time = false;
- cin.getline(action, 10);
- toLower(action);
- system("CLS");
- if(strcmp(action, "registrar") == 0)
- RegisterCop();
- else if(strcmp(action, "logar") == 0)
- {
- bool continue_login = true, check_login = true;
- char login[13], password[11];
- do
- {
- int input;
- if(!check_login)
- {
- cout << "Combinação inválida. (login inexistente ou senha incorreta)" << endl << endl;
- cout << "Se você esqueceu sua senha, tente recuperá-la através de nosso método por chave de segurança." << endl;
- cout << "Deseja voltar ao menu de opções?" << endl;
- input = getYesOrNo();
- if(input == 0)
- {
- continue_login = false;
- break;
- }
- cin.ignore();
- }
- cout << "-----------------------------" << endl;
- cout << "********** LOGANDO **********" << endl;
- cout << "-----------------------------" << endl << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin.getline(login, 13);
- writeInColor(" Senha", 9);
- cout << ": ";
- int count = 0;
- while(count <= 10)
- {
- if(count == 10) {password[10] = '\0'; break;}
- password[count] = _getch();
- if(password[count] == '\n' || password[count] == '\r')
- {
- password[count] = '\0';
- break;
- }
- cout << "*";
- count++;
- }
- system("CLS");
- check_login = false;
- } while(!checkCombination(login, password));
- if(continue_login)
- {
- Cop data = getAccountInfo(login);
- if(data.status == -1)
- {
- cout << "Esta conta ainda não foi ativada em nosso sistema. Por gentileza, aguarde até um oficial autorizá-la.";
- cout << endl << endl << "Pressione qualquer tecla para voltar ao menu de opções." << endl;
- getch();
- system("CLS");
- }
- else
- {
- char new_action[10];
- logon = true;
- time_t t = time(NULL);
- tm* timePtr = localtime(&t);
- int k[getIndexesSize(data.birth_date, '-')];
- getIndexesBySplittingSentence(data.birth_date, '-', k);
- char day_str[3], mon_str[3], year_str[5];
- fillSentence(data.birth_date, -1, k[0], day_str);
- fillSentence(data.birth_date, k[0], k[1], mon_str);
- fillSentence(data.birth_date, k[1], strlen(data.birth_date), year_str);
- int day = atoi(day_str), month = atoi(mon_str), year = atoi(year_str);
- if(timePtr->tm_mday == day && timePtr->tm_mon + 1 == month)
- cout << "FELIZ ANIVERSÁRIO, " << data.name << "!" << endl << endl;
- else
- {
- if(timePtr->tm_hour >= 19 || timePtr->tm_hour < 6)
- cout << "Boa noite, ";
- else if(timePtr->tm_hour >= 6 || timePtr->tm_hour < 12)
- cout << "Bom dia, ";
- else
- cout << "Boa tarde, ";
- cout << data.name << "." << endl << endl;
- }
- int g[getIndexesSize(data.gun, '-')];
- getIndexesBySplittingSentence(data.gun, '-', g);
- int gday_size = g[0], gmon_size = g[1] - g[0] - 1, gyear_size = strlen(data.gun) - g[1] - 1;
- char gday_str[gday_size], gmon_str[gmon_size], gyear_str[gyear_size];
- fillSentence(data.gun, -1, g[0], gday_str);
- fillSentence(data.gun, g[0], g[1], gmon_str);
- fillSentence(data.gun, g[1], strlen(data.gun), gyear_str);
- day = atoi(gday_str);
- month = atoi(gmon_str);
- year = atoi(gyear_str);
- int time_diff = (year + 5) - (timePtr->tm_year + 1900);
- if(time_diff <= 1)
- {
- if(timePtr->tm_mday > day && timePtr->tm_mon + 1 >= month)
- 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;
- else if(month - timePtr->tm_mon + 1 <= 6)
- 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;
- }
- bool new_time = true;
- while(logon)
- {
- data = getAccountInfo(login);
- if(!new_time) system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> ";
- writeInColor("policia ", 9);
- cout << "para verificar o banco de dados policial" << endl;
- cout << " -> ";
- writeInColor("criminoso ", 9);
- cout << "para verificar o banco de dados de criminosos" << endl;
- cout << " -> ";
- writeInColor("pessoal ", 9);
- cout << "para verificar suas informações pessoais" << endl;
- if(strcmp(data.key, "-1") == 0)
- {
- cout << " -> ";
- writeInColor("chave ", 9);
- cout << "para gerar uma chave de segurança" << endl;
- }
- if(data.access > 9)
- {
- cout << " -> ";
- writeInColor("pendente ", 9);
- cout << "para checar as autorizações pendentes no sistema" << endl;
- }
- cout << " -> ";
- writeInColor("sair ", 9);
- cout << "para deslogar do sistema" << endl << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- new_time = false;
- cin.getline(new_action, 10);
- toLower(new_action);
- if(strcmp(new_action, "policia") == 0)
- {
- bool searching = true;
- char action_cop[9];
- while(searching)
- {
- system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> ";
- writeInColor("procurar ", 9);
- cout << "para procurar registro(s) no sistema" << endl;
- cout << " -> ";
- writeInColor("todos ", 9);
- cout << "para receber o registro policial completo do sistema" << endl;
- if(data.access > 9)
- {
- cout << " -> ";
- writeInColor("remover ", 9);
- cout << "para remover algum policial do sistema" << endl;
- }
- cout << " -> ";
- writeInColor("voltar ", 9);
- cout << "para voltar ao menu de opções" << endl << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(action_cop, 9);
- toLower(action_cop);
- system("CLS");
- if(strcmp(action_cop, "procurar") == 0)
- {
- int n_action;
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> (";
- writeInColor("1", 9);
- cout << ") para procurar por nome" << endl;
- cout << " -> (";
- writeInColor("2", 9);
- cout << ") para procurar por cargo" << endl;
- cout << " -> (";
- writeInColor("3", 9);
- cout << ") para procurar por idade" << endl << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin >> n_action;
- system("CLS");
- switch(n_action)
- {
- case 1:
- lookForName(data.access);
- break;
- case 2:
- lookForJob(data.access);
- break;
- case 3:
- lookForAge(data.access);
- break;
- default:
- cout << " Opção inválida." << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- }
- else if(strcmp(action_cop, "todos") == 0)
- showFullRegister(data.access);
- else if(strcmp(action_cop, "remover") == 0 && data.access > 9)
- executeDeletion(data.access, data.login);
- else if(strcmp(action_cop, "voltar") == 0) searching = false;
- }
- }
- else if(strcmp(new_action, "criminoso") == 0)
- {
- bool villain = true;
- char bad_action[10];
- while(villain)
- {
- system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> {";
- writeInColor("registrar", 4);
- cout << "} para registrar criminosos no sistema" << endl;
- cout << " -> {";
- writeInColor("procurar", 4);
- cout << "} para procurar por registro(s) de criminosos no sistema" << endl;
- cout << " -> {";
- writeInColor("todos", 4);
- cout << "} para ver o registro completo dos criminosos no sistema" << endl;
- cout << " -> {";
- writeInColor("atualizar", 4);
- cout << "} para atualizar registros de criminosos no sistema" << endl;
- cout << " -> {";
- writeInColor("voltar", 9);
- cout << "} para voltar ao menu de opcoes" << endl << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(bad_action, 10);
- toLower(bad_action);
- system("CLS");
- if(strcmp(bad_action, "registrar") == 0)
- RegisterVillain();
- else if(strcmp(bad_action, "procurar") == 0)
- {
- bool searching = true;
- char action_cop[9];
- while(searching)
- {
- system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> (";
- writeInColor("ID", 9);
- cout << ") para procurar por uma identificao especifica" << endl;
- cout << " -> (";
- writeInColor("artigo", 9);
- cout << ") para procurar por registro(s) de artigo especifico" << endl;
- cout << " -> (";
- writeInColor("estado", 9);
- cout << ") para procurar por registro(s) com estado especifico" << endl;
- cout << " -> (";
- writeInColor("voltar", 9);
- cout << ") para voltar ao menu anterior" << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(action_cop, 9);
- toLower(action_cop);
- if(strcmp(action_cop, "id") == 0)
- lookForID();
- else if(strcmp(action_cop, "artigo") == 0)
- lookForArt();
- else if(strcmp(action_cop, "estado") == 0)
- lookForStatus();
- else if(strcmp(action_cop, "voltar") == 0) searching = false;
- }
- }
- else if(strcmp(bad_action, "atualizar") == 0)
- {
- bool updating = true;
- char action_update[8];
- while(updating)
- {
- system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> (";
- writeInColor("status", 9);
- cout << ") para atualizar o estado do criminoso." << endl;
- cout << " -> (";
- writeInColor("idade", 9);
- cout << ") para atualizar a idade do criminoso." << endl;
- cout << " -> (";
- writeInColor("extra", 9);
- cout << ") para atualizar a informacao extra do criminoso." << endl;
- cout << " -> (";
- writeInColor("voltar", 9);
- cout << ") para voltar ao menu anterior" << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(action_update, 8);
- toLower(action_update);
- system("CLS");
- if(strcmp(action_update, "status") == 0)
- updateStatus();
- else if(strcmp(action_update, "idade") == 0)
- updateAge();
- else if(strcmp(action_update, "extra") == 0)
- updateExtra();
- else if(strcmp(action_update, "voltar") == 0) updating = false;
- }
- }
- else if(strcmp(bad_action, "todos") == 0)
- showFullVillainRegister();
- else if(strcmp(bad_action, "voltar") == 0) villain = false;
- }
- }
- else if(strcmp(new_action, "pessoal") == 0)
- {
- edit = true;
- char yourself[8];
- while(edit)
- {
- system("CLS");
- printInfoAbout(data.login, data.access, true, false);
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> (";
- writeInColor("senha", 9);
- cout << ") para mudar sua senha" << endl;
- cout << " -> (";
- writeInColor("cargo", 9);
- cout << ") para alterar seu cargo" << endl;
- cout << " -> (";
- writeInColor("data", 9);
- cout << ") para atualizar a data de emissão do documento de porte de arma" << endl;
- cout << " -> (";
- writeInColor("voltar", 9);
- cout << ") para voltar ao menu anterior" << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(yourself, 8);
- toLower(yourself);
- system("CLS");
- if(strcmp(yourself, "senha") == 0)
- changePassword(data.login);
- else if(strcmp(yourself, "cargo") == 0)
- changeCargo(data.login);
- else if(strcmp(yourself, "data") == 0)
- changeDate(data.login);
- else if(strcmp(yourself, "voltar") == 0) edit = false;
- }
- }
- else if(strcmp(new_action, "pendente") == 0 && data.access > 9)
- {
- pendent = true;
- char pendent_action[7];
- while(pendent)
- {
- system("CLS");
- cout << "-----------------------------------------------------------------------" << endl;
- cout << " ************* OPÇÕES DE AÇÃO *************" << endl << endl;
- cout << " -> (";
- writeInColor("cargo", 9);
- cout << ") para aprovar alterações pendentes de cargos" << endl;
- cout << " -> (";
- writeInColor("conta", 9);
- cout << ") para autorizar novas contas no sistema" << endl;
- cout << " -> (";
- writeInColor("voltar", 9);
- cout << ") para voltar ao menu anterior" << endl;
- cout << "-----------------------------------------------------------------------" << endl << endl;
- cin.getline(pendent_action, 7);
- toLower(pendent_action);
- if(strcmp(pendent_action, "cargo") == 0)
- {
- int pendent_job = getPendentJobSolicitations();
- system("CLS");
- if(pendent_job == 0)
- {
- cout << "-> Não há solicitações pendentes de mudança de cargo." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- _getch();
- }
- else
- showPendentJobs(pendent_job, data.status == 2 ? true : false);
- }
- else if(strcmp(pendent_action, "conta") == 0)
- {
- int pendent_account = getPendentAdmissions();
- system("CLS");
- if(pendent_account == 0)
- {
- cout << "-> Não há contas pendentes para admitir no sistema." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- _getch();
- }
- else
- showPendentAccounts(pendent_account, data.status == 2 ? true : false);
- }
- else if(strcmp(pendent_action, "voltar") == 0) pendent = false;
- }
- }
- else if(strcmp(new_action, "chave") == 0 && strcmp(data.key, "-1") == 0)
- {
- system("CLS");
- generateSecurityKey(data.key);
- cout << "-> Chave de segurança gerada. Guarde-a em segurança!" << endl;
- cout << "Sua chave: ";
- writeInColor(data.key, 9);
- cout << endl << endl;
- updateAccount(data.login, 6, data.key, false);
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- getch();
- }
- else if(strcmp(new_action, "sair") == 0) logon = false;
- }
- }
- }
- }
- else if(strcmp(action, "recuperar") == 0)
- recoverAccount();
- else if(strcmp(action, "saber") == 0)
- {
- int option;
- cout << "O ";
- writeInColor("Sistema de Controle Policial ", 9);
- cout << "é, como o próprio nome sugere, um sistema de controle e manipulação de informações referentes a Polícia Militar." << endl;
- cout << "Através de uma interface simples e prática, é possível, dentre várias funcionalidades:" << endl;
- cout << " --> controle da entrada de policiais" << endl;
- cout << " --> controle do banco de dados policial" << endl;
- cout << " --> controle do banco de dados criminal" << endl;
- cout << " --> alterações de cargo, requerindo-se permissão proveniente de patentes maiores" << endl;
- cout << " --> avisos antecedentes sobre a data de expiração do documento de porte de armas" << endl << endl;
- cout << "Para saber mais sobre a PM e artigos penais, você pode acessar os seguintes links:" << endl;
- cout << " -> (";
- writeInColor("1", 9);
- cout << ") Polícia Militar de Minas Gerais" << endl;
- cout << " -> (";
- writeInColor("2", 9);
- cout << ") Código Penal" << endl;
- cout << " -> (";
- writeInColor("3", 9);
- cout << ") Crime" << endl << endl;
- cout << "Se deseja voltar ao menu, entre com qualquer outro dígito." << endl << endl;
- cin >> option;
- switch(option)
- {
- case 1:
- openWebsite("https://www.policiamilitar.mg.gov.br/portal-pm/principal.action");
- break;
- case 2:
- openWebsite("http://www.planalto.gov.br/ccivil_03/decreto-lei/Del2848compilado.htm");
- break;
- case 3:
- openWebsite("https://pt.wikipedia.org/wiki/Crime");
- break;
- }
- }
- else if(strcmp(action, "sair") == 0) program_running = false;
- }
- }
- bool isInUse(char login[])
- {
- file.open("cop_data.txt");
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- if(strcmp(login_now, login) == 0)
- {
- file.close();
- return true;
- }
- }
- file.close();
- return false;
- }
- int getNameOccurrences(char name[])
- {
- file.open("cop_data.txt");
- char line[2000];
- int count_name = 0;
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int name_size = i[1] - i[0] - 1;
- char name_now[name_size];
- fillSentence(line, i[0], i[1], name_now);
- if(strcmp(name_now, name) == 0) count_name++;
- }
- file.close();
- return count_name;
- }
- int getAccessLevel(const char * vocation)
- {
- char lower[strlen(vocation) + 1];
- strcpy(lower, vocation);
- toLower(lower);
- if(strcmp(lower, "coronel") == 0)
- return 13;
- else if(strcmp(lower, "tenente-coronel") == 0)
- return 12;
- else if(strcmp(lower, "major") == 0)
- return 11;
- else if(strcmp(lower, "capitao") == 0)
- return 10;
- else if(strcmp(lower, "1 tenente") == 0)
- return 9;
- else if(strcmp(lower, "2 tenente") == 0)
- return 8;
- else if(strcmp(lower, "aspirante a oficial") == 0)
- return 7;
- else if(strcmp(lower, "subtenente") == 0)
- return 6;
- else if(strcmp(lower, "1 sargento") == 0)
- return 5;
- else if(strcmp(lower, "2 sargento") == 0)
- return 4;
- else if(strcmp(lower, "3 sargento") == 0)
- return 3;
- else if(strcmp(lower, "cabo") == 0)
- return 2;
- else if(strcmp(lower, "soldado") == 0)
- return 1;
- else
- return 0;
- }
- void correctAndTransferCPF(char CPF[], char old_CPF[])
- {
- int count = 0;
- for(int i = 0; i < 14; i++)
- {
- if(i == 3 || i == 7)
- CPF[i] = '.';
- else if(i == 11)
- CPF[i] = '-';
- else
- CPF[i] = old_CPF[count++];
- }
- CPF[14] = '\0';
- }
- void Register::writeIntoFile()
- {
- out_file.open("cop_data.txt", ios_base::app | ios_base::out);
- out_file << "Nome:/" << this->name << "/";
- out_file << "Login:/" << this->login << "/";
- out_file << "Senha:/" << this->password << "/";
- out_file << "Chave:/" << this->key << "/";
- out_file << "Nascimento:/" << this->d << "-" << this->m << "-" << this->y << "/";
- out_file << "Cargo:/" << this->job << "/";
- out_file << "Data de registro da arma:/" << this->dg << "-" << this->mg << "-" << this->yg << "/";
- out_file << "CPF:/" << this->CPF << "/";
- out_file << "Status:/" << this->status << "/" << endl;
- out_file.close();
- }
- int getFileLineCount(const char* file_name)
- {
- file.open(file_name);
- int count = 0;
- char line[2000];
- while(file.getline(line, 2000)) count++;
- file.close();
- return count;
- }
- bool compareTwoStrings(char str1[], char str2[])
- {
- char cpystr1[strlen(str1) + 1], cpystr2[strlen(str2) + 1];
- strcpy(cpystr1, str1);
- strcpy(cpystr2, str2);
- toLower(cpystr1);
- toLower(cpystr2);
- return strcmp(cpystr1, cpystr2) < 0 ? false : true;
- }
- void lookForName(int access)
- {
- cin.ignore();
- char name[1000];
- system("CLS");
- cout << "-> Digite o nome do policial." << endl << endl;
- cout << " Nome: ";
- cin.getline(name, 1000);
- adjustName(name);
- int occurrences = getNameOccurrences(name);
- system("CLS");
- if(occurrences == 0)
- {
- cout << "Este nome não está registrado no sistema." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- else
- {
- char n[10];
- itoa(occurrences, n, 10);
- cout << "Há (";
- writeInColor(n, 9);
- cout << ") ocorrência(s) deste nome no sistema" << endl << endl;
- showInfosAboutName(name, access);
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- }
- void printByBadArray(int ID[], int count)
- {
- int tmp;
- for(int i = 0; i < count; i++)
- {
- for(int j = 0; j < count; j++)
- {
- Villain cmp1 = getVillainInfo(ID[i]), cmp2 = getVillainInfo(ID[j]);
- if(!compareTwoStrings(cmp1.name, cmp2.name))
- {
- tmp = ID[j];
- ID[j] = ID[i];
- ID[i] = tmp;
- }
- }
- }
- for(int i = 0; i < count; i++)
- printBadInfoAbout(ID[i]);
- }
- void printByArray(char *array[], int count, int access, bool show_new_job)
- {
- char tmp[13];
- for(int i = 0; i < count; i++)
- {
- for(int j = 0; j < count; j++)
- {
- Cop cmp1 = getAccountInfo(array[i]), cmp2 = getAccountInfo(array[j]);
- if(!compareTwoStrings(cmp1.name, cmp2.name))
- {
- strcpy(tmp, array[j]);
- strcpy(array[j], array[i]);
- strcpy(array[i], tmp);
- }
- }
- }
- for(int i = 0; i < count; i++)
- {
- printInfoAbout(array[i], access, false, show_new_job);
- delete array[i];
- }
- }
- void lookForJob(int access)
- {
- cin.ignore();
- char job[100];
- bool check_job = false;
- int count = 0;
- system("CLS");
- cout << "-> Digite o cargo." << endl << endl;
- do
- {
- if(check_job)
- cout << "Cargo invalido." << endl << endl;
- cout << " Cargo: ";
- cin.getline(job, 100);
- adjustName(job);
- check_job = true;
- system("CLS");
- } while(getAccessLevel(job) == 0);
- ifstream tmp("cop_data.txt");
- char line[2000], *login[getFileLineCount("cop_data.txt")];
- while(tmp.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int job_size = i[11] - i[10] - 1;
- char job_now[job_size];
- fillSentence(line, i[10], i[11], job_now);
- char job_cmp[100];
- if(strchr(job_now, ':') != NULL)
- {
- int k[getIndexesSize(job_now, ':')];
- getIndexesBySplittingSentence(job_now, ':', k);
- int now_job = k[1] - k[0] - 1;
- char tmp_job[now_job];
- fillSentence(job_now, k[0], k[1], tmp_job);
- strcpy(job_cmp, tmp_job);
- }
- else
- strcpy(job_cmp, job_now);
- if(strcmp(job, job_cmp) == 0)
- {
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- login[count] = new char[login_size];
- strcpy(login[count], login_now);
- count++;
- }
- }
- tmp.close();
- if(count == 0)
- cout << "Não há registro de policiais com este cargo." << endl << endl;
- else
- {
- char n[10];
- itoa(count, n, 10);
- cout << "Há (";
- writeInColor(n, 9);
- cout << ") ocorrência(s) com este cargo no sistema" << endl << endl;
- printByArray(login, count, access, false);
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- void lookForArt()
- {
- bool check_art = false;
- int count = 0;
- char art[6];
- system("CLS");
- cout << "-> Digite o artigo." << endl;
- do
- {
- writeColorInfo("33");
- cout << " - Tráfico de drogas" << endl;
- writeColorInfo("121");
- cout << " - Homicídio" << endl;
- writeColorInfo("129");
- cout << " - Lesão Corporal" << endl;
- writeColorInfo("155");
- cout << " - Furto" << endl;
- writeColorInfo("157");
- cout << " - Roubo ou Latrocínio" << endl;
- writeColorInfo("158");
- cout << " - Extorsão" << endl;
- writeColorInfo("171");
- cout << " - Fraude ou Estelionato" << endl;
- writeColorInfo("213");
- cout << " - Estupro" << endl;
- writeColorInfo("216");
- cout << " - Assédio Sexual" << endl;
- writeColorInfo("250");
- cout << " - Incêndio" << endl;
- writeColorInfo("256");
- cout << " - Desmoronamento/desabamento" << endl;
- writeColorInfo("outro");
- cout << " - Outro" << endl << endl;
- if(check_art)
- cout << "Artigo inválido." << endl << endl;
- writeInColor(" Artigo", 9);
- cout << ": ";
- cin.getline(art, 6);
- check_art = true;
- system("CLS");
- } while(!isStringValid(art, CONST_ART_CHECK));
- ifstream file_now("bad_data.txt");
- int ID[getFileLineCount("bad_data.txt")];
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int art_size = i[9] - i[8] - 1;
- char art_now[art_size];
- fillSentence(line, i[8], i[9], art_now);
- if(strcmp(art_now, art) == 0)
- {
- int ID_size = i[1] - i[0] - 1;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- ID[count] = atoi(ID_now);
- count++;
- }
- }
- file_now.close();
- if(count == 0)
- cout << "Não há registro de criminosos com este artigo." << endl << endl;
- else
- {
- int resp;
- char n[3];
- itoa(count, n, 10);
- cout << " (";
- writeInColor(n, 9);
- cout << ") ocorrência(s) com este artigo." << endl << endl;
- printByBadArray(ID, count);
- if(strcmp(art, "outro") != 0)
- {
- cout << " Deseja saber mais sobre tal artigo?" << endl;
- resp = getYesOrNo();
- if(resp == 0)
- getArt(atoi(art), true);
- }
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- void lookForStatus()
- {
- bool check_status = false;
- int input_status, count = 0;
- system("CLS");
- cout << "-> Digite o estado." << endl;
- writeColorInfo("0");
- cout << " - Preso" << endl;
- writeColorInfo("1");
- cout << " - Foragido" << endl;
- writeColorInfo("2");
- cout << " - Livre" << endl;
- writeColorInfo("3");
- cout << " - Condicional" << endl;
- writeColorInfo("4");
- cout << " - Morto" << endl << endl;
- do
- {
- if(check_status)
- cout << "Estado inválido." << endl << endl;
- writeInColor(" Status", 9);
- cout << ": ";
- cin >> input_status;
- check_status = true;
- system("CLS");
- } while(input_status < 0 || input_status > 4);
- ifstream file_now("bad_data.txt");
- int ID[getFileLineCount("bad_data.txt")];
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int stat_size = i[13] - i[12] - 1;
- char status_now[stat_size];
- fillSentence(line, i[12], i[13], status_now);
- if(atoi(status_now) == input_status)
- {
- int ID_size = i[1] - i[0] - 1;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- ID[count] = atoi(ID_now);
- count++;
- }
- }
- file_now.close();
- if(count == 0)
- cout << "Não há registro de criminosos neste estado." << endl << endl;
- else
- {
- char n[3];
- itoa(count, n, 10);
- cout << " (";
- writeInColor(n, 9);
- cout << ") ocorrência(s) com este estado." << endl << endl;
- printByBadArray(ID, count);
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- void lookForID()
- {
- bool check_ID = false, found_ID = false;
- int input_ID;
- system("CLS");
- cout << "-> Digite a identificação." << endl << endl;
- do
- {
- if(check_ID)
- cout << "Identificação inválida." << endl << endl;
- writeInColor(" ID", 9);
- cout << ": ";
- cin >> input_ID;
- check_ID = true;
- system("CLS");
- } while(input_ID <= 0);
- ifstream file_now("bad_data.txt");
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, cmp_ID;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- cmp_ID = atoi(ID_now);
- if(cmp_ID == input_ID)
- {
- printBadInfoAbout(input_ID);
- found_ID = true;
- break;
- }
- }
- file_now.close();
- if(!found_ID)
- cout << "Não foi encontrado nenhum registro com esta identificação." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- void lookForAge(int access)
- {
- bool check_age = false;
- int age, count = 0;
- system("CLS");
- cout << "-> Digite a idade." << endl << endl;
- do
- {
- if(check_age)
- cout << "Idade inválida." << endl << endl;
- cout << " Idade: ";
- cin >> age;
- check_age = true;
- system("CLS");
- } while(age <= 0);
- ifstream tmp("cop_data.txt");
- char line[2000], *login[getFileLineCount("cop_data.txt")];
- Cop get_info;
- while(tmp.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- get_info = getAccountInfo(login_now);
- if(get_info.age == age)
- {
- login[count] = new char[login_size];
- strcpy(login[count], login_now);
- count++;
- }
- }
- tmp.close();
- if(count == 0)
- cout << "Não há registro de policiais com esta idade." << endl << endl;
- else
- {
- char n[10];
- itoa(count, n, 10);
- cout << "Há (";
- writeInColor(n, 9);
- cout << ") ocorrência(s) com esta idade no sistema" << endl << endl;
- printByArray(login, count, access, false);
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- void showInfosAboutName(char name[], int access)
- {
- file.open("cop_data.txt");
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int name_size = i[1] - i[0] - 1;
- char name_now[name_size];
- fillSentence(line, i[0], i[1], name_now);
- if(strcmp(name_now, name) == 0)
- {
- int login_size = i[3] - i[2] - 1;
- char login[login_size];
- fillSentence(line, i[2], i[3], login);
- Cop info = getAccountInfo(login);
- cout << " -> Nome: " << info.name << endl;
- if(access > 9)
- cout << " -> Login: " << login << endl;
- cout << " -> Idade: " << info.age << endl;
- char job_cmp[100];
- if(strchr(info.job, ':') != NULL)
- {
- int k[getIndexesSize(info.job, ':')];
- getIndexesBySplittingSentence(info.job, ':', k);
- int now_job = k[1] - k[0] - 1;
- char tmp_job[now_job];
- fillSentence(info.job, k[0], k[1], tmp_job);
- strcpy(job_cmp, tmp_job);
- }
- else
- strcpy(job_cmp, info.job);
- cout << " -> Cargo: " << job_cmp << endl;
- cout << " -> Data de nascimento: " << info.birth_date << endl;
- cout << " -> Data de registro da arma: " << info.gun << endl << endl;
- }
- }
- file.close();
- }
- int getYesOrNo()
- {
- int ret;
- cout << " (";
- writeInColor("0", 9);
- cout << ") - sim" << endl;
- cout << " (";
- writeInColor("1", 9);
- cout << ") - nao" << endl;
- do
- {
- cin >> ret;
- system("CLS");
- } while(ret != 0 && ret != 1);
- return ret;
- }
- void writeColorInfo(const char* art)
- {
- cout << " (";
- writeInColor(art, 4);
- cout << ")";
- }
- bool isStringValid(char str[], int check_type)
- {
- if(check_type == CONST_NAME_CHECK)
- {
- bool check_name_logic = false;
- if(strlen(str) < 5)
- {
- cout << "-> Nome muito curto!" << endl;
- return false;
- }
- for(unsigned int i = 0; i < strlen(str); i++)
- {
- if(isalpha(str[i]))
- check_name_logic = true;
- else if(!isspace(str[i])) return false;
- }
- if(!check_name_logic) return false;
- }
- else if(check_type == CONST_ART_CHECK)
- {
- int arts[] = {33, 121, 129, 155, 157, 158, 171, 213, 216, 250, 256};
- bool check_str = false;
- for(unsigned int i = 0; i < strlen(str); i++)
- if(!isdigit(str[i]))
- {
- check_str = true;
- break;
- }
- if(check_str)
- return strcmp(str, "outro") == 0 ? true : false;
- else
- {
- for(unsigned int i = 0; i < sizeof(arts); i++)
- if(arts[i] == atoi(str))
- return true;
- return false;
- }
- }
- else if(check_type == CONST_SPECIFIC_CHECK)
- {
- bool check_name_logic = false;
- for(unsigned int i = 0; i < strlen(str); i++)
- {
- if(isalnum(str[i]))
- check_name_logic = true;
- else
- {
- if(!isspace(str[i]) && str[i] != '.' && str[i] != ',' && str[i] != ';') return false;
- }
- }
- if(!check_name_logic) return false;
- }
- else if(check_type == CONST_CPF_CHECK)
- {
- if(strlen(str) != 11) return false;
- for(unsigned int i = 0; i < strlen(str); i++)
- if(!isdigit(str[i]))
- return false;
- }
- else
- {
- unsigned int max = check_type == CONST_LOGIN_CHECK ? 12 : 10;
- if(strlen(str) < 4 || strlen(str) > max) return false;
- for(unsigned int i = 0; i < strlen(str); i++)
- if(!isalpha(str[i]) && !isdigit(str[i]))
- return false;
- }
- return true;
- }
- void RegisterVillain()
- {
- Villain info;
- cout << " Muito bem, comecemos o registro do criminoso em questão." << endl << endl;
- cout << "-> O nome é conhecido?" << endl;
- int OP = getYesOrNo();
- if(OP == 1)
- strcpy(info.name, "-1");
- else
- {
- int resp;
- do
- {
- cin.ignore();
- bool check_name = true;
- do
- {
- if(!check_name)
- cout << "Nome inválido. Por gentileza, reentre com o dado correto." << endl << endl;
- writeInColor(" Nome completo", 4);
- cout << ": ";
- cin.getline(info.name, 1000);
- check_name = false;
- system("CLS");
- } while(!isStringValid(info.name, CONST_NAME_CHECK));
- adjustName(info.name);
- cout << "-> Nome registrado: " << info.name << endl << endl;
- cout << "Este nome está correto?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- if(strcmp(info.name, "-1") != 0)
- cout << "-> " << info.name << " possui um apelido?" << endl << endl;
- else
- cout << "-> Este criminoso possui um apelido?" << endl << endl;
- OP = getYesOrNo();
- if(OP == 1)
- strcpy(info.nickname, "-1");
- else
- {
- int resp;
- do
- {
- cin.ignore();
- bool check_nick = true;
- do
- {
- if(!check_nick)
- cout << "Apelido inválido. Por gentileza, reentre com o dado correto." << endl << endl;
- writeInColor(" Apelido", 4);
- cout << ": ";
- cin.getline(info.nickname, 1000);
- check_nick = false;
- system("CLS");
- } while(!isStringValid(info.nickname, CONST_NAME_CHECK));
- adjustName(info.nickname);
- cout << "-> Apelido registrado: " << info.nickname << endl << endl;
- cout << "Este apelido está correto?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- cout << "-> Há alguma ideia quanto a idade deste criminoso?" << endl;
- OP = getYesOrNo();
- if(OP == 1)
- info.age = -1;
- else
- {
- int resp;
- do
- {
- bool check_age = true;
- do
- {
- if(!check_age)
- cout << "Idade inválida. Por gentileza, reentre com o dado correto." << endl << endl;
- writeInColor(" Idade", 4);
- cout << ": ";
- cin >> info.age;
- check_age = false;
- system("CLS");
- } while(info.age <= 0);
- cout << "-> Idade registrada: " << info.age << endl << endl;
- cout << "Esta idade está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- cout << "-> Qual artigo mais se encaixa no crime?" << endl;
- int resp;
- do
- {
- bool check_art = true;
- cin.ignore();
- do
- {
- writeColorInfo("33");
- cout << " - Tráfico de drogas" << endl;
- writeColorInfo("121");
- cout << " - Homicídio" << endl;
- writeColorInfo("129");
- cout << " - Lesão Corporal" << endl;
- writeColorInfo("155");
- cout << " - Furto" << endl;
- writeColorInfo("157");
- cout << " - Roubo ou Latrocínio" << endl;
- writeColorInfo("158");
- cout << " - Extorsão" << endl;
- writeColorInfo("171");
- cout << " - Fraude ou Estelionato" << endl;
- writeColorInfo("213");
- cout << " - Estupro" << endl;
- writeColorInfo("216");
- cout << " - Assédio Sexual" << endl;
- writeColorInfo("250");
- cout << " - Incêndio" << endl;
- writeColorInfo("256");
- cout << " - Desmoronamento/desabamento" << endl;
- writeColorInfo("outro");
- cout << " - Outro" << endl << endl;
- if(!check_art)
- cout << "Artigo inválido. Por gentileza, reentre com o dado correto." << endl << endl;
- writeInColor(" Artigo", 4);
- cout << ": ";
- cin.getline(info.art, 6);
- check_art = false;
- system("CLS");
- } while(!isStringValid(info.art, CONST_ART_CHECK));
- cout << "-> Artigo registrado: ";
- getArt(atoi(info.art), false);
- cout << "." << endl << endl;
- cout << "Este artigo está correto?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- if(strcmp(info.art, "outro") != 0)
- strcpy(info.specific, "no_specific");
- else
- {
- int resp;
- cout << "-> Especifique o crime." << endl;
- do
- {
- cin.ignore();
- bool check_specific = true;
- cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
- do
- {
- if(!check_specific)
- cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" Especificação", 4);
- cout << ": ";
- cin.getline(info.specific, 51);
- check_specific = false;
- system("CLS");
- } while(!isStringValid(info.specific, CONST_SPECIFIC_CHECK));
- cout << "-> Informação registrada: " << info.specific << endl << endl;
- cout << "Esta informação está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- cout << "Qual a situação atual deste criminoso?" << endl;
- do
- {
- bool check_status = true;
- do
- {
- writeColorInfo("0");
- cout << " - Preso" << endl;
- writeColorInfo("1");
- cout << " - Foragido" << endl;
- writeColorInfo("2");
- cout << " - Livre" << endl;
- writeColorInfo("3");
- cout << " - Condicional" << endl;
- writeColorInfo("4");
- cout << " - Morto" << endl << endl;
- if(!check_status)
- cout << "Estado inválido. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" Estado", 4);
- cout << ": ";
- cin >> info.status;
- check_status = false;
- system("CLS");
- } while(info.status < 0 || info.status > 4);
- cout << "-> Estado registrado: ";
- switch(info.status)
- {
- case 0:
- cout << "preso." << endl << endl;
- break;
- case 1:
- cout << "foragido." << endl << endl;
- break;
- case 2:
- cout << "livre." << endl << endl;
- break;
- case 3:
- cout << "em condicional." << endl << endl;
- break;
- case 4:
- cout << "falecido." << endl << endl;
- break;
- }
- cout << "Este estado está correto?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- if(info.status == 0 || info.status == 3)
- {
- cout << "-> Qual a identificação do prisioneiro?" << endl << endl;
- int resp;
- do
- {
- bool check_ID = true;
- do
- {
- if(!check_ID)
- cout << "Identifição inválida ou repetida. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" ID", 4);
- cout << ": ";
- cin >> info.ID;
- check_ID = false;
- system("CLS");
- } while(info.ID <= 0 || !isIDValid(info.ID));
- cout << "-> Identifição registrada: " << info.ID << endl << endl;
- cout << "Esta identificação está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- else
- {
- info.ID = -(getFileLineCount("bad_data.txt"));
- while(!isIDValid(info.ID))
- info.ID--;
- }
- cout << "-> Deseja acrescentar alguma informação extra?" << endl;
- OP = getYesOrNo();
- if(OP == 1)
- strcpy(info.extra, "Nada a acrescentar.");
- else
- {
- int resp;
- do
- {
- cin.ignore();
- bool check_extra = true;
- cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
- do
- {
- if(!check_extra)
- cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" Extra", 4);
- cout << ": ";
- cin.getline(info.extra, 51);
- check_extra = false;
- system("CLS");
- } while(!isStringValid(info.extra, CONST_SPECIFIC_CHECK));
- cout << "-> Informação extra registrada: " << info.extra << endl << endl;
- cout << "Esta informação está correta?" << endl;
- resp = getYesOrNo();
- } while(resp == 1);
- }
- info.writeIntoBadFile();
- cout << " -> Registro completo!" << endl << endl;
- cout << "As informações deste criminoso foram armazenadas com sucesso no sistema." << endl;
- cout << "Pressione qualquer tecla para continuar." << endl;
- getch();
- system("CLS");
- }
- void Villain::writeIntoBadFile()
- {
- out_file.open("bad_data.txt", ios_base::app | ios_base::out);
- out_file << "ID:/" << this->ID << "/";
- out_file << "Nome:/" << this->name << "/";
- out_file << "Apelido:/" << this->nickname << "/";
- out_file << "Idade:/" << this->age << "/";
- out_file << "Artigo:/" << this->art << "/";
- out_file << "Outro:/" << this->specific << "/";
- out_file << "Status:/" << this->status << "/";
- out_file << "Extra:/" << this->extra << "/" << endl;
- out_file.close();
- }
- void RegisterCop()
- {
- Register info;
- cout << " Muito bem, comecemos o processo de registro de conta." << endl << endl;
- cout << "-> Primeiramente, entre com o login que deseja utilizar." << endl;
- cout << "MIN. 4 MÁX. 12 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
- bool check_login = true;
- char login[13];
- do
- {
- if(!check_login)
- {
- cout << "Login inválido." << endl;
- cout << "MIN. 4 MÁX. 12 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
- }
- writeInColor(" Login", 9);
- cout << ": ";
- cin >> login;
- strcpy(info.login, login);
- check_login = false;
- system("CLS");
- while(isInUse(login))
- {
- cout << "Login em uso! Escolha outro, por gentileza." << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin >> login;
- strcpy(info.login, login);
- system("CLS");
- }
- } while(!isStringValid(info.login, CONST_LOGIN_CHECK));
- cout << "-> Passemos agora para a senha." << endl;
- cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
- bool same_passwords = true;
- do
- {
- if(!same_passwords)
- cout << "Senhas diferentes. Por favor, reentre com este dado." << endl << endl;
- bool check_password = true;
- do
- {
- if(!check_password)
- {
- cout << "Senha inválida." << endl;
- cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
- }
- int count = 0;
- writeInColor(" Senha", 9);
- cout << ": ";
- while(count <= 10)
- {
- if(count == 10) {info.password[10] = '\0'; break;}
- info.password[count] = _getch();
- if(info.password[count] == '\n' || info.password[count] == '\r')
- {
- info.password[count] = '\0';
- break;
- }
- cout << "*";
- count++;
- }
- check_password = false;
- system("CLS");
- } while(!isStringValid(info.password, CONST_PASSWORD_CHECK));
- char repeat_password[11];
- cout << "-> Repita a senha." << endl;
- int count = 0;
- writeInColor(" Senha", 9);
- cout << ": ";
- while(count <= 10)
- {
- if(count == 10) {repeat_password[10] = '\0'; break;}
- repeat_password[count] = _getch();
- if(repeat_password[count] == '\n' || repeat_password[count] == '\r')
- {
- repeat_password[count] = '\0';
- break;
- }
- cout << "*";
- count++;
- }
- same_passwords = strcmp(info.password, repeat_password) == 0 ? true : false;
- system("CLS");
- } while(!same_passwords);
- writeInColor(" Login", 9);
- cout << ": " << info.login << endl;
- writeInColor(" Senha", 9);
- cout << ": " << info.password << endl << endl;
- cout << "-> Pressione qualquer tecla para continuar o registro." << endl;
- getch();
- system("CLS");
- cout << "-> Por gentileza, informe-nos agora seu nome completo." << endl;
- bool check_name = true;
- cin.ignore();
- do
- {
- if(!check_name)
- cout << "Nome inválido. Por gentileza, reentre com o dado correto." << endl << endl;
- writeInColor(" Nome completo", 9);
- cout << ": ";
- cin.getline(info.name, 1000);
- check_name = false;
- system("CLS");
- } while(!isStringValid(info.name, CONST_NAME_CHECK));
- adjustName(info.name);
- cout << "Nome registrado: " << info.name << endl << endl;
- cout << "-> Pressione qualquer tecla para continuar o registro." << endl;
- getch();
- bool _continue = true;
- if(getNameOccurrences(info.name) > 0)
- {
- char resp[10];
- cout << endl;
- cout << "Parece que há " << getNameOccurrences(info.name) << " ocorrência(s) desse nome em nosso sistema." << endl;
- cout << endl;
- 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;
- cout << " -> Se for apenas uma coincidência, então entre com ";
- writeInColor("continuar", 9);
- cout << ". Qualquer outra entrada resultará em uma interrupção no registro." << endl;
- cin.getline(resp, 10);
- _continue = strcmp(resp, "continuar") == 0 ? true : false;
- }
- system("CLS");
- if(!_continue) return;
- cout << "Login, senha e nome confirmados." << endl << endl;
- cout << "-> Entre agora com seu dia de nascimento." << endl << endl;
- bool check_day = true;
- do
- {
- if(!check_day)
- cout << "Dia inválido. Por gentileza, reentre com este dado." << endl << endl;
- writeInColor(" Dia de nascimento", 9);
- cout << ": ";
- cin >> info.day;
- check_day = false;
- system("CLS");
- } while(info.day < 1 || info.day > 31);
- cout << "-> Entre agora com seu mês de nascimento." << endl << endl;
- bool check_month = true;
- do
- {
- if(!check_month)
- {
- cout << "Mês inválido. Por gentileza, reentre com este dado." << endl;
- cout << endl;
- }
- writeInColor(" Mês de nascimento", 9);
- cout << ": ";
- cin >> info.month;
- check_month = false;
- system("CLS");
- } while(info.month < 1 || info.month > 12);
- while(info.day > 29 && info.month == 2)
- {
- cout << "Combinação de data inválida." << endl;
- cout << "-> Entre agora com seu dia de nascimento." << endl << endl;
- bool check_day = true;
- do
- {
- if(!check_day)
- cout << "Dia inválido. Por gentileza, reentre com este dado." << endl << endl;
- writeInColor(" Dia de nascimento", 9);
- cout << ": ";
- cin >> info.day;
- check_day = false;
- system("CLS");
- } while(info.day < 1 || info.day > 31);
- cout << "-> Entre agora com seu mês de nascimento." << endl << endl;
- bool check_month = true;
- do
- {
- if(!check_month)
- cout << "Mês inválido. Por gentileza, reentre com este dado." << endl << endl;
- writeInColor(" Mês de nascimento", 9);
- cout << ": ";
- cin >> info.month;
- check_month = false;
- system("CLS");
- } while(info.month < 1 || info.month > 12);
- }
- cout << "-> Entre agora com seu ano de nascimento." << endl << endl;
- time_t t = time(NULL);
- tm* timePtr = localtime(&t);
- int year_now = timePtr->tm_year + 1900;
- bool check_year = true;
- do
- {
- if(!check_year)
- cout << "Ano inválido. Por gentileza, reentre com este dado." << endl << endl;
- writeInColor(" Ano de nascimento", 9);
- cout << ": ";
- cin >> info.year;
- check_year = false;
- system("CLS");
- } while(info.year < 1910 || info.year > year_now);
- char add_d[3] = "0", add_m[3] = "0";
- itoa(info.day, info.d, 10);
- itoa(info.month, info.m, 10);
- itoa(info.year, info.y, 10);
- if(info.day < 10)
- {
- strcat(add_d, info.d);
- strcpy(info.d, add_d);
- }
- if(info.month < 10)
- {
- strcat(add_m, info.m);
- strcpy(info.m, add_m);
- }
- cout << "Data de nascimento salva. [" << info.d << "-" << info.m << "-" << info.y << "]" << endl << endl;
- cout << "-> Agora, informe seu cargo." << endl;
- cout << "As opções de cargo aceitas são as seguintes:" << endl << endl;
- cout << " -> ";
- writeInColor("Coronel", 4);
- cout << endl << " -> ";
- writeInColor("Tenente-Coronel", 4);
- cout << endl << " -> ";
- writeInColor("Major", 4);
- cout << endl << " -> ";
- writeInColor("Capitao", 4);
- cout << endl << " -> ";
- writeInColor("1 Tenente", 4);
- cout << endl << " -> ";
- writeInColor("2 Tenente", 4);
- cout << endl << " -> ";
- writeInColor("Aspirante a Oficial", 4);
- cout << endl << " -> ";
- writeInColor("Subtenente", 4);
- cout << endl << " -> ";
- writeInColor("1 Sargento", 4);
- cout << endl << " -> ";
- writeInColor("2 Sargento", 4);
- cout << endl << " -> ";
- writeInColor("3 Sargento", 4);
- cout << endl << " -> ";
- writeInColor("Cabo", 4);
- cout << endl << " -> ";
- writeInColor("Soldado", 4);
- cout << endl << endl;
- bool is_valid = true;
- cin.ignore();
- do
- {
- if(!is_valid)
- cout << "Este cargo não é válido em nosso sistema. Por favor, entre com outro." << endl << endl;
- writeInColor(" Cargo", 9);
- cout << ": ";
- cin.getline(info.job, 100);
- adjustName(info.job);
- is_valid = false;
- system("CLS");
- } while(getAccessLevel(info.job) == 0);
- cout << "Seu cargo foi definido como " << info.job << "." << endl << endl;
- cout << "-> Agora, você deverá entrar com a data de emissão do seu documento de porte de arma." << endl;
- cout << "O processo é o mesmo do registro de sua data de nascimento." << endl << endl;
- bool check_gday = true, check_gmonth = true, check_gyear = true;
- cout << "-> Entre com o dia." << endl << endl;
- do
- {
- if(!check_gday)
- cout << "Dia inválido." << endl << endl;
- writeInColor(" Dia", 9);
- cout << ": ";
- cin >> info.gun_day;
- check_gday = false;
- system("CLS");
- } while(info.gun_day < 1 || info.gun_day > 31);
- cout << "-> Entre agora com o mês." << endl << endl;
- do
- {
- if(!check_gmonth)
- cout << "Mês inválido." << endl << endl;
- writeInColor(" Mês", 9);
- cout << ": ";
- cin >> info.gun_month;
- check_gmonth = false;
- system("CLS");
- } while(info.gun_month < 1 || info.gun_month > 12);
- while(info.gun_day > 29 && info.gun_month == 2)
- {
- cout << "Combinacão de data inválida." << endl;
- cout << "Por gentileza, reentre com os dados." << endl;
- bool check_day_in_scope = true, check_month_in_scope = true;
- cout << "-> Entre com o dia." << endl << endl;
- do
- {
- if(!check_day_in_scope)
- cout << "Dia invalido." << endl << endl;
- writeInColor(" Dia", 9);
- cout << ": ";
- cin >> info.gun_day;
- check_day_in_scope = false;
- system("CLS");
- } while(info.gun_day < 1 || info.gun_day > 31);
- cout << "-> Entre agora com o mês." << endl << endl;
- do
- {
- if(!check_month_in_scope)
- cout << "Mês inválido." << endl << endl;
- writeInColor(" Mês", 9);
- cout << ": ";
- cin >> info.gun_month;
- check_month_in_scope = false;
- system("CLS");
- } while(info.gun_month < 1 || info.gun_month > 12);
- }
- cout << "-> Entre agora com o ano." << endl << endl;
- do
- {
- if(!check_gyear)
- cout << "Ano inválido." << endl << endl;
- writeInColor(" Ano", 9);
- cout << ": ";
- cin >> info.gun_year;
- check_gyear = false;
- system("CLS");
- } while(info.gun_year < (year_now - 5) || info.gun_year > year_now);
- char add_dg[3] = "0", add_mg[3] = "0";
- itoa(info.gun_day, info.dg, 10);
- itoa(info.gun_month, info.mg, 10);
- itoa(info.gun_year, info.yg, 10);
- if(info.gun_day < 10)
- {
- strcat(add_dg, info.dg);
- strcpy(info.dg, add_dg);
- }
- if(info.gun_month < 10)
- {
- strcat(add_mg, info.mg);
- strcpy(info.mg, add_mg);
- }
- cout << "A data de emissão do seu documento de porte de arma foi salva. [" << info.dg << "-" << info.mg << "-" << info.yg << "]" << endl;
- cout << "-> Agora, entre com seu cadastro de pessoa física (CPF)." << endl;
- cout << " APENAS OS CARACTERES NÚMERICOS." << endl << endl;
- cin.ignore();
- bool check_CPF = true;
- char generic_CPF[12];
- do
- {
- do
- {
- if(!check_CPF)
- cout << "CPF inválido ou em uso. Lembre-se: o CPF possui 11 caracteres NÚMERICOS." << endl << endl;
- writeInColor(" CPF", 9);
- cout << ": ";
- cin.getline(generic_CPF, 12);
- check_CPF = false;
- system("CLS");
- } while(!isStringValid(generic_CPF, CONST_CPF_CHECK));
- correctAndTransferCPF(info.CPF, generic_CPF);
- } while(isCPFInUse(info.CPF));
- cout << "Seu CPF foi registrado com sucesso. [" << info.CPF << "]" << endl;
- cout << "-> Pressione qualquer tecla para finalizar o registro." << endl;
- getch();
- strcpy(info.key, "-1");
- info.status = -1;
- info.writeIntoFile();
- system("CLS");
- cout << " -> Registro completo!" << endl << endl;
- cout << "Suas informações foram com sucesso salvas em nosso banco de dados." << endl;
- cout << "Seu ingresso no sistema deve agora ser autorizado por algum oficial de maior ordem. Por gentileza, aguarde pacientemente" << endl << endl;
- cout << "Pressione qualquer tecla para continuar." << endl;
- getch();
- system("CLS");
- }
- void printInfoAbout(char login[], int access, bool yourself, bool show_new_job)
- {
- Cop info = getAccountInfo(login);
- cout << " -> Nome: " << info.name << endl;
- if(access > 9 || yourself)
- cout << " -> Login: " << login << endl;
- if(yourself)
- cout << " -> Senha: " << info.password << endl;
- if(yourself && strcmp(info.key, "-1") != 0)
- cout << " -> Chave: " << info.key << endl;
- if(yourself)
- cout << " -> CPF: " << info.CPF << endl;
- cout << " -> Idade: " << info.age << endl;
- char job_cmp[100], new_job[100];
- if(strchr(info.job, ':') != NULL)
- {
- int k[getIndexesSize(info.job, ':')];
- getIndexesBySplittingSentence(info.job, ':', k);
- int now_job = k[0] - 1;
- char tmp_job[now_job];
- fillSentence(info.job, -1, k[0], tmp_job);
- strcpy(job_cmp, tmp_job);
- if(show_new_job)
- {
- int new_job_size = strlen(info.job) - k[0] - 1;
- char new_job_here[new_job_size];
- fillSentence(info.job, k[0], strlen(info.job), new_job_here);
- strcpy(new_job, new_job_here);
- }
- }
- else
- strcpy(job_cmp, info.job);
- cout << " -> Cargo: " << job_cmp << endl;
- if(show_new_job)
- cout << " -> Cargo solicitado: " << new_job << endl;
- cout << " -> Data de nascimento: " << info.birth_date << endl;
- cout << " -> Data de registro da arma: " << info.gun << endl << endl;
- }
- Cop getAccountInfo(char input_login[])
- {
- ifstream file_now("cop_data.txt");
- Cop ret;
- time_t t = time(NULL);
- tm* timePtr = localtime(&t);
- strcpy(ret.login, input_login);
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login[login_size];
- fillSentence(line, i[2], i[3], login);
- if(strcmp(input_login, login) == 0)
- {
- int name_size = i[1] - i[0] - 1, pass_size = i[5] - i[4] - 1, key_size = 8;
- 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;
- 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;
- 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];
- fillSentence(line, i[0], i[1], name_now);
- fillSentence(line, i[4], i[5], password);
- fillSentence(line, i[6], i[7], key);
- fillSentence(line, i[8], i[9], birth_date);
- fillSentence(line, i[10], i[11], job_now);
- fillSentence(line, i[12], i[13], gun);
- fillSentence(line, i[14], i[15], CPF);
- fillSentence(line, i[16], i[17], status);
- int g[getIndexesSize(birth_date, '-')];
- getIndexesBySplittingSentence(birth_date, '-', g);
- int day_size = g[0], mon_size = g[1] - g[0] - 1, year_size = strlen(birth_date) - g[1] - 1;
- char day_str[day_size], mon_str[mon_size], year_str[year_size];
- fillSentence(birth_date, -1, g[0], day_str);
- fillSentence(birth_date, g[0], g[1], mon_str);
- fillSentence(birth_date, g[1], strlen(birth_date), year_str);
- int day = atoi(day_str);
- int month = atoi(mon_str);
- int year = atoi(year_str);
- age = year_now - year;
- if(month_now < month || (month_now == month && day_now < day))
- age--;
- strcpy(ret.name, name_now);
- strcpy(ret.password, password);
- strcpy(ret.key, key);
- strcpy(ret.birth_date, birth_date);
- strcpy(ret.job, job_now);
- strcpy(ret.gun, gun);
- strcpy(ret.CPF, CPF);
- ret.status = atoi(status);
- ret.age = age;
- ret.access = getAccessLevel(ret.job);
- break;
- }
- }
- file_now.close();
- return ret;
- }
- void fillSentence(char line[], int begin, int end, char target[])
- {
- int count = 0;
- for(int i = begin + 1; i < end; i++)
- target[count++] = line[i];
- target[end - begin - 1] = '\0';
- }
- void deleteAccount(const char* input_login)
- {
- file.open("cop_data.txt");
- out_file.open("tmp.txt", ios_base::app | ios_base::out);
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login[login_size];
- fillSentence(line, i[2], i[3], login);
- if(strcmp(input_login, login) != 0)
- out_file << line << endl;
- }
- file.close();
- out_file.close();
- remove("cop_data.txt");
- rename("tmp.txt", "cop_data.txt");
- }
- void openWebsite(const char* website){ShellExecute(NULL, "open", website, NULL, NULL, SW_SHOWNORMAL);}
- void createAdminAccount()
- {
- Register admin;
- strcpy(admin.login, "admin");
- strcpy(admin.password, "admin");
- strcpy(admin.name, "Administrador");
- strcpy(admin.job, "Coronel");
- strcpy(admin.CPF, "000.000.000-00");
- strcpy(admin.key, "0");
- strcpy(admin.d, "30");
- strcpy(admin.m, "04");
- strcpy(admin.y, "1999");
- strcpy(admin.dg, "30");
- strcpy(admin.mg, "04");
- strcpy(admin.yg, "3000");
- admin.status = 2;
- admin.writeIntoFile();
- }
- bool isCPFInUse(char CPF[])
- {
- file.open("cop_data.txt");
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int CPF_size = i[15] - i[14] - 1;
- char CPF_check[CPF_size];
- fillSentence(line, i[14], i[15], CPF_check);
- if(strcmp(CPF, CPF_check) == 0)
- {
- file.close();
- return true;
- }
- }
- file.close();
- return false;
- }
- void recoverAccount()
- {
- char login[13], key[8];
- cout << "-> Entre com o login da conta que deseja recuperar." << endl << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin.getline(login, 13);
- system("CLS");
- if(!isInUse(login))
- {
- cout << "-> Login inválido." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- _getch();
- return;
- }
- Cop info = getAccountInfo(login);
- cout << "-> Entre com a chave de segurança desta conta." << endl;
- writeInColor(" Chave", 9);
- cout << ": ";
- cin.getline(key, 8);
- system("CLS");
- if(strcmp(info.key, "-1") == 0 || strcmp(info.key, key) != 0)
- {
- cout << "-> Combinação inválida." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- _getch();
- return;
- }
- cout << "-> A senha desta conta é: ";
- writeInColor(info.password, 9);
- cout << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu." << endl;
- _getch();
- }
- bool isInArray(int array[], int size, int element)
- {
- for(int i = 0; i < size; i++)
- if(element == array[i])
- return true;
- return false;
- }
- void generateSecurityKey(char key[])
- {
- const char options[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789";
- int size = sizeof(options) - 1;
- srand(time(NULL));
- for(int i = 0; i < 7; i++)
- key[i] = options[rand() % size];
- key[7] = '\0';
- }
- void showPendentAccounts(int count, bool admin)
- {
- file.open("cop_data.txt");
- int c = 0;
- char *login[count], line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int status_size = i[17] - i[16] - 1;
- char status[status_size];
- fillSentence(line, i[16], i[17], status);
- if(atoi(status) == -1)
- {
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- login[c] = new char[login_size];
- strcpy(login[c], login_now);
- c++;
- }
- }
- file.close();
- char tmp_n[4];
- itoa(count, tmp_n, 10);
- cout << " *** Há (";
- writeInColor(tmp_n, 9);
- cout << ") conta(s) para admitir. ***" << endl << endl;
- printByArray(login, count, 10, false);
- char look_for_login[13];
- bool check_login = true;
- do
- {
- if(!check_login)
- cout << " Login inválido. Se desejar voltar ao menu, digite 1." << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin.getline(look_for_login, 13);
- check_login = false;
- system("CLS");
- } while(!isInUse(look_for_login) && strcmp(look_for_login, "1") != 0);
- if(strcmp(look_for_login, "1") == 0) return;
- char num[] = "1";
- updateAccount(look_for_login, 16, num, admin);
- cout << "-> Conta admitida." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- void showPendentJobs(int count, bool admin)
- {
- file.open("cop_data.txt");
- char *login[count], line[2000];
- int counting = 0;
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int job_size = i[11] - i[10] - 1;
- char job_now[job_size];
- fillSentence(line, i[10], i[11], job_now);
- if(strchr(job_now, ':') != NULL)
- {
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- login[counting] = new char[login_size];
- strcpy(login[counting], login_now);
- counting++;
- }
- }
- file.close();
- char tmp_n[4];
- itoa(count, tmp_n, 10);
- cout << " *** Há (";
- writeInColor(tmp_n, 9);
- cout << ") solicitação(ões) de mudança de cargo. ***" << endl << endl;
- printByArray(login, count, 10, true);
- char look_for_login[13];
- bool check_login = true;
- do
- {
- if(!check_login)
- cout << endl << " Login inválido. Se desejar voltar ao menu, digite 1." << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin.getline(look_for_login, 13);
- check_login = false;
- system("CLS");
- } while(!isInUse(look_for_login) && strcmp(look_for_login, "1") != 0);
- system("CLS");
- if(strcmp(look_for_login, "1") == 0) return;
- Cop info = getAccountInfo(look_for_login);
- int k[getIndexesSize(info.job, ':')];
- getIndexesBySplittingSentence(info.job, ':', k);
- int new_job_size = strlen(info.job) - k[0] - 1;
- char new_job[new_job_size];
- fillSentence(info.job, k[0], strlen(info.job), new_job);
- updateAccount(look_for_login, 10, new_job, admin);
- cout << "-> Cargo da referida conta atualizado com sucesso para " << new_job << "." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- int getPendentAdmissions()
- {
- file.open("cop_data.txt");
- char line[2000];
- int count = 0;
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int status_size = i[17] - i[16] - 1;
- char status[status_size];
- fillSentence(line, i[16], i[17], status);
- if(atoi(status) == -1) count++;
- }
- file.close();
- return count;
- }
- int getPendentJobSolicitations()
- {
- file.open("cop_data.txt");
- int count = 0;
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int job_size = i[11] - i[10] - 1;
- char job_now[job_size];
- fillSentence(line, i[10], i[11], job_now);
- if(strchr(job_now, ':') != NULL) count++;
- }
- file.close();
- return count;
- }
- void executeDeletion(int access, char login_input[])
- {
- char login[13];
- system("CLS");
- cout << "-> Digite o login do policial que será removido." << endl << endl;
- writeInColor(" Login", 9);
- cout << ": ";
- cin.getline(login, 13);
- system("CLS");
- if(strcmp(login_input, login) == 0)
- {
- cout << " Você não pode deletar sua própria conta." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- else if(!isInUse(login))
- {
- cout << " Este nome de usuário não está registrado no sistema. Por gentileza, verifique-o novamente." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- else
- {
- char name[1000];
- cout << "-> Digite o nome do policial para confirmar o processo." << endl << endl;
- int resp, check_name = true;
- do
- {
- do
- {
- if(!check_name)
- cout << " Nome inválido. Por gentileza, reentre com o dado correto. (1 para voltar ao menu de pesquisa)" << endl << endl;
- writeInColor(" Nome completo", 9);
- cout << ": ";
- cin.getline(name, 1000);
- check_name = false;
- system("CLS");
- } while(!isStringValid(name, 2) && atoi(name) != 1);
- if(atoi(name) == 1)
- resp = 1;
- else
- {
- cout << " O nome " << name << " está correto?" << endl;
- resp = getYesOrNo();
- }
- } while(resp == 1);
- if(atoi(name) != 1)
- {
- Cop target = getAccountInfo(login);
- adjustName(name);
- if(strcmp(target.name, name) != 0)
- {
- cout << " O nome entrado é diferente do nome do dono da conta." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- else if(target.access > access)
- {
- cout << " Você possui um nível de acesso inferior ao da conta." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- else
- {
- deleteAccount(login);
- cout << " Conta deletada com sucesso." << endl << endl;
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- }
- }
- }
- void getArt(int art, bool open_site)
- {
- switch(art)
- {
- case 33:
- if(open_site)
- openWebsite("https://www.jusbrasil.com.br/topicos/10636569/artigo-33-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
- else
- cout << "Tráfico de drogas";
- break;
- case 121:
- if(open_site)
- openWebsite("https://pt.wikipedia.org/wiki/Homic%C3%ADdio");
- else
- cout << "Homicídio";
- break;
- case 129:
- if(open_site)
- openWebsite("https://pt.wikipedia.org/wiki/Les%C3%A3o_corporal");
- else
- cout << "Lesão Corporal";
- break;
- case 155:
- if(open_site)
- openWebsite("https://pt.wikipedia.org/wiki/Furto");
- else
- cout << "Furto";
- break;
- case 157:
- if(open_site)
- openWebsite("https://pt.wikipedia.org/wiki/Roubo");
- else
- cout << "Roubo ou Latrocínio";
- break;
- case 158:
- if(open_site)
- openWebsite("https://pt.wikipedia.org/wiki/Extors%C3%A3o");
- else
- cout << "Extorsão";
- break;
- case 171:
- if(open_site)
- openWebsite("https://www.jusbrasil.com.br/topicos/10617301/artigo-171-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
- else
- cout << "Fraude ou Estelionato";
- break;
- case 213:
- if(open_site)
- openWebsite("https://leonardocastro2.jusbrasil.com.br/artigos/121943503/legislacao-comentada-artigo-213-do-cp-estupro");
- else
- cout << "Estupro";
- break;
- case 216:
- if(open_site)
- openWebsite("https://vicentemaggio.jusbrasil.com.br/artigos/121942480/o-crime-de-assedio-sexual");
- else
- cout << "Assédio Sexual";
- break;
- case 250:
- if(open_site)
- openWebsite("https://www.jusbrasil.com.br/topicos/10607060/artigo-250-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
- else
- cout << "Incêndio";
- break;
- case 256:
- if(open_site)
- openWebsite("https://www.jusbrasil.com.br/topicos/10606196/artigo-256-do-decreto-lei-n-2848-de-07-de-dezembro-de-1940");
- else
- cout << "Desmoronamento/desabamento";
- break;
- default:
- cout << "Outro";
- }
- }
- void updateAccount(char login[], int start, char new_value[], bool admin)
- {
- Cop info = getAccountInfo(login);
- Register new_info;
- ifstream old_file("cop_data.txt");
- out_file.open("tmp.txt", ios_base::app | ios_base::out);
- char line[2000], old_line[2000];
- while(old_file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- if(strcmp(login_now, login) == 0)
- strcpy(old_line, line);
- else
- out_file << line << endl;
- }
- old_file.close();
- out_file.close();
- remove("cop_data.txt");
- rename("tmp.txt", "cop_data.txt");
- strcpy(new_info.name, info.name);
- strcpy(new_info.login, login);
- if(start == 4)
- strcpy(new_info.password, new_value);
- else
- strcpy(new_info.password, info.password);
- if(start == 6)
- strcpy(new_info.key, new_value);
- else
- strcpy(new_info.key, info.key);
- int k[getIndexesSize(info.birth_date, '-')];
- getIndexesBySplittingSentence(info.birth_date, '-', k);
- char day[3], mon[3], year[5];
- fillSentence(info.birth_date, -1, k[0], day);
- fillSentence(info.birth_date, k[0], k[1], mon);
- fillSentence(info.birth_date, k[1], strlen(info.birth_date), year);
- new_info.day = atoi(day);
- new_info.month = atoi(mon);
- new_info.year = atoi(year);
- strcpy(new_info.d, day);
- strcpy(new_info.m, mon);
- strcpy(new_info.y, year);
- strcpy(new_info.job, info.job);
- if(start == 10)
- {
- if(strchr(new_info.job, ':') != NULL)
- strcpy(new_info.job, new_value);
- else
- {
- strcat(new_info.job, ":");
- strcat(new_info.job, new_value);
- }
- }
- char gday[3], gmon[3], gyear[5];
- if(start == 12)
- {
- int j[getIndexesSize(new_value, '-')];
- getIndexesBySplittingSentence(new_value, '-', j);
- fillSentence(new_value, -1, j[0], gday);
- fillSentence(new_value, j[0], j[1], gmon);
- fillSentence(new_value, j[1], strlen(new_value), gyear);
- new_info.gun_day = atoi(gday);
- new_info.gun_month = atoi(gmon);
- new_info.gun_year = atoi(gyear);
- strcpy(new_info.dg, gday);
- strcpy(new_info.mg, gmon);
- strcpy(new_info.yg, gyear);
- }
- else
- {
- int j[getIndexesSize(info.gun, '-')];
- getIndexesBySplittingSentence(info.gun, '-', j);
- fillSentence(info.gun, -1, j[0], gday);
- fillSentence(info.gun, j[0], j[1], gmon);
- fillSentence(info.gun, j[1], strlen(info.gun), gyear);
- new_info.gun_day = atoi(gday);
- new_info.gun_month = atoi(gmon);
- new_info.gun_year = atoi(gyear);
- strcpy(new_info.dg, gday);
- strcpy(new_info.mg, gmon);
- strcpy(new_info.yg, gyear);
- }
- strcpy(new_info.CPF, info.CPF);
- if(start == 16)
- new_info.status = atoi(new_value);
- else
- new_info.status = info.status;
- if(admin && getAccessLevel(new_info.job) > 9)
- {
- deleteAccount("admin");
- pendent = false;
- edit = false;
- logon = false;
- }
- new_info.writeIntoFile();
- }
- void changeDate(char login[])
- {
- system("CLS");
- cout << "-> Informe a nova data de emissão do documento de porte de armas." << endl;
- int new_day, new_month, new_year;
- bool check_day = true, check_month = true, check_year = true;
- do
- {
- if(!check_day)
- cout << "Dia inválido." << endl << endl;
- writeInColor(" Dia", 9);
- cout << ": ";
- cin >> new_day;
- check_day = false;
- system("CLS");
- } while(new_day < 1 || new_day > 31);
- cout << "-> Informe o novo mês de emissão do documento de porte de armas." << endl;
- do
- {
- if(!check_month)
- cout << "Mês inválido." << endl << endl;
- writeInColor(" Mês", 9);
- cout << ": ";
- cin >> new_month;
- check_month = false;
- system("CLS");
- } while(new_month < 1 || new_month > 12);
- while(new_day > 29 && new_month == 2)
- {
- cout << "Combinação de data inválida." << endl;
- cout << "Por gentileza, reentre com os dados." << endl;
- bool check_day_in_scope = true, check_month_in_scope = true;
- cout << "-> Informe a nova data de emissão do documento de porte de armas." << endl;
- do
- {
- if(!check_day_in_scope)
- cout << "Dia inválido." << endl << endl;
- writeInColor(" Dia", 9);
- cout << ": ";
- cin >> new_day;
- check_day_in_scope = false;
- system("CLS");
- } while(new_day < 1 || new_day > 31);
- cout << "-> Informe o novo mês de emissão do documento de porte de armas." << endl;
- do
- {
- if(!check_month_in_scope)
- cout << "Mês inválido." << endl << endl;
- writeInColor(" Mês", 9);
- cout << ": ";
- cin >> new_month;
- check_month_in_scope = false;
- system("CLS");
- } while(new_month < 1 || new_month > 12);
- }
- time_t t = time(NULL);
- tm* timePtr = localtime(&t);
- int year_now = timePtr->tm_year + 1900;
- cout << "-> Informe o novo ano de emissão do documento de porte de armas." << endl;
- do
- {
- if(!check_year)
- cout << "Ano inválido." << endl << endl;
- writeInColor(" Ano", 9);
- cout << ": ";
- cin >> new_year;
- check_year = false;
- system("CLS");
- } while(new_year < (year_now - 5) || new_year > year_now);
- char date[11], d[3], m[3], y[5], add_dg[3] = "0", add_mg[3] = "0";
- itoa(new_day, d, 10);
- itoa(new_month, m, 10);
- itoa(new_year, y, 10);
- if(new_day < 10)
- {
- strcat(add_dg, d);
- strcpy(d, add_dg);
- }
- if(new_month < 10)
- {
- strcat(add_mg, m);
- strcpy(m, add_mg);
- }
- strcpy(date, d);
- strcat(date, "-");
- strcat(date, m);
- strcat(date, "-");
- strcat(date, y);
- updateAccount(login, 12, date, false);
- cout << "-> Data de emissao atualizada." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- void changeCargo(char login[])
- {
- Cop info = getAccountInfo(login);
- if(getIndexesSize(info.job, ':') != 0)
- {
- cout << "Esta conta já solicitou por uma mudança de cargo." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- return;
- }
- char new_job[100];
- system("CLS");
- cout << "-> Informe seu novo cargo." << endl;
- cout << "As opções de cargo aceitas são as seguintes:" << endl << endl;
- cout << " -> ";
- writeInColor("Coronel", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Tenente-Coronel", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Major", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Capitao", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("1 Tenente", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("2 Tenente", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Aspirante a Oficial", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Subtenente", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("1 Sargento", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("2 Sargento", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("3 Sargento", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Cabo", 4);
- cout << endl;
- cout << " -> ";
- writeInColor("Soldado", 4);
- cout << endl << endl;
- bool is_valid = true;
- do
- {
- if(!is_valid)
- cout << "Este cargo não é válido em nosso sistema. Por favor, reentre com este dado." << endl << endl;
- writeInColor(" Cargo", 9);
- cout << ": ";
- cin.getline(new_job, 100);
- adjustName(new_job);
- is_valid = false;
- system("CLS");
- } while(getAccessLevel(new_job) == 0);
- updateAccount(login, 10, new_job, false);
- cout << "-> Mudança de cargo solicitada." << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- void changePassword(char login[])
- {
- char new_password[11];
- system("CLS");
- cout << "-> Entre com a nova senha." << endl;
- cout << "MIN. 4 MÁX. 10 caracteres. APENAS LETRAS E NÚMEROS!" << endl << endl;
- bool same_passwords = true;
- do
- {
- if(!same_passwords)
- cout << "Senhas diferentes. Por favor, reentre com este dado." << endl << endl;
- bool check_password = true;
- do
- {
- if(!check_password)
- {
- system("CLS");
- cout << "Senha inválida." << endl;
- cout << "MIN. 4 MAX. 10 caracteres. APENAS LETRAS E NUMEROS!" << endl << endl;
- }
- int count = 0;
- writeInColor(" Senha", 9);
- cout << ": ";
- while(count <= 10)
- {
- if(count == 10) {new_password[10] = '\0'; break;}
- new_password[count] = _getch();
- if(new_password[count] == '\n' || new_password[count] == '\r')
- {
- new_password[count] = '\0';
- break;
- }
- cout << "*";
- count++;
- }
- system("CLS");
- } while(!isStringValid(new_password, CONST_PASSWORD_CHECK));
- char repeat_password[11];
- cout << "-> Repita a nova senha." << endl;
- int count = 0;
- writeInColor(" Senha", 9);
- cout << ": ";
- while(count <= 10)
- {
- if(count == 10) {repeat_password[10] = '\0'; break;}
- repeat_password[count] = _getch();
- if(repeat_password[count] == '\n' || repeat_password[count] == '\r')
- {
- repeat_password[count] = '\0';
- break;
- }
- cout << "*";
- count++;
- }
- same_passwords = strcmp(new_password, repeat_password) == 0 ? true : false;
- system("CLS");
- } while(!same_passwords);
- updateAccount(login, 4, new_password, false);
- cout << "-> Senha alterada com sucesso!" << endl << endl;
- cout << "Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- void showFullRegister(int access)
- {
- int total = getFileLineCount("cop_data.txt"), count = 0;
- file.open("cop_data.txt");
- char line[2000], *login[total];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int login_size = i[3] - i[2] - 1;
- char login_now[login_size];
- fillSentence(line, i[2], i[3], login_now);
- login[count] = new char[login_size];
- strcpy(login[count], login_now);
- count++;
- }
- file.close();
- if(total == 0)
- cout << "Não há registro de policiais no sistema." << endl << endl;
- else
- {
- char to_ch[5];
- itoa(total, to_ch, 10);
- cout << " (";
- writeInColor(to_ch, 9);
- cout << ") registro(s) no sistema." << endl << endl;
- printByArray(login, total, access, false);
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu anterior." << endl;
- _getch();
- }
- void showFullVillainRegister()
- {
- int total = getFileLineCount("bad_data.txt"), count = 0;
- int ID[total];
- file.open("bad_data.txt");
- char line[2000];
- while(file.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- ID[count] = atoi(ID_now);
- count++;
- }
- file.close();
- if(total == 0)
- cout << "Não há registro de criminosos." << endl << endl;
- else
- {
- char n[3];
- itoa(count, n, 10);
- cout << " (";
- writeInColor(n, 9);
- cout << ") registro(s) de criminoso(s)." << endl << endl;
- printByBadArray(ID, total);
- }
- cout << "-> Pressione qualquer tecla para voltar ao menu de pesquisa." << endl;
- _getch();
- }
- bool isIDValid(int ID)
- {
- char line[2000];
- ifstream file_now("bad_data.txt");
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, cmp_ID;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- cmp_ID = atoi(ID_now);
- if(cmp_ID == ID)
- {
- file_now.close();
- return false;
- }
- }
- file_now.close();
- return true;
- }
- void getOldLine(char get_line[])
- {
- int resp, cmpID = 0;
- char line[2000];
- ifstream file_tmp("bad_data.txt");
- cout << "-> O criminoso em questão possui um número de identifição?" << endl;
- resp = getYesOrNo();
- if(resp == 0)
- {
- do
- {
- bool check_ID = true;
- do
- {
- if(!check_ID)
- cout << "Identifição inválida. Por favor, reentre com esta informação." << endl << endl;
- cout << "-> Entre com a identificação." << endl;
- writeInColor(" ID", 9);
- cout << ": ";
- cin >> cmpID;
- check_ID = false;
- system("CLS");
- } while(cmpID <= 0);
- cout << "Identifição registrada: " << cmpID << endl << endl;
- cout << "Esta identificação está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- while(file_tmp.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, ID_to_number;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- ID_to_number = atoi(ID_now);
- if(ID_to_number == cmpID)
- {
- strcpy(get_line, line);
- break;
- }
- }
- }
- else
- {
- int line_count = 0, count = 0, wanted_line, all_options[getFileLineCount("bad_data.txt")];
- while(file_tmp.getline(line, 2000))
- {
- line_count++;
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, ID_to_number;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- ID_to_number = atoi(ID_now);
- if(ID_to_number <= 0)
- {
- char n[3];
- itoa(line_count, n, 10);
- cout << " OPÇÃO (";
- writeInColor(n, 9);
- cout << "): " << endl;
- all_options[count++] = line_count;
- printBadInfoAbout(ID_to_number);
- }
- }
- cout << "-> Entre com a opção desejada." << endl;
- int file_size = getFileLineCount("bad_data.txt");
- do
- {
- bool check_line = true;
- do
- {
- if(!check_line)
- {
- cout << "-> Opção inválida." << endl;
- cout << " Opções: " << endl << " ";
- for(int i = 0; i < count; i++)
- {
- cout << all_options[i];
- if(i != count - 1)
- cout << ", ";
- }
- cout << "." << endl << endl;
- }
- writeInColor(" Opção", 9);
- cout << ": ";
- cin >> wanted_line;
- check_line = false;
- system("CLS");
- } while(wanted_line <= 0 || wanted_line > file_size || !isInArray(all_options, count, wanted_line));
- cout << "Opção escolhida: " << wanted_line << endl << endl;
- cout << "Esta informação está correta?" << endl;
- resp = getYesOrNo();
- } while(resp == 1);
- file_tmp.close();
- file_tmp.open("bad_data.txt");
- line_count = 0;
- while(file_tmp.getline(line, 2000))
- {
- line_count++;
- if(line_count == wanted_line)
- {
- strcpy(get_line, line);
- break;
- }
- }
- }
- file_tmp.close();
- }
- void updateStatus()
- {
- char old_line[2000];
- getOldLine(old_line);
- cout << "-> Entre com o novo estado do criminoso." << endl;
- writeColorInfo("0");
- cout << " - Preso" << endl;
- writeColorInfo("1");
- cout << " - Foragido" << endl;
- writeColorInfo("2");
- cout << " - Livre" << endl;
- writeColorInfo("3");
- cout << " - Condicional" << endl;
- writeColorInfo("4");
- cout << " - Morto" << endl << endl;
- int input_status, resp;
- bool check_status = false;
- do
- {
- do
- {
- if(check_status)
- cout << "Estado inválido." << endl << endl;
- writeInColor(" Status", 9);
- cout << ": ";
- cin >> input_status;
- check_status = true;
- system("CLS");
- } while(input_status < 0 || input_status > 4);
- cout << "Estado escolhido: " << input_status << endl << endl;
- cout << "Esta informação está correta?" << endl;
- resp = getYesOrNo();
- } while(resp == 1);
- int ID = 0;
- if(input_status == 0)
- {
- cout << "-> Qual a identificação do prisioneiro?" << endl << endl;
- do
- {
- bool check_ID = true;
- do
- {
- if(!check_ID)
- cout << "Identifição inválida ou repetida. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" ID", 9);
- cout << ": ";
- cin >> ID;
- check_ID = false;
- system("CLS");
- } while(ID <= 0 || !isIDValid(ID));
- cout << "-> Identifição registrada: " << ID << endl << endl;
- cout << "Esta identificação está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- }
- char v[2];
- itoa(input_status, v, 10);
- updateBadLine(old_line, 12, v, ID);
- cout << " -> Atualização completa!" << endl << endl;
- cout << "O estado deste criminoso foi atualizado com sucesso." << endl;
- cout << "Pressione qualquer tecla para continuar." << endl;
- getch();
- }
- void updateAge()
- {
- char old_line[2000];
- getOldLine(old_line);
- int resp, age;
- do
- {
- bool check_age = true;
- do
- {
- if(!check_age)
- cout << "Idade inválida. Por gentileza, reentre com o dado correto." << endl << endl;
- cout << "-> Entre com a nova idade." << endl;
- writeInColor(" Idade", 9);
- cout << ": ";
- cin >> age;
- check_age = false;
- system("CLS");
- } while(age <= 0);
- cout << "Idade registrada: " << age << endl;
- cout << "Esta idade está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- char v[1000];
- itoa(age, v, 10);
- updateBadLine(old_line, 6, v, 0);
- cout << " -> Atualização completa!" << endl << endl;
- cout << "A idade deste criminoso foi atualizada com sucesso." << endl;
- cout << "Pressione qualquer tecla para continuar." << endl;
- getch();
- }
- void updateExtra()
- {
- char old_line[2000], extra[51];
- getOldLine(old_line);
- cout << "-> Entre com a nova informação extra." << endl;
- int resp;
- do
- {
- cin.ignore();
- bool check_extra = true;
- cout << "MIN. 1 MÁX. 50 caracteres." << endl << endl;
- do
- {
- if(!check_extra)
- cout << "Você fez uso de algum caractere inválido. Por favor, reentre com esta informação." << endl << endl;
- writeInColor(" Extra", 9);
- cout << ": ";
- cin.getline(extra, 51);
- check_extra = false;
- system("CLS");
- } while(!isStringValid(extra, CONST_SPECIFIC_CHECK));
- cout << "Informação extra registrada: " << extra << endl;
- cout << "Esta informação está correta?" << endl;
- resp = getYesOrNo();
- system("CLS");
- } while(resp == 1);
- updateBadLine(old_line, 14, extra, 0);
- cout << " -> Atualização completa!" << endl << endl;
- cout << "A informação adicional deste criminoso foi atualizada com sucesso." << endl;
- cout << "Pressione qualquer tecla para continuar." << endl;
- getch();
- }
- void updateBadLine(const char* input_line, int start, const char* new_input, int new_ID)
- {
- char old_line[2000], line[2000];
- strcpy(old_line, input_line);
- ifstream file_now("bad_data.txt");
- out_file.open("tmp.txt", ios_base::app | ios_base::out);
- while(file_now.getline(line, 2000))
- {
- if(strcmp(line, old_line) != 0)
- out_file << line << endl;
- }
- file_now.close();
- out_file.close();
- remove("bad_data.txt");
- rename("tmp.txt", "bad_data.txt");
- int i[getIndexesSize(old_line, '/')];
- getIndexesBySplittingSentence(old_line, '/', i);
- 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;
- 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;
- char get_ID[ID_size], name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
- char status[status_size], extra[extra_size];
- fillSentence(old_line, i[0], i[1], get_ID);
- fillSentence(old_line, i[2], i[3], name);
- fillSentence(old_line, i[4], i[5], nick);
- fillSentence(old_line, i[6], i[7], age);
- fillSentence(old_line, i[8], i[9], art);
- fillSentence(old_line, i[10], i[11], specific);
- fillSentence(old_line, i[12], i[13], status);
- fillSentence(old_line, i[14], i[15], extra);
- Villain new_info;
- if(new_ID != 0)
- new_info.ID = new_ID;
- else
- new_info.ID = atoi(get_ID);
- if(start == 6)
- new_info.age = atoi(new_input);
- else
- new_info.age = atoi(age);
- if(start == 12)
- new_info.status = atoi(new_input);
- else
- new_info.status = atoi(status);
- if(start == 14)
- strcpy(new_info.extra, new_input);
- else
- strcpy(new_info.extra, extra);
- strcpy(new_info.name, name);
- strcpy(new_info.nickname, nick);
- strcpy(new_info.art, art);
- strcpy(new_info.specific, specific);
- new_info.writeIntoBadFile();
- }
- Villain getVillainInfo(int ID)
- {
- Villain ret;
- ret.ID = ID;
- ifstream file_now("bad_data.txt");
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, cmp_ID;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- cmp_ID = atoi(ID_now);
- if(cmp_ID == ID)
- {
- int name_size = i[3] - i[2] - 1, nick_size = i[5] - i[4] - 1, age_size = i[7] - i[6] - 1;
- 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;
- char name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
- char status[status_size], extra[extra_size];
- fillSentence(line, i[2], i[3], name);
- fillSentence(line, i[4], i[5], nick);
- fillSentence(line, i[6], i[7], age);
- fillSentence(line, i[8], i[9], art);
- fillSentence(line, i[10], i[11], specific);
- fillSentence(line, i[12], i[13], status);
- fillSentence(line, i[14], i[15], extra);
- strcpy(ret.name, name);
- strcpy(ret.nickname, nick);
- ret.age = atoi(age);
- strcpy(ret.art, art);
- strcpy(ret.specific, specific);
- ret.status = atoi(status);
- strcpy(ret.extra, extra);
- break;
- }
- }
- file_now.close();
- return ret;
- }
- void printBadInfoAbout(int ID)
- {
- ifstream file_now("bad_data.txt");
- char line[2000];
- while(file_now.getline(line, 2000))
- {
- int i[getIndexesSize(line, '/')];
- getIndexesBySplittingSentence(line, '/', i);
- int ID_size = i[1] - i[0] - 1, cmp_ID;
- char ID_now[ID_size];
- fillSentence(line, i[0], i[1], ID_now);
- cmp_ID = atoi(ID_now);
- if(cmp_ID == ID)
- {
- int name_size = i[3] - i[2] - 1, nick_size = i[5] - i[4] - 1, age_size = i[7] - i[6] - 1;
- 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;
- char name[name_size], nick[nick_size], age[age_size], art[art_size], specific[specific_size];
- char status[status_size], extra[extra_size];
- fillSentence(line, i[2], i[3], name);
- fillSentence(line, i[4], i[5], nick);
- fillSentence(line, i[6], i[7], age);
- fillSentence(line, i[8], i[9], art);
- fillSentence(line, i[10], i[11], specific);
- fillSentence(line, i[12], i[13], status);
- fillSentence(line, i[14], i[15], extra);
- if(strcmp(name, "-1") == 0)
- cout << " -> Nome: desconhecido." << endl;
- else
- cout << " -> Nome: " << name << endl;
- if(strcmp(nick, "-1") == 0)
- cout << " -> Apelido: desconhecido." << endl;
- else
- cout << " -> Apelido: " << nick << endl;
- if(ID > 0)
- cout << " -> ID: " << ID << endl;
- if(atoi(age) == -1)
- cout << " -> Idade: desconhecida." << endl;
- else
- cout << " -> Idade: " << age << endl;
- if(strcmp(art, "outro") != 0)
- {
- cout << " -> Artigo: ";
- getArt(atoi(art), false);
- cout << "." << endl;
- }
- else
- {
- cout << " -> Artigo: outro." << endl;
- cout << " -> Especificação: " << specific << endl;
- }
- cout << " -> Status: ";
- switch(atoi(status))
- {
- case 0:
- writeInColor("preso", 4);
- break;
- case 1:
- writeInColor("foragido", 4);
- break;
- case 2:
- writeInColor("livre", 4);
- break;
- case 3:
- writeInColor("em condicional", 4);
- break;
- case 4:
- writeInColor("morto", 4);
- break;
- }
- cout << "." << endl;
- cout << " -> Informação extra: " << extra << endl << endl;
- break;
- }
- }
- file_now.close();
- }
- int getIndexesSize(char* line, char split_character)
- {
- int size = strlen(line) + 1, count = 0;
- bool continue_func = false;
- for(unsigned int i = 0; i < strlen(line); i++)
- {
- if(line[i] == split_character)
- {
- continue_func = true;
- break;
- }
- }
- if(!continue_func) return count;
- if(line[0] != split_character && line[strlen(line)] != split_character)
- size += 2;
- char working_on[size];
- if((unsigned int) size == strlen(line) + 1)
- strcpy(working_on, line);
- else
- {
- working_on[0] = ' ';
- working_on[size - 2] = ' ';
- for(int k = 1; k < size - 2; k++)
- working_on[k] = line[k - 1];
- working_on[size - 1] = '\0';
- }
- for(unsigned int i = 0; i <= strlen(working_on); i++)
- if(working_on[i] == split_character)
- count++;
- return count;
- }
- void SetColor(int ForgC)
- {
- WORD wColor;
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
- SetConsoleTextAttribute(hStdOut, wColor);
- }
- return;
- }
- void writeInColor(const char* phrase, int color)
- {
- SetColor(color);
- cout << phrase;
- SetColor(0);
- }
- void getIndexesBySplittingSentence(char* line, char split_character, int j[])
- {
- int size = strlen(line) + 1, count = 0;
- if(line[0] != split_character && line[strlen(line)] != split_character && split_character == ' ')
- size += 2;
- char working_on[size];
- if((unsigned int) size == strlen(line) + 1)
- strcpy(working_on, line);
- else
- {
- working_on[0] = ' ';
- working_on[size - 1] = ' ';
- for(int k = 1; k < size - 2; k++)
- working_on[k] = line[k - 1];
- working_on[size] = '\0';
- }
- for(unsigned int i = 0; i <= strlen(working_on); i++)
- if(working_on[i] == split_character)
- j[count++] = i;
- }
- void adjustName(char name[])
- {
- int size = getIndexesSize(name, ' ');
- cout << "";
- if(size == 0)
- name[0] = toupper(name[0]);
- else
- {
- int index[size];
- getIndexesBySplittingSentence(name, ' ', index);
- for(int i = 0; i < size - 1; i++)
- {
- int size = i[index + 1] - i[index] - 1, count = 0;
- char part[size];
- for(int j = index[i]; j < index[i + 1]; j++)
- part[count++] = name[j];
- part[sizeof(part)] = '\0';
- 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)
- name[index[i]] = toupper(name[index[i]]);
- }
- }
- }
- void toLower(char w[])
- {
- for(unsigned int i = 0; i < strlen(w); i++)
- w[i] = tolower(w[i]);
- }
- bool checkCombination(char login[], char password[])
- {
- bool var;
- Cop info = getAccountInfo(login);
- var = strcmp(info.password, password) == 0 ? true : false;
- return var;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement