• Jueves 25 de Abril de 2024, 06:30

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - checlops

Páginas: [1]
1
C++ Builder / Agenda... En C++, Funcion Para Guardar Txt
« en: Jueves 29 de Mayo de 2008, 08:47 »
Tengo un problema, estoy haciendo una agenda por mas que intento que crear archivos de tipo . dat o txt no puedo tengo varias versiones sin embargo aparecen errores, como "expected" y no ninguna especificacion... ojala me puedan a ayudar, necesito que la agenda tu introduscas los datos y te cree un archivo txt espero su ayuda les dejo el codigo :P
Código: Text
  1.  
  2. #include <iostream.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <conio.h>
  8. #include <dos.h>
  9.  
  10.  
  11.  
  12. void menu(void);
  13.  
  14. void agregar(void);
  15. void cambiar(void);
  16. void mostrar(void);
  17. void borrar(void);
  18.  
  19.  
  20. class persona {
  21. public:
  22. persona();
  23. void modificar(void);
  24. void listar(void);
  25. private:
  26. char nombre[32];
  27. char appaterno[50];
  28. char apmaterno[50];
  29. char domicilio[30];
  30. char telefono[15];
  31. int id;
  32. };
  33.  
  34.  
  35. persona *p[10];
  36.  
  37. int total&#59;
  38. char opta;
  39.  
  40.  
  41.  
  42. persona::persona() {
  43. cout << "Nombre :\n "&#59; cin.getline(nombre, sizeof(nombre))&#59;
  44. cout << "Apellido Paterno :\n "&#59; cin.getline(appaterno, sizeof(appaterno))&#59;
  45. cout << "Apellido Materno :\n "&#59; cin.getline(apmaterno, sizeof(apmaterno))&#59;
  46. cout << "Domicilio :\n "; cin.getline(domicilio,
  47. sizeof(domicilio))&#59;
  48. cout << "Telefono :\n "; cin.getline(telefono,
  49. sizeof(telefono));
  50. cout << "ID :\n\n "; cin >> id; cin.get();
  51. {
  52. cout << "GUARDANDO DATOS...\n\n" << endl;
  53. getch();
  54. cout << "LOS DATOS YA FUERON GUARDADOS..." << endl;
  55. getch();
  56.  
  57. }
  58. cout << "-----------------------------------\n" << endl;
  59. };
  60.  
  61.  
  62. void persona::modificar(void)
  63. { char opcion;
  64. cout<< "Deseas modificar el domicilio (S/N) : "&#59;
  65. do { opcion = cin.get();
  66. opcion = toupper(opcion);
  67. } while ((opcion !='S') && (opcion !='N'))&#59;
  68. if (opcion == 'S') { cout << "Domicilio :\n\n"&#59;
  69. {
  70. cout << "BUSCANDO DATO..." << endl;
  71. getch();
  72. } cin.get();
  73. cin.getline(domicilio,sizeof(domicilio));}
  74. cout<< "Deseas modificar el telefono (S/N) : "&#59;
  75. do { cin.get(opcion);
  76. opcion = toupper(opcion);
  77. } while ((opcion !='S') && (opcion !='N'))&#59;
  78. if (opcion == 'S')
  79. {
  80. cout << "BUSCANDO DATO..." << endl;
  81. getch();
  82. }
  83.  { cout << "Telefono :\n "; cin.get();
  84. cin.getline(telefono, sizeof(telefono));}
  85. }
  86.                                                              void persona::listar(void)
  87. {
  88. cout << "**************************\n\n" << endl;
  89. cout << "Nombre : " << nombre << endl;
  90. cout << "Domicilio : " << domicilio << endl;
  91. cout << "Telefono : " << telefono << endl;
  92. cout << "ID : " << id << endl;
  93. };
  94.  
  95. void menu()
  96. {
  97. textcolor(7);
  98. clrscr();
  99. gotoxy(38,10); textcolor(7); cprintf("AGENDA!!!");
  100. gotoxy(34,11); textcolor(1); cprintf("1.- Agregar Contacto");
  101. gotoxy(34,12); textcolor(1); cprintf("2.- Modificar Contacto");
  102. gotoxy(34,13); textcolor(1); cprintf("3.- Borrar Contacto");
  103. gotoxy(34,14); textcolor(1); cprintf("4.- Mostrar el contenido");
  104. gotoxy(34,15); textcolor(1); cprintf("5.- SALIR");
  105. gotoxy(36,16); textcolor(4); cprintf("Opcion >>> ");
  106. do
  107. opta=getch();
  108. while ((opta < '1') || (opta > '5'));
  109. switch (opta) {
  110. case '1': agregar()&#59;break;
  111. case '2': cambiar();break;
  112. case '3': borrar();break;
  113. case '4': mostrar();break;
  114. case '5': exit (1);break;
  115. }
  116. }
  117.  
  118.                                                        void agregar(void)
  119. { if (total==10) { gotoxy(20,23);
  120. cout << "No hay espacio disponible" << endl;
  121. delay(1000);}
  122. else { clrscr();
  123. p[total] = new persona;
  124. total++;
  125. }
  126. }
  127.  
  128.    void cambiar(void)
  129.  
  130.  
  131. { int cual; char opcion;
  132. if (total==0) { gotoxy(2,23);
  133. cout << "No existen registros" << endl;
  134. delay(2000);}
  135. else { clrscr();
  136. cout << "Existen"<< total << " Registros, Cual deseas modificar ???\n ";
  137. cin >> cual; cin.get();
  138. p[cual-1]->listar();
  139. cout<< "\nDeseas cambiar el registro (S/N)?:\n"&#59;
  140. do { opcion = cin.get(); cin.get();
  141. opcion = toupper(opcion);
  142. }while ((opcion !='S') && (opcion !='N'))&#59;
  143. if (opcion == 'S')
  144. {
  145. cout << "EN PROCESO...\n\n" << endl;
  146. getch();
  147. }
  148. p[cual-1]->modificar();
  149. }
  150. }
  151.  
  152.  
  153.          void borrar(void)
  154.  
  155. {
  156.    int cual;
  157.  
  158. if (total==0) { gotoxy(2,23);
  159. cout << "No existen registros" << endl;
  160. delay(2000);
  161. }
  162. else { clrscr();
  163. cout << "Existen"<< total << " Registros, Cual quiere borrar??? \n";
  164. cin >> cual; cin.get();
  165. delete p[cual-1];
  166. p[cual-1] = p[total-1];
  167. total--;
  168. }
  169. cout << "BORRANDO...\n\n\n" << endl;
  170. getch();
  171. cout << "Operacion EXITOSA" << endl;
  172. getch();
  173. }
  174.  
  175.                                                                                                                                        // manda llamar el metodo listar
  176.       void mostrar(void)
  177.  
  178. {
  179. int cual; int j;
  180. if (total==0) { gotoxy(2,23);
  181. cout << "No existen registros" << endl;
  182. delay(2000);}
  183. else {
  184. clrscr();
  185. cout << "Existen"<< total << " Registros, Cual  se desea ver??? \n";
  186. cin >> cual; cin.get();
  187. {
  188. cout << "BUSCANDO DATOS DEL CONTACTO...\n\n" << endl;
  189. getch();
  190. }
  191. {
  192. cout << "PROCESO EXISTOSO...\n\n" << endl;
  193. getch();
  194. }
  195. if(cual <=total) {    p[cual-1]->listar();
  196. delay(2000);
  197. }
  198. else { for(j=0; j<total;j++) p[j]->listar();
  199. delay(3000);
  200. }
  201. getch();
  202. }
  203. }
  204.  
  205. void main(void)
  206. { clrscr();
  207. total = 0;
  208. do
  209. menu();
  210. while(opta != '6');
  211. };
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
ojala puedan ayudarme de antemano gracias

Páginas: [1]