#include <stdio.h> #include <conio.h> #include <string.h> void carga1 (char (*)[3],char (*)[30]); void carga2 (int (*)[3],int (*)[3], char (*)[3]); int busq1(char (*)[3],char *); int busq2(char (*)[3],char *); void procesar(char (*)[3], int *); void mostrar1(int *,char (*)[30]); void mostrar2(int (*)[3],char (*)[30]); void main(void) { int vcp[10]; char vciu[3][3]; char vnom[3][30]; int mpu[3][3],mdist[3][3];
carga1(vciu,vnom); carga2(mpu,mdist,vciu); procesar(vciu,vcp); mostrar1(vcp,vnom); mostrar2(mdist,vnom); getch(); }
void carga1 (char (*pcc)[3],char (*pnm)[30]) { for(int i=0; i<3; i++) { gets(pcc[i]); gets(pnm[i]); } getch(); } void carga2 (int (*mp)[3],int (*md)[3], char *pcc ) { char co[3],cd[3]; int posd,poso; fflush(stdin); printf("\n ciudad de origen "); gets(co); fflush(stdin); printf("\n ciudad de destino "); gets(cd);
posd=busq1(pcc,cd); poso=busq2(pcc,co);
printf("\n ingrese precio "); scanf("%d",&mp[poso][posd]); printf("\n ingrese distancia "); scanf("%d",&md[poso][posd]);
} void procesar(char (*pcc)[3], int *pcp) { char co[3],cd[3]; int cant,posd;
for(int i=0; i<10; i++) { pcp[i]=0; }
fflush(stdin); printf("\n ciudad de origen "); gets(co); fflush(stdin); printf("\n ciudad de destino "); gets(cd); printf("\n cantidad pasajes vendidos "); scanf("%d",&cant);
while(cant!=0) { posd=busq1(pcc,cd); pcp[posd]+=cant;
} getch(); } int busq1 (char (*pcc)[3], char *d) { int i=0,pos; while(strcmp(pcc[i],d)!=0 && i<3) { i++; } if(strcmp(pcc[i],d)==0) { pos=i; } else { pos=-1; }
return pos;
}
int busq2 (char (*pcc)[3], char *o) { int i=0,pos; while(strcmp(pcc[i],o)!=0 && i<3) { i++; } if(strcmp(pcc[i],o)==0) { pos=i; } else { pos=-1; }
return pos;
} void mostrar1(int *pcp,char (*pnm)[30]) { int max,posmx; max=pcp[0]; posmx=0;
for(int i=0; i<10; i++) { if(pcp[i]>max) { max=pcp[i]; posmx=i; } }
printf( " la ciudad con mayor cantidad de pasajeros su nombre es %s \n",pnm[posmx]); getch(); } void mostrar2(int (*md)[3],char (*pnm)[30]) { int mx,pmx;
for(int i=0; i<3; i++) { mx=md[i][0]; pmx=0; for(int j=0; j<3; j++) { if(md[i][j]>mx) { mx=md[i][j]; pmx=j; } } printf( " ciudad %s ciudad mas distante es %s \n",pnm[i],pnm[pmx]); } getch(); }
|