Advertisement
gonzalob

Untitled

May 28th, 2020
1,358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct
  5. {
  6.     int numeroExpediente;
  7.     char nombre [30];
  8.     float cuotas[3];
  9.     char sexo;
  10.     int numeroHabitacion;
  11.     char direccion[20];
  12.     char obraSocial[20];
  13. } paciente;
  14.  
  15. paciente cargarPaciente();
  16. void cargarPacienteConPuntero(paciente * punteroApaciente);
  17.  
  18.  
  19. int main()
  20. {
  21.     /*
  22.     paciente paciente1 = cargarPaciente();
  23.  
  24.     paciente paciente2 = cargarPaciente();
  25.  
  26.     mostrarPaciente(paciente1);
  27.  
  28.     mostrarPaciente(paciente2);
  29.  
  30.  
  31.     paciente paciente3;
  32.  
  33.     cargarPacienteConPuntero(&paciente3);
  34.  
  35.     mostrarPaciente(paciente3);
  36.  
  37.     */
  38.     int dim = 20;
  39.     paciente consultorio[20]; //un arreglo de estructura
  40.     int cantidadPacientes = cargarArreglo(consultorio,dim);
  41.     mostrarConsultorio(consultorio,cantidadPacientes);
  42.  
  43.     return 0;
  44. }
  45.  
  46. void mostrarConsultorio(paciente consultorio[20], int validos)
  47. {
  48.     int indice;
  49.     for (indice = 0;indice<validos;indice++)
  50.     {
  51.         //mostrarPaciente(consultorio[índice]);
  52.         paciente pacAux = consultorio[indice];
  53.         mostrarPaciente(pacAux);
  54.     }
  55. }
  56.  
  57. int cargarArreglo(paciente consultorio[20], int dim)
  58. {
  59.     int cantidadPacientes = 0;
  60.      char mander = 's';
  61.     while ((mander == 's')&&(cantidadPacientes<dim))
  62.     {
  63.         //consultorio[cantidadPacientes] = cargarPaciente();
  64.  
  65.         paciente pacAux = cargarPaciente();
  66.         consultorio[cantidadPacientes] = pacAux;
  67.  
  68.  
  69.         cantidadPacientes++;
  70.  
  71.         printf("hay otro paciente?\n");
  72.         fflush(stdin);
  73.         scanf("%c",&mander);
  74.     }
  75.     return cantidadPacientes;
  76. }
  77.  
  78. void cargarPacienteConPuntero(paciente * punteroApaciente)
  79. {
  80.     printf("numeroExpediente\n");
  81.     fflush(stdin);
  82.     scanf("%d",&punteroApaciente->numeroExpediente);//super valida!!!
  83.  
  84.     printf("nombre\n");
  85.     fflush(stdin);
  86.     scanf("%s",&punteroApaciente->nombre);//super valida!!!
  87.     printf("sexo\n");
  88.     fflush(stdin);
  89.     scanf("%c",&punteroApaciente->sexo);//super valida!!!
  90. }
  91.  
  92. paciente cargarPaciente()
  93. {
  94.     paciente pacienteLocal;
  95.  
  96.     //scanf("%????",&paciente1); invalida
  97.  
  98.     printf("numeroExpediente\n");
  99.     fflush(stdin);
  100.     scanf("%d",&pacienteLocal.numeroExpediente);//super valida!!!
  101.  
  102.     printf("nombre\n");
  103.     fflush(stdin);
  104.     scanf("%s",&pacienteLocal.nombre);//super valida!!!
  105.     printf("sexo\n");
  106.     fflush(stdin);
  107.     scanf("%c",&pacienteLocal.sexo);//super valida!!!
  108.  
  109.     int indiceCuotas;
  110.  
  111.     for (indiceCuotas=0;indiceCuotas<3;indiceCuotas++)
  112.     {
  113.         printf("ingrese cuota %d\n",indiceCuotas+1);
  114.         fflush(stdin);
  115.         scanf("%f",&pacienteLocal.cuotas[indiceCuotas]);
  116.     }
  117.  
  118.     return pacienteLocal;
  119. }
  120.  
  121. void mostrarPaciente(paciente pacAux)
  122. {
  123.     printf("%d\n",pacAux.numeroExpediente);
  124.     printf("%s\n",pacAux.nombre);
  125.     printf("%c\n",pacAux.sexo);
  126.  
  127.     int indiceCuotas;
  128.  
  129.     for (indiceCuotas=0;indiceCuotas<3;indiceCuotas++)
  130.     {
  131.         printf("cuota %d -> $ %f\n",indiceCuotas+1,pacAux.cuotas[indiceCuotas]);
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement