Open oregonyuky opened 2 weeks ago
#include <stdio.h> #include <ctype.h> #include <string.h> #include <conio.h> #include <stdlib.h> #define TF 5 struct Endereco{ char rua[30], complemento[30], bairro[30], cep[30], cidade[30], numero[30]; }; struct Telefone{ int ddd, numeros; }; struct DataAniversario{ int dia, mes, ano; }; struct TpDados{ char nome[30], email[30]; Endereco E1; Telefone T1; DataAniversario D1; }; char menu(){ system("cls"); printf("[A] Cadastrar o nome\n"); printf("[B] Buscar por primeiro nome\n"); printf("[C] busca por mes de aniversario\n"); printf("[D] busca por dia e mes de aniversario\n"); printf("[E] retira pessoa\n"); printf("[F] Exibir dados\n"); return toupper(getch()); } void CadastroDados(TpDados vetAgenda,int &TL); void BuscaNome(TpDados vetAgenda, int TL); void busca_mes(TpDados vetAgenda, int TL); void busca_dia_mes(TpDados vetAgenda, int TL); void Retira(TpDados vetAgenda, int &TL); void prints(TpDados vetAgenda); void Exibir(TpDados vetAgenda, int TL); TpDados leRegistro(TpDados vetAgenda[TF], int TL){ TpDados reg; char nome[30]; printf("Digite o nome:\n"); fflush(stdin); gets(reg.nome); int canInsert = 1; for(int i = 0; i < TL && canInsert; i++) { if(strcmp(vetAgenda[i].nome, reg.nome) == 0) canInsert = 0; } if(canInsert) { printf("Digite o e-mail:\n"); fflush(stdin); gets(reg.email); fflush(stdin); printf("Digite a rua, numero, complemento, bairro, cep, cidade respectivamente:\n"); gets(reg.E1.rua); fflush(stdin); gets(reg.E1.numero); fflush(stdin); gets(reg.E1.complemento); fflush(stdin); gets(reg.E1.bairro); fflush(stdin); gets(reg.E1.cep); fflush(stdin); gets(reg.E1.cidade); printf("Digite o DDD e o numero respectivamente:\n"); fflush(stdin); scanf("%d", ®.T1.ddd); fflush(stdin); scanf("%d", ®.T1.numeros); printf("Digite a data de nascimento:\n"); fflush(stdin); scanf("%d", ®.D1.dia); fflush(stdin); scanf("%d", ®.D1.mes); fflush(stdin); scanf("%d", ®.D1.ano); fflush(stdin); } else { reg.nome[0] = '0'; puts("Nome ja existe"); } return reg; } void bubblesortstring(TpDados vetAgenda[TF], int TL){ int i, flag=1; TpDados aux; while(i>0 && flag){ flag=0; for(int i=0;i<TL-1;i++){ if(strcmp(vetAgenda[i].nome, vetAgenda[i+1].nome)>0){ aux = vetAgenda[i]; vetAgenda[i] = vetAgenda[i+1]; vetAgenda[i+1] = aux; flag=1; } } TL--; } } void CadastroDados(TpDados vetAgenda[TF], int &TL){ system("cls"); char tecla; TpDados regaux; do{ TpDados reg = leRegistro(vetAgenda, TL); if(reg.nome[0] != '0') vetAgenda[TL++] = reg; printf("Deseja continuar?<S/N>\n"); tecla = toupper(getch()); }while(tecla=='S'); bubblesortstring(vetAgenda, TL); getch(); } void BuscaNome(TpDados vetAgenda[TF], int TL) { system("cls"); char nome[30], op; do { printf("Digite o nome:\n"); fflush(stdin); gets(nome); int encontrado = 0; for (int i = 0; i < TL; i++) { int pos = 0; while (pos < strlen(vetAgenda[i].nome) && pos < strlen(nome) && vetAgenda[i].nome[pos] == nome[pos]) { pos++; } if (pos == strlen(nome) && (vetAgenda[i].nome[pos] == ' ' || vetAgenda[i].nome[pos] == '\0')) { prints(vetAgenda[i]); encontrado = 1; } } if (!encontrado) { printf("Nome não encontrado.\n"); } printf("Deseja continuar? <S/N>\n"); op = toupper(getch()); } while (op == 'S'); } void busca_mes(TpDados vetAgenda[TF], int TL){ system("cls"); int mes; char tecla; do{ printf("Digite o Mes\n"); fflush(stdin); scanf("%d", &mes); for(int i=0;i<TL;i++){ if(vetAgenda[i].D1.mes==mes); prints(vetAgenda[i]); } printf("Deseja continuar?<S/N>\n"); tecla=toupper(getch()); }while(tecla=='S'); getch(); } void busca_dia_mes(TpDados vetAgenda[TF], int TL){ system("cls"); int dia, mes; char tecla; do{ printf("Digite o dia:\n"); scanf("%d", &dia); printf("Digite o mes:\n"); scanf("%d", &mes); for(int i=0;i<TL;i++){ if(vetAgenda[i].D1.mes==mes && vetAgenda[i].D1.dia==dia) prints(vetAgenda[i]); } printf("deseja continuar?<S/N>\n"); tecla = toupper(getch()); }while(tecla=='S'); getch(); } void ordenacao(TpDados vetAgenda[TF], int TL){ TpDados aux; for(int i=1;i<TL;i++){ strcpy(aux.nome, vetAgenda[i].nome); int j=i-1; while(j>=0 && strcmp(vetAgenda[i].nome, aux.nome)!=0){ vetAgenda[j+1] = vetAgenda[j]; j--; } vetAgenda[j+1] = aux; } } void Retira(TpDados vetAgenda[TF], int &TL){ system("cls"); char nome[30], op; int pos; do{ printf("Digite o nome para retirar:\n"); fflush(stdin); gets(nome); pos=0; while(pos<TL && strcmp(vetAgenda[pos].nome, nome)!=0) pos++; if(pos<TL){ for(int i=pos;i<TL-1;i++){ vetAgenda[i] = vetAgenda[i+1]; } TL--; } printf("Deseja continuar?<S/n>\n"); op = toupper(getch()); }while(op=='S'); getch(); } void prints(TpDados vetAgend){ printf("Nome: %s\n", vetAgend.nome); printf("E-mail: %s\n", vetAgend.email); printf("Rua: %s\n", vetAgend.E1.rua); printf("Numero: %s\n", vetAgend.E1.numero); printf("Complemento: %s\n", vetAgend.E1.complemento); printf("Bairro: %s\n", vetAgend.E1.bairro); printf("Cep: %s\n", vetAgend.E1.cep); printf("Cidade: %s\n", vetAgend.E1.cidade); printf("DDD: %d\n", vetAgend.T1.ddd); printf("numero de tel: %d\n", vetAgend.T1.numeros); printf("Data de nascimento: %d/%d/%d\n", vetAgend.D1.dia, vetAgend.D1.mes, vetAgend.D1.ano); } void Exibir(TpDados vetAgend[TF], int TL){ for(int i=0;i<TL;i++){ printf("Nome: %s\n", vetAgend[i].nome); printf("E-mail: %s\n", vetAgend[i].email); printf("Rua: %s\n", vetAgend[i].E1.rua); printf("Numero: %s\n", vetAgend[i].E1.numero); printf("Complemento: %s\n", vetAgend[i].E1.complemento); printf("Bairro: %s\n", vetAgend[i].E1.bairro); printf("Cep: %s\n", vetAgend[i].E1.cep); printf("Cidade: %s\n", vetAgend[i].E1.cidade); printf("DDD: %d\n", vetAgend[i].T1.ddd); printf("numero de tel: %d\n", vetAgend[i].T1.numeros); printf("Data de nascimento: %d/%d/%d\n", vetAgend[i].D1.dia, vetAgend[i].D1.mes, vetAgend[i].D1.ano); printf("\n"); } getch(); } int main(){ TpDados vetAgenda[TF]; char tecla; int TL=0; do{ tecla = menu(); switch(tecla){ case 'A':CadastroDados(vetAgenda, TL);break; case 'B':BuscaNome(vetAgenda, TL);break; case 'C':busca_mes(vetAgenda, TL);break; case 'D':busca_dia_mes(vetAgenda, TL);break; case 'E':Retira(vetAgenda, TL);break; case 'F':Exibir(vetAgenda, TL);break; } }while(tecla!=27); } ´´´
You seem to know for and Bubblezada inside out!
for
Bubblezada