Advertisement
ThaisAlmeida

2011.2 questão 2

Aug 4th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5.  
  6. typedef struct{
  7.  
  8. char rua[30];
  9. char bairro[10];
  10. char cidade[10];
  11. }endereco;
  12.  
  13.  
  14. typedef struct{
  15.  
  16. char nome[30];
  17. int idade;
  18. char telefone[10];
  19. endereco endereco;
  20. }AGENDA;
  21.  
  22.  
  23. typedef struct{
  24.  
  25. char nome[30];
  26. int idade;
  27. char rua[30];
  28. char bairro[10];
  29. }SAIDA;
  30.  
  31. void Cadastro(AGENDA *agenda, FILE *arquivo,FILE *arquivo2, endereco *endereco,SAIDA *saida){
  32.  
  33. char resposta,bairro[10],cidade[10];
  34. int i=0,soma=0,contatos=0,media=0;
  35.  
  36. printf("Deseja realizar um novo cadastro?(S/N)/n");
  37. gets(resposta);
  38.  
  39. do{
  40.  
  41. printf("Digite o nome:/n");
  42. gets(agenda->nome);
  43.  
  44. printf("Digite a idade:/n");
  45. scanf("%d", &agenda->idade);
  46.  
  47. printf("Digite o telefone:/n");
  48. gets(agenda->telefone);
  49.  
  50. printf("Digite a rua:/n");
  51. gets(agenda->endereco->rua);
  52.  
  53. printf("Digite o bairro:/n");
  54. gets(agenda->endereco->bairro);
  55.  
  56. printf("Digite a cidade:/n");
  57. gets(agenda->endereco->cidade);
  58.  
  59. fwrite(arquivo,sizeof(AGENDA),1,arquivo);
  60.  
  61. }while(resposta == "s");
  62.  
  63.  
  64. printf("Digite o nome da cidade que deseja pesquisar:/n");
  65. gets(cidade);
  66.  
  67. rewind(arquivo);
  68.     while (!feof(arquivo)){
  69.        fread(agenda, sizeof(AGENDA),1, arquivo);
  70.         if (strcmp(endereco.cidade, cidade){
  71.  
  72.             AGENDA.nome = SAIDA.nome;
  73.             AGENDA.idade = SAIDA.idade;
  74.             endereco.rua = SAIDA.rua;
  75.             endereco.bairro = SAIDA.bairro;
  76.             i++;
  77.  
  78.             }else{
  79.  
  80.              printf("Cidade inexistente!");
  81.             }
  82.  
  83. if(i>50){
  84.  
  85. printf("Digite o nome do bairro:/n");
  86. gets(bairro);
  87.  
  88. while (!feof(arquivo)){
  89.        fread(agenda, sizeof(AGENDA),1, arquivo);
  90.         if (strcmp(endereco.bairro, bairro){
  91.             contatos++;
  92.             soma = soma + AGENDA.idade;
  93.             }
  94. }
  95.  
  96. media = soma/contatos;
  97. printf("A media eh %d:/n", media);
  98.  
  99. }
  100.  
  101. }
  102.  
  103. int main(){
  104.  
  105. FILE *arquivo1; FILE *arquivo2;
  106. arquivo1 = fopen("AGENDA.CAD","w+b");
  107. arquivo2 = fopen("SAIDA.DAT","w+b");
  108.  
  109. Cadastro(*agenda, *arquivo1, *arquivo2, *endereco, *saida);
  110.  
  111. fclose(arquivo1);
  112. fclose(arquivo2);
  113.  
  114. getche(0);
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement