Guest User

Untitled

a guest
Oct 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5.  
  6. typedef struct agenda{
  7. char nombre[20];
  8. char direccion[30];
  9. char tel[20];
  10. int calculado;
  11. } Agenda;
  12.  
  13. /* Arreglo que almacena en agenda */
  14. Agenda agenda[100];
  15. /* Contiene el numero de personas actual */
  16. int total = 0;
  17. void presentacion();
  18. void cargar(), guardar(), insertar(Agenda info);
  19. void ingresar(),modificar(), eliminar(), mostrar();
  20. char menu(void);
  21.  
  22. void main(void)
  23. {
  24. clrscr();
  25. cargar();
  26. presentacion();
  27. clrscr();
  28. char op;
  29.  
  30. for(;;)
  31. {
  32. switch(op=menu())
  33. {
  34. case '1':
  35. ingresar();
  36. getch();
  37. break;
  38.  
  39. case '2':
  40. modificar();
  41. getch();
  42. break;
  43. case '3':
  44. eliminar();
  45. getch();
  46. break;
  47.  
  48. case '4':
  49. mostrar();
  50. getch();
  51. break;
  52. case '5':
  53. break;
  54. default :
  55. printf("Opcion no valida");
  56. getch();
  57. break;
  58. }
  59.  
  60. if(op=='5') return;
  61. clrscr();
  62. }
  63.  
  64.  
  65. }
  66.  
  67.  
  68. void insertar(Agenda info)
  69. {
  70. strcpy(agenda[total].nombre, info.nombre);
  71. strcpy(agenda[total].direccion, info.direccion);
  72. strcpy(agenda[total].tel, info.tel);
  73. agenda[total].calculado= info.calculado;
  74. total++;
  75. }
  76.  
  77. void cargar()
  78. {
  79. Agenda info;
  80. FILE *fp;
  81.  
  82. fp=fopen("agenda.txt","r");
  83. if(fp==NULL)
  84. {
  85. printf("No se puede abrir el archivo\n");
  86. return;
  87. }
  88.  
  89. while(!feof(fp))
  90. {
  91. if(fread(&info, sizeof(Agenda), 1, fp)!=1) break;
  92. insertar(info);
  93. }
  94.  
  95. fclose(fp);
  96. }
  97.  
  98. void guardar()
  99. {
  100. Agenda info;
  101. FILE *fp;
  102.  
  103. fp=fopen("agenda.txt","w");
  104. if(fp==NULL)
  105. {
  106. printf("No se puede abrir el archivo\n");
  107. return;
  108. }
  109.  
  110. for(int i=0; i<total; i++)
  111. fwrite(&agenda[i], sizeof(Agenda), 1, fp);
  112.  
  113. fclose(fp);
  114. }
  115.  
  116.  
  117. int edad (struct date fecha)
  118. {
  119. struct date hoy;
  120. getdate(&hoy);
  121.  
  122. int anios = hoy.da_year - fecha.da_year;
  123.  
  124. if(hoy.da_mon < fecha.da_mon)
  125. anios--;
  126. else if(hoy.da_mon == fecha.da_mon && hoy.da_day < fecha.da_day)
  127. anios--;
  128.  
  129. return anios;
  130. }
  131. void ingresar()
  132. {
  133. int dia,mon,year;
  134. Agenda info;
  135. struct date fecha;
  136. gotoxy(30,29); printf(" NOMBRE: ");
  137. gotoxy(30,31); printf(" DIRECCION: ");
  138. gotoxy(30,33); printf(" TELEFONO: ");
  139.  
  140. gotoxy(25,35); printf("FECHA NACIMIENTO");
  141. gotoxy(30,37); printf(" DIA: ");
  142. gotoxy(30,39); printf(" MES: ");
  143. gotoxy(30,41); printf(" AñO: ");
  144.  
  145. gotoxy(43,29); fflush(stdin); gets(info.nombre);
  146. gotoxy(43,31);fflush(stdin); gets(info.direccion);
  147. gotoxy(43,33);fflush(stdin); gets(info.tel);
  148. gotoxy(43,37);//scanf("%d",&dia);
  149. dia=0;
  150. do{
  151.  
  152. scanf("%d",&dia);
  153. gotoxy(43,37);
  154. printf(" ");
  155. }while(dia<1 || dia >31);
  156.  
  157. gotoxy(43,39);scanf("%d",&mon);
  158. gotoxy(43,41);scanf("%d",&year);
  159.  
  160. fecha.da_day=dia;
  161. fecha.da_mon=mon;
  162. fecha.da_year=year;
  163.  
  164.  
  165. info.calculado=edad(fecha);
  166. insertar(info);
  167. guardar();
  168.  
  169. gotoxy(35,43);printf("Persona ingresada exitosamente");
  170. }
  171.  
  172.  
  173. void modificar()
  174. {
  175. char nombre[20];
  176. int i;
  177.  
  178. printf("Ingrese nombre a modificar: ");
  179. fflush(stdin);
  180. gets(nombre);
  181. clrscr();
  182. for(i=0; i<total; i++)
  183. if(!strcmp(agenda[i].nombre, nombre))
  184. {
  185. gotoxy(30,6); printf("--- Datos actuales ---\n");
  186. gotoxy(11,8); printf("NOMBRE");
  187. gotoxy(26,8); printf("DIRECCION");
  188. gotoxy(44,8); printf("TELEFONO");
  189.  
  190. gotoxy(11,10);printf("%s", agenda[i].nombre);
  191. gotoxy(25,10);printf("%s", agenda[i].direccion);
  192. gotoxy(45,10);printf("%s", agenda[i].tel);
  193.  
  194.  
  195.  
  196. gotoxy(30,16); printf("--- Nuevos datos ---\n");
  197. gotoxy(11,18);gets(agenda[i].nombre);
  198. gotoxy(25,18); gets(agenda[i].direccion);
  199. gotoxy(45,18);gets(agenda[i].tel);
  200. guardar();
  201. printf("\n\nDatos actualizados exitosamente!");
  202.  
  203. return;
  204. }
  205.  
  206. if(i==total)
  207. gotoxy(35,43); printf("Persona no encontrada");
  208. menu();
  209. }
  210.  
  211. void eliminar()
  212. {
  213. char nombre[20];
  214. int i;
  215.  
  216. printf("Ingrese nombre a eliminar: ");
  217. gets(nombre);
  218.  
  219. for(i=0; i<total; i++)
  220. if(!strcmp(agenda[i].nombre, nombre))
  221. {
  222. /* Recorre registros posteriores */
  223. for(int j=i+1; j<total; j++)
  224. {
  225. strcpy(agenda[j-1].nombre, agenda[j].nombre);
  226. strcpy(agenda[j-1].direccion, agenda[j].direccion);
  227. strcpy(agenda[j-1].tel, agenda[j].tel);
  228.  
  229. }
  230.  
  231. gotoxy(35,43); printf("Persona eliminada");
  232. total--;
  233. guardar();
  234. return;
  235. }
  236. if(i==total)
  237. gotoxy(35,43); printf("Persona no encontrada");
  238. }
  239.  
  240.  
  241. void mostrar()
  242. {
  243. clrscr();
  244. int y=10,i;
  245. gotoxy(11,8); printf("NOMBRE");
  246. gotoxy(26,8); printf("DIRECCION");
  247. gotoxy(44,8); printf("TELEFONO");
  248. gotoxy(60,8); printf("EDAD");
  249.  
  250. for(i=0; i<total; i++)
  251. {
  252.  
  253. gotoxy(11,y);printf("%s", agenda[i].nombre);
  254. gotoxy(25,y);printf("%s", agenda[i].direccion);
  255. gotoxy(45,y);printf("%s", agenda[i].tel);
  256. gotoxy(61,y);printf("%d", agenda[i].calculado);
  257.  
  258. y=y+2;
  259.  
  260. }
  261. }
  262.  
  263. char menu(void)
  264. {
  265. char c;
  266.  
  267.  
  268. gotoxy(17,2);printf(" ");
  269. gotoxy(17,3);printf(" ÛÛÛÛÛÛ ÛÛÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛÛÛ ");
  270. gotoxy(17,4);printf(" Û Û Û Û Û Û Û Û Û Û ");
  271. gotoxy(17,5);printf(" ÛÛÛÛÛÛ Û ÛÛÛ ÛÛÛÛ Û Û Û Û ÛÛÛÛÛÛ ");
  272. gotoxy(17,6);printf(" Û Û Û Û Û Û Û Û Û Û Û ");
  273. gotoxy(17,7);printf(" Û Û ÛÛÛÛÛÛ ÛÛÛÛÛ Û Û ÛÛÛÛÛ Û Û ");
  274. gotoxy(17,8);printf(" ");
  275.  
  276. gotoxy(34,17);printf("[1]Ingresar");
  277. gotoxy(34,19);printf("[2]Modificar");
  278. gotoxy(34,21);printf("[3]Eliminar");
  279. gotoxy(34,23);printf("[4]Mostrar lista");
  280. gotoxy(34,25);printf("[5]Salir");
  281. gotoxy(55,27);printf("[ ]");
  282. gotoxy(56,27);
  283.  
  284.  
  285. c=getche();
  286. printf("\n");
  287. return(c);
  288. }
  289.  
  290.  
  291. void presentacion()
  292. {
  293.  
  294.  
  295.  
  296. gotoxy(17,2);printf(" ");
  297. gotoxy(17,3);printf(" ÛÛÛÛÛÛ ÛÛÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛÛÛ ÛÛÛÛÛ ÛÛÛÛÛÛ ");
  298. gotoxy(17,4);printf(" Û Û Û Û Û Û Û Û Û Û ");
  299. gotoxy(17,5);printf(" ÛÛÛÛÛÛ Û ÛÛÛ ÛÛÛÛ Û Û Û Û ÛÛÛÛÛÛ ");
  300. gotoxy(17,6);printf(" Û Û Û Û Û Û Û Û Û Û Û ");
  301. gotoxy(17,7);printf(" Û Û ÛÛÛÛÛÛ ÛÛÛÛÛ Û Û ÛÛÛÛÛ Û Û ");
  302. gotoxy(17,8);printf(" ");
  303.  
  304. gotoxy(22,13);printf("INGENIERIA EN SISTEMAS COMPUTACIONALES ");
  305. gotoxy(22,15);printf(" ESTRUCTURA DE DATOS ");
  306. gotoxy(22,17);printf(" AGENDA PERSONAL ");
  307. gotoxy(20,22);printf("LA SIGUIENTE AGENDA ESTA HECHA EN LENGUAJE");
  308. gotoxy(22,24);printf(" EN LENGUAJE C++ ");
  309. gotoxy(5,29);printf("EN EL SIGUIENTE PROGRAMA SE UTILIZAN FUNCIONES , ESTRUCTURAS Y ARCHIVOS ");
  310. gotoxy(11,31);printf(" EL PROGRAMA CAPTURA NOMBRE , DIRECCCION , TELEFONO Y EDAD");
  311. gotoxy(11,33);printf(" CAPTURA LOS DATOS DE LA EDAD Y LISTA LA EDAD YA CALCULADA");
  312.  
  313. getch();
  314.  
  315. }
Add Comment
Please, Sign In to add comment