Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef enum { false, true } bool;
- typedef enum { eletrico, computacao, civil, mecanico, quimico } tipo;
- typedef struct Engenheiro Engenheiro;
- struct Engenheiro {
- char nome[50];
- char cpf[25];
- char endereco[50];
- tipo tipo;
- };
- Engenheiro agenda[100];
- void runProgram();
- int addEngenheiro(int size);
- void listEngenheiro(int size);
- void updateEngenheiro(int index);
- int searchEngenheiro(int size);
- int removeEngenheiro(int index, int size);
- int inicializar();
- int main() {
- runProgram();
- return 0;
- }
- void runProgram() {
- bool run = true;
- int value;
- int contador = 0;
- contador = inicializar(contador);
- while (run == true) {
- printf("================================\n");
- printf("0 - CADASTRAR\n");
- printf("1 - LISTAR\n");
- printf("2 - PESQUISAR\n");
- printf("3 - ATUALIZAR\n");
- printf("4 - REMOVER\n");
- printf("5 - SAIR\n");
- printf("================================\n");
- printf("\nSelecione uma das opções: ");
- scanf("%d", &value);
- switch (value){
- case 0:
- contador = addEngenheiro(contador);
- break;
- case 1:
- listEngenheiro(contador);
- break;
- case 2:
- searchEngenheiro(contador);
- break;
- case 3:
- updateEngenheiro(searchEngenheiro(contador));
- break;
- case 4:
- contador = removeEngenheiro(searchEngenheiro(contador), contador);
- break;
- case 5:
- run = false;
- break;
- default:
- break;
- }
- }
- }
- int addEngenheiro(int size) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- printf("Qual nome: ");
- scanf("%s", nome);
- printf("\nQual CPF: ");
- scanf("%s", cpf);
- printf("\nQual Endereço: ");
- scanf("%s", endereco);
- printf("\nQual tipo: (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico)");
- scanf("%d", &tipo);
- strcpy(agenda[size].nome, nome);
- strcpy(agenda[size].cpf, cpf);
- strcpy(agenda[size].endereco, endereco);
- agenda[size].tipo = tipo;
- size++;
- printf("\nEngenheiro Adicionado com Sucesso\n");
- return size;
- }
- void listEngenheiro(int size) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- for (int i = 1; i < size; i++) {
- for (int j = 1; j < size; 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 (int i = 0; i < size; 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: %d\n\n", agenda[i].tipo);
- }
- }
- int searchEngenheiro(int size) {
- char nome[50];
- bool search = false;
- printf("Qual nome: ");
- scanf("%s", nome);
- for (int i = 0; i < size; 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: %d\n\n", agenda[i].tipo);
- return i;
- search = true;
- }
- }
- if (search == false) {
- printf("\nNenhum Engenheiro com este nome foi encontrado\n");
- }
- }
- void updateEngenheiro(int index) {
- char nome[50];
- char cpf[50];
- char endereco[50];
- tipo tipo = eletrico;
- printf("Qual novo nome: ");
- scanf("%s", nome);
- printf("\nQual novo CPF: ");
- scanf("%s", cpf);
- printf("\nQual novo Endereço: ");
- scanf("%s", endereco);
- printf("\nQual novo tipo: (0 = eletrico, 1 = computação, 2 = civil, 3 = mecanico, 4 = quimico)");
- scanf("%d", &tipo);
- strcpy(agenda[index].nome, nome);
- strcpy(agenda[index].cpf, cpf);
- strcpy(agenda[index].endereco, endereco);
- agenda[index].tipo = tipo;
- printf("\nEngenheiro Mudado com Sucesso\n");
- }
- int removeEngenheiro(int index, int size) {
- for (index; index < size; 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;
- }
- printf("\nEngenheiro Removido com Sucesso\n");
- size--;
- return size;
- }
- int inicializar(int contador) {
- strcpy(agenda[0].nome, "Gustavo");
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement