Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <locale.h>
- typedef enum { eletrico, computacao, civil, mecanico, quimico } tipo;
- typedef struct {
- char nome[50];
- char cpf[25];
- char endereco[50];
- tipo tipo;
- }Engenheiro;
- Engenheiro agenda[100];
- Engenheiro favoritos[100];
- void rodar_programa();
- void listar_engenheiro(int contador);
- void listar_favoritos(int contadorfav);
- int adicionar_favoritos(int index, int contadorfav);
- void atualizar_engenheiro(int index);
- int adicionar_engenheiro(int contador, int contadorfav);
- int procurar_engenheiro(int contador);
- int remover_engenheiro(int index, int contador, int who);
- int inicializar(int contador);
- char* getTipoEngenheiro(tipo enumerador);
- int main() {
- setlocale(LC_ALL, "Portuguese");
- rodar_programa();
- return 0;
- }
- void rodar_programa() {
- int op, fav;
- int contador = 0;
- int contadorfav = 0;
- int whil = 1;
- contador = inicializar(contador);
- while (whil == 1) {
- printf("================================\n"); // MENU PRINCIPAL
- printf("0 - CADASTRAR\n"); // MENU PRINCIPAL
- printf("1 - LISTAR\n"); // MENU PRINCIPAL
- printf("2 - PESQUISAR\n"); // MENU PRINCIPAL
- printf("3 - ATUALIZAR\n"); // MENU PRINCIPAL
- printf("4 - REMOVER\n"); // MENU PRINCIPAL
- printf("5 - SAIR\n"); // MENU PRINCIPAL
- printf("6 - FAVORITOS\n"); // MENU PRINCIPAL
- printf("================================\n"); // MENU PRINCIPAL
- printf("\nSelecione uma das opções: "); // MENU PRINCIPAL
- scanf("%d", &op);
- getchar();
- switch (op) {
- case 0:
- contador = adicionar_engenheiro(contador, contadorfav);
- break;
- case 1:
- listar_engenheiro(contador);
- break;
- case 2:
- procurar_engenheiro(contador);
- break;
- case 3:
- atualizar_engenheiro(procurar_engenheiro(contador));
- break;
- case 4:
- contador = remover_engenheiro(procurar_engenheiro(contador), contador, 1);
- break;
- case 5:
- whil = 0;
- case 6:
- printf("\n\n=========================================\n");
- printf("1 - ADICIONAR ENGENHEIRO AOS FAVORITOS\n");
- printf("2 - LISTAR FAVORITOS\n");
- printf("3 - REMOVER FAVORITOS\n");
- printf("\n===========================================\n\n");
- scanf("%d", &fav);
- if (fav == 1)
- {
- contadorfav = adicionar_favoritos(procurar_engenheiro(contador), contadorfav);
- break;
- }
- if (fav == 2)
- {
- listar_favoritos(contadorfav);
- break;
- }
- if (fav == 3) {
- contadorfav = remover_engenheiro(procurar_engenheiro(contadorfav), contadorfav, 0);
- }
- default:
- break;
- }
- }
- }
- int adicionar_engenheiro(int contador, int contadorfav) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- int op;
- printf("Insira o nome (Digite a Primeira Letra Maiscula!): ");
- scanf(" %[^\n]s", nome);
- printf("\nInsira o cpf: ");
- scanf(" %[^\n]s", cpf);
- printf("\nInsira o Endereço: ");
- scanf(" %[^\n]s", endereco);
- printf("\nInsira o tipo: (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico)");
- scanf("%d", &tipo);
- strcpy(agenda[contador].nome, nome);
- strcpy(agenda[contador].cpf, cpf);
- strcpy(agenda[contador].endereco, endereco);
- agenda[contador].tipo = tipo;
- contador++;
- printf("\nEngenheiro Adicionado com Sucesso\n");
- return contador;
- }
- void listar_engenheiro(int contador) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- int i, j;
- for (i = 1; i < contador; i++) {
- for (j = 1; j < contador; j++) {
- if (strcmp(agenda[j - 1].nome, agenda[j].nome) > 0) {
- strcpy(nome, agenda[j - 1].nome);
- strcpy(agenda[j - 1].nome, agenda[j].nome);
- strcpy(agenda[j].nome, nome);
- strcpy(cpf, agenda[j - 1].cpf);
- strcpy(agenda[j - 1].cpf, agenda[j].cpf);
- strcpy(agenda[j].cpf, cpf);
- strcpy(endereco, agenda[j - 1].endereco);
- strcpy(agenda[j - 1].endereco, agenda[j].endereco);
- strcpy(agenda[j].endereco, endereco);
- tipo = agenda[j - 1].tipo;
- agenda[j - 1].tipo = agenda[j].tipo;
- agenda[j].tipo = tipo;
- }
- }
- }
- for (i = 0; i < contador; i++) {
- printf("\nNome do individuo: %s\n", agenda[i].nome);
- printf("CPF: %s\n", agenda[i].cpf);
- printf("Endereco: %s\n", agenda[i].endereco);
- printf("Tipo de Engenheiro: %s\n\n", getTipoEngenheiro(agenda[i].tipo));
- }
- }
- int procurar_engenheiro(int contador) { // Função para Procurar Engenheiros
- char nome[50];
- int i;
- setlocale(LC_ALL, "Portuguese");
- printf("Qual nome: ");
- scanf("%s", nome);
- for (i = 0; i < contador; i++) {
- if (strcmp(nome, agenda[i].nome) == 0)
- {
- printf("\nNome do individuo: %s\n", agenda[i].nome);
- printf("CPF: %s\n", agenda[i].cpf);
- printf("Endereco: %s\n", agenda[i].endereco);
- printf("Tipo de Engenheiro: %s\n\n", getTipoEngenheiro(agenda[i].tipo));
- return i;
- }
- }
- if (strcmp(nome, agenda[i].nome) != 0)
- {
- printf("\nNenhum Engenheiro com este nome foi encontrado\n");
- return -1;
- }
- }
- void atualizar_engenheiro(int index) { // Função da Atualização dos dados dos engenheiros cadastrados
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- printf("Insira o novo nome: (Digite a Primeira Letra Maiscula!)");
- scanf("%s", nome);
- printf("\nInsira o novo Endereço: ");
- scanf("%s", endereco);
- printf("\nInsira o novo tipo (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico):");
- scanf("%d", &tipo);
- strcpy(agenda[index].nome, nome);
- strcpy(agenda[index].endereco, endereco);
- agenda[index].tipo = tipo;
- printf("\nEngenheiro Atualizado com Sucesso\n");
- }
- int remover_engenheiro(int index, int contador, int who) { // Essa Função Remove o engenheiro procurado.
- if (index == -1) {
- return contador;
- }
- if (who == 1) {
- for (index; index < contador; index++) {
- strcpy(agenda[index].nome, agenda[index + 1].nome);
- strcpy(agenda[index].cpf, agenda[index + 1].cpf);
- strcpy(agenda[index].endereco, agenda[index + 1].endereco);
- agenda[index].tipo = agenda[index + 1].tipo;
- }
- }
- else {
- for (index; index < contador; index++) {
- strcpy(favoritos[index].nome, favoritos[index + 1].nome);
- strcpy(favoritos[index].cpf, favoritos[index + 1].cpf);
- strcpy(favoritos[index].endereco, favoritos[index + 1].endereco);
- favoritos[index].tipo = favoritos[index + 1].tipo;
- }
- }
- printf("\nEngenheiro removido com sucesso!");
- contador--;
- return contador;
- }
- int adicionar_favoritos(int contador, int contadorfav) {
- int op;
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- printf("\nDeseja Adicionar aos favoritos?: (1) PARA SIM (0) PARA NÃO \n\n");
- scanf("%d", &op);
- if (op == 1) {
- strcpy(favoritos[contadorfav].nome, agenda[contador].nome);
- strcpy(favoritos[contadorfav].cpf, agenda[contador].cpf);
- strcpy(favoritos[contadorfav].endereco, agenda[contador].endereco);
- favoritos[contadorfav].tipo = agenda[contador].tipo;
- printf("\nAdicionado com sucesso!!!\n\n");
- contadorfav++;
- return contadorfav;
- }
- }
- void listar_favoritos(int contadorfav) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- int i, j;
- for (i = 1; i < contadorfav; i++) {
- for (j = 1; j < contadorfav; j++) {
- if (strcmp(favoritos[j - 1].nome, favoritos[j].nome) > 0) {
- strcpy(nome, favoritos[j - 1].nome);
- strcpy(favoritos[j - 1].nome, favoritos[j].nome);
- strcpy(favoritos[j].nome, nome);
- strcpy(cpf, favoritos[j - 1].cpf);
- strcpy(favoritos[j - 1].cpf, favoritos[j].cpf);
- strcpy(favoritos[j].cpf, cpf);
- strcpy(endereco, favoritos[j - 1].endereco);
- strcpy(favoritos[j - 1].endereco, favoritos[j].endereco);
- strcpy(favoritos[j].endereco, endereco);
- tipo = favoritos[j - 1].tipo;
- favoritos[j - 1].tipo = favoritos[j].tipo;
- favoritos[j].tipo = tipo;
- }
- }
- }
- for (i = 0; i < contadorfav; i++) {
- printf("\nNome do individuo: %s\n", favoritos[i].nome);
- printf("CPF: %s\n", favoritos[i].cpf);
- printf("Endereco: %s\n", favoritos[i].endereco);
- printf("Tipo de Engenheiro: %s\n\n", getTipoEngenheiro(favoritos[i].tipo));
- }
- }
- int inicializar(int contador) {
- strcpy(agenda[0].nome, "Gustavo"); // Essa Função Pré estabelece os engenheiros já cadastrados no sistema.
- strcpy(agenda[0].cpf, "123456789");
- strcpy(agenda[0].endereco, "Rua");
- agenda[0].tipo = computacao;
- contador++;
- strcpy(agenda[1].nome, "Ruan");
- strcpy(agenda[1].cpf, "123456789");
- strcpy(agenda[1].endereco, "Rua");
- agenda[1].tipo = computacao;
- contador++;
- strcpy(agenda[2].nome, "Amanda");
- strcpy(agenda[2].cpf, "123456789");
- strcpy(agenda[2].endereco, "Rua");
- agenda[2].tipo = computacao;
- contador++;
- strcpy(agenda[3].nome, "Beto");
- strcpy(agenda[3].cpf, "123456789");
- strcpy(agenda[3].endereco, "Rua");
- agenda[3].tipo = computacao;
- contador++;
- strcpy(agenda[4].nome, "Pedro");
- strcpy(agenda[4].cpf, "123456789");
- strcpy(agenda[4].endereco, "Rua");
- agenda[4].tipo = computacao;
- contador++;
- strcpy(agenda[5].nome, "Tiago");
- strcpy(agenda[5].cpf, "777777");
- strcpy(agenda[5].endereco, "RuaAlpaca");
- agenda[5].tipo = eletrico;
- contador++;
- strcpy(agenda[6].nome, "Olivia");
- strcpy(agenda[6].cpf, "123456789");
- strcpy(agenda[6].endereco, "Rua");
- agenda[6].tipo = computacao;
- contador++;
- strcpy(agenda[7].nome, "Igor");
- strcpy(agenda[7].cpf, "123456789");
- strcpy(agenda[7].endereco, "Rua");
- agenda[7].tipo = computacao;
- contador++;
- strcpy(agenda[8].nome, "Xayah");
- strcpy(agenda[8].cpf, "123456789");
- strcpy(agenda[8].endereco, "Rua");
- agenda[8].tipo = computacao;
- contador++;
- strcpy(agenda[9].nome, "Junior");
- strcpy(agenda[9].cpf, "123456789");
- strcpy(agenda[9].endereco, "Rua");
- agenda[9].tipo = computacao;
- contador++;
- return contador;
- }
- char* getTipoEngenheiro(tipo enumerador) { // Função para retornar String.
- static char tipo[50];
- if (enumerador == eletrico) {
- strcpy(tipo, "Elétrico");
- }
- else if (enumerador == computacao) {
- strcpy(tipo, "Computação");
- }
- else if (enumerador == civil) {
- strcpy(tipo, "Civil");
- }
- else if (enumerador == mecanico) {
- strcpy(tipo, "Mecanico");
- }
- else if (enumerador == quimico) {
- strcpy(tipo, "Quimico");
- }
- return tipo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement