Advertisement
Guest User

Engenheiros - Lucas

a guest
Nov 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef enum { false, true } bool;
  4. typedef enum { eletrico, computacao, civil, mecanico, quimico } tipo;
  5. typedef struct Engenheiro Engenheiro;
  6.  
  7. struct Engenheiro {
  8.     char nome[50];
  9.     char cpf[25];
  10.     char endereco[50];
  11.     tipo tipo;
  12. };
  13.  
  14. Engenheiro agenda[100];
  15.  
  16. void runProgram();
  17. int addEngenheiro(int size);
  18. void listEngenheiro(int size);
  19. void updateEngenheiro(int index);
  20. int searchEngenheiro(int size);
  21. int removeEngenheiro(int index, int size);
  22.  
  23. int inicializar();
  24.  
  25. int main() {
  26.     runProgram();
  27.     return 0;
  28. }
  29.  
  30. void runProgram() {
  31.     bool run = true;
  32.     int value;
  33.     int contador = 0;
  34.  
  35.     contador = inicializar(contador);
  36.  
  37.     while (run == true) {
  38.         printf("================================\n");
  39.         printf("0 - CADASTRAR\n");
  40.         printf("1 - LISTAR\n");
  41.         printf("2 - PESQUISAR\n");
  42.         printf("3 - ATUALIZAR\n");
  43.         printf("4 - REMOVER\n");
  44.         printf("5 - SAIR\n");
  45.         printf("================================\n");
  46.         printf("\nSelecione uma das opções: ");
  47.         scanf("%d", &value);
  48.  
  49.         switch (value){
  50.         case 0:
  51.             contador = addEngenheiro(contador);
  52.             break;
  53.         case 1:
  54.             listEngenheiro(contador);
  55.             break;
  56.         case 2:
  57.             searchEngenheiro(contador);
  58.             break;
  59.         case 3:
  60.             updateEngenheiro(searchEngenheiro(contador));
  61.             break;
  62.         case 4:
  63.             contador = removeEngenheiro(searchEngenheiro(contador), contador);
  64.             break;
  65.         case 5:
  66.             run = false;
  67.             break;
  68.         default:
  69.             break;
  70.         }
  71.     }
  72.    
  73. }
  74.  
  75. int addEngenheiro(int size) {
  76.  
  77.     char nome[50];
  78.     char cpf[50];
  79.     char endereco[50];
  80.     tipo tipo = eletrico;
  81.  
  82.     printf("Qual nome: ");
  83.     scanf("%s", nome);
  84.  
  85.     printf("\nQual CPF: ");
  86.     scanf("%s", cpf);
  87.  
  88.     printf("\nQual Endereço: ");
  89.     scanf("%s", endereco);
  90.  
  91.     printf("\nQual tipo: (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico)");
  92.     scanf("%d", &tipo);
  93.  
  94.     strcpy(agenda[size].nome, nome);
  95.     strcpy(agenda[size].cpf, cpf);
  96.     strcpy(agenda[size].endereco, endereco);
  97.     agenda[size].tipo = tipo;
  98.     size++;
  99.  
  100.     printf("\nEngenheiro Adicionado com Sucesso\n");
  101.  
  102.     return size;
  103. }
  104.  
  105. void listEngenheiro(int size) {
  106.  
  107.     char nome[50];
  108.     char cpf[50];
  109.     char endereco[50];
  110.     tipo tipo = eletrico;
  111.  
  112.     for (int i = 1; i < size; i++) {
  113.         for (int j = 1; j < size; j++) {
  114.             if (strcmp(agenda[j - 1].nome, agenda[j].nome) > 0) {
  115.                 strcpy(nome, agenda[j - 1].nome);
  116.                 strcpy(agenda[j - 1].nome, agenda[j].nome);
  117.                 strcpy(agenda[j].nome, nome);
  118.  
  119.                 strcpy(cpf, agenda[j - 1].cpf);
  120.                 strcpy(agenda[j - 1].cpf, agenda[j].cpf);
  121.                 strcpy(agenda[j].cpf, cpf);
  122.  
  123.                 strcpy(endereco, agenda[j - 1].endereco);
  124.                 strcpy(agenda[j - 1].endereco, agenda[j].endereco);
  125.                 strcpy(agenda[j].endereco, endereco);
  126.  
  127.                 tipo = agenda[j - 1].tipo;
  128.                 agenda[j - 1].tipo = agenda[j].tipo;
  129.                 agenda[j].tipo = tipo;
  130.             }
  131.         }
  132.     }
  133.  
  134.     for (int i = 0; i < size; i++) {
  135.         printf("\nNome do individuo: %s\n", agenda[i].nome);
  136.         printf("CPF: %s\n", agenda[i].cpf);
  137.         printf("Endereco: %s\n", agenda[i].endereco);
  138.         printf("Tipo de Engenheiro: %d\n\n", agenda[i].tipo);
  139.     }
  140. }
  141.  
  142. int searchEngenheiro(int size) {
  143.     char nome[50];
  144.     bool search = false;
  145.  
  146.     printf("Qual nome: ");
  147.     scanf("%s", nome);
  148.  
  149.     for (int i = 0; i < size; i++) {
  150.         if (strcmp(nome, agenda[i].nome) == 0) {
  151.             printf("\nNome do individuo: %s\n", agenda[i].nome);
  152.             printf("CPF: %s\n", agenda[i].cpf);
  153.             printf("Endereco: %s\n", agenda[i].endereco);
  154.             printf("Tipo de Engenheiro: %d\n\n", agenda[i].tipo);
  155.             return i;
  156.             search = true;
  157.         }
  158.     }
  159.     if (search == false) {
  160.         printf("\nNenhum Engenheiro com este nome foi encontrado\n");
  161.     }
  162. }
  163.  
  164. void updateEngenheiro(int index) {
  165.  
  166.     char nome[50];
  167.     char cpf[50];
  168.     char endereco[50];
  169.     tipo tipo = eletrico;
  170.  
  171.     printf("Qual novo nome: ");
  172.     scanf("%s", nome);
  173.  
  174.     printf("\nQual novo CPF: ");
  175.     scanf("%s", cpf);
  176.  
  177.     printf("\nQual novo Endereço: ");
  178.     scanf("%s", endereco);
  179.  
  180.     printf("\nQual novo tipo: (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico)");
  181.     scanf("%d", &tipo);
  182.  
  183.     strcpy(agenda[index].nome, nome);
  184.     strcpy(agenda[index].cpf, cpf);
  185.     strcpy(agenda[index].endereco, endereco);
  186.     agenda[index].tipo = tipo;
  187.  
  188.     printf("\nEngenheiro Mudado com Sucesso\n");
  189. }
  190.  
  191. int removeEngenheiro(int index, int size) {
  192.     for (index; index < size; index++) {
  193.         strcpy(agenda[index].nome, agenda[index+1].nome);
  194.         strcpy(agenda[index].cpf, agenda[index + 1].cpf);
  195.         strcpy(agenda[index].endereco, agenda[index + 1].endereco);
  196.         agenda[index].tipo = agenda[index + 1].tipo;
  197.     }
  198.  
  199.     printf("\nEngenheiro Removido com Sucesso\n");
  200.  
  201.     size--;
  202.     return size;
  203. }
  204.  
  205. int inicializar(int contador) {
  206.     strcpy(agenda[0].nome, "Gustavo");
  207.     strcpy(agenda[0].cpf, "123456789");
  208.     strcpy(agenda[0].endereco, "Rua");
  209.     agenda[0].tipo = computacao;
  210.     contador++;
  211.  
  212.     strcpy(agenda[1].nome, "Ruan");
  213.     strcpy(agenda[1].cpf, "123456789");
  214.     strcpy(agenda[1].endereco, "Rua");
  215.     agenda[1].tipo = computacao;
  216.     contador++;
  217.  
  218.     strcpy(agenda[2].nome, "Amanda");
  219.     strcpy(agenda[2].cpf, "123456789");
  220.     strcpy(agenda[2].endereco, "Rua");
  221.     agenda[2].tipo = computacao;
  222.     contador++;
  223.  
  224.     strcpy(agenda[3].nome, "Beto");
  225.     strcpy(agenda[3].cpf, "123456789");
  226.     strcpy(agenda[3].endereco, "Rua");
  227.     agenda[3].tipo = computacao;
  228.     contador++;
  229.  
  230.     strcpy(agenda[4].nome, "Pedro");
  231.     strcpy(agenda[4].cpf, "123456789");
  232.     strcpy(agenda[4].endereco, "Rua");
  233.     agenda[4].tipo = computacao;
  234.     contador++;
  235.  
  236.     strcpy(agenda[5].nome, "Tiago");
  237.     strcpy(agenda[5].cpf, "777777");
  238.     strcpy(agenda[5].endereco, "RuaAlpaca");
  239.     agenda[5].tipo = eletrico;
  240.     contador++;
  241.  
  242.     strcpy(agenda[6].nome, "Olivia");
  243.     strcpy(agenda[6].cpf, "123456789");
  244.     strcpy(agenda[6].endereco, "Rua");
  245.     agenda[6].tipo = computacao;
  246.     contador++;
  247.  
  248.     strcpy(agenda[7].nome, "Igor");
  249.     strcpy(agenda[7].cpf, "123456789");
  250.     strcpy(agenda[7].endereco, "Rua");
  251.     agenda[7].tipo = computacao;
  252.     contador++;
  253.  
  254.     strcpy(agenda[8].nome, "Xayah");
  255.     strcpy(agenda[8].cpf, "123456789");
  256.     strcpy(agenda[8].endereco, "Rua");
  257.     agenda[8].tipo = computacao;
  258.     contador++;
  259.  
  260.     strcpy(agenda[9].nome, "Junior");
  261.     strcpy(agenda[9].cpf, "123456789");
  262.     strcpy(agenda[9].endereco, "Rua");
  263.     agenda[9].tipo = computacao;
  264.     contador++;
  265.  
  266.     return contador;
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement