<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hola, me llamo Alejandro y soy español.</DIV>
<DIV>Tengo 13 años y me gusta la informática. Antes había hecho páginas web con HTML pero ahora me he metido a la programación</DIV>
<DIV>Me gustaría saber si se pueden guardar los datos que introduzcas en un programa y que al cerrar el programa no los pierdas. Os pregunto esto para el problema 1 de la parte de estructuras en el que hay que crear una agenda telefónica y para el que yo he usado este código:</DIV>
<DIV> </DIV>
<DIV><FONT color=#008000 size=2>
<P>//Escribir un programa que almacene en un array los nombres y números de teléfono de 10 personas.</P>
<P>//El programa debe leer los datos introducidos por el usuario y guardarlos en memoria. </P>
<P>//Después debe ser capaz de buscar el nombre correspondiente a un número de teléfono y el teléfono </P>
<P>//correspondiente a una persona. Ambas opciones deben se accesibles a través de un menú, así como la </P>
<P>//opción de salir del programa. El menú debe tener esta forma, más o menos: </P>
<P>//a) Buscar por nombre</P>
<P>//b) Buscar por número de teléfono</P>
<P>//c) Salir</P>
<P>//Pulsa una opción:</P>
<P>//4/1/2007 Alejandro Vilar López</P></FONT><FONT color=#0000ff size=2>
<P>#include</FONT><FONT color=#800000 size=2><iostream></FONT><FONT color=#008000 size=2>//Librería para usar cout</P></FONT><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>namespace</FONT><FONT size=2> std;</P></FONT><FONT color=#0000ff size=2>
<P>struct</FONT><FONT size=2> Datos</FONT><FONT color=#008000 size=2>//Estructura donde guardaré los datos</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> nombre[15];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde guardaré el nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> telefono;</FONT><FONT color=#008000 size=2>//Variable entera para guardar el teléfono</P></FONT><FONT size=2>
<P>}Persona[100];</FONT><FONT color=#008000 size=2>//Array donde se guerdan las personas</P></FONT><FONT color=#0000ff size=2>
<P>int</FONT><FONT size=2> main()</FONT><FONT color=#008000 size=2>//Función principal</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> opcion[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde guardaré la respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> respuesta1[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> respuesta2[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> respuesta3[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> cnombre[15];</FONT><FONT color=#008000 size=2>//Variable para comprobar el nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> ctelefono;</FONT><FONT color=#008000 size=2>//Variable par comprobar el teléfono</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> k;</FONT><FONT color=#008000 size=2>//Variable entera que usaré de contador en los bucles</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> n;</FONT><FONT color=#008000 size=2>//Variable que usaré como contador en los bucles</P></FONT><FONT size=2>
<P></P>
<P>Start:</FONT><FONT color=#008000 size=2>//Etiqueta para goto</P></FONT><FONT size=2>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Que deseas hacer? (a/b/c/d)"</FONT><FONT size=2> << endl << </FONT><FONT color=#800000 size=2>"a) Introducir datos"</FONT><FONT size=2> << endl</P>
<P><<</FONT><FONT color=#800000 size=2>"b) Buscar por nombre"</FONT><FONT size=2> << endl << </FONT><FONT color=#800000 size=2>"c) Buscar por telefono"</FONT><FONT size=2> << endl << </FONT><FONT color=#800000 size=2>"d) Salir"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> opcion;</FONT><FONT color=#008000 size=2>//Te deja responder</P></FONT><FONT size=2>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] == </FONT><FONT color=#800000 size=2>'a'</FONT><FONT size=2> || opcion[0] == </FONT><FONT color=#800000 size=2>'A'</FONT><FONT size=2>)</FONT><FONT color=#008000 size=2>//Si respondes a</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <= 99; k ++)</FONT><FONT color=#008000 size=2>//Bucle for para meter el nombra</P></FONT><FONT size=2>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el nombre (maximo 15 letras y sin"</FONT><FONT size=2> </P>
<P></FONT><FONT color=#800000 size=2>" espacios): "</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> Persona[k].nombre;</FONT><FONT color=#008000 size=2>//Te deja meter el nombre</P></FONT><FONT size=2>
<P>cout << </FONT><FONT color=#800000 size=2>"Introduce el telefono: "</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> Persona[k].telefono;</FONT><FONT color=#008000 size=2>//Te deja meter el teléfono</P></FONT><FONT size=2>
<P>cout << </FONT><FONT color=#800000 size=2>"Introducir mas personas? (s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta1;</FONT><FONT color=#008000 size=2>//Te deja contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta1[0] == </FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta1[0] == </FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000 size=2>//Si se cumple, hace esto</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] == </FONT><FONT color=#800000 size=2>'b'</FONT><FONT size=2> || opcion[0] == </FONT><FONT color=#800000 size=2>'B'</FONT><FONT size=2>)</FONT><FONT color=#008000 size=2>//Si respondes b hace lo siguiente</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(n = 0; n <= 99; n ++)</P>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el nombre a buscar:"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> cnombre;</FONT><FONT color=#008000 size=2>//Te deja meter el nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <=99; k ++)</FONT><FONT color=#008000 size=2>//Bucle para buscar el telefono</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(cnombre[0] == Persona[k].nombre[0] </P>
<P>&& cnombre[1] == Persona[k].nombre[1])</FONT><FONT color=#008000 size=2>//Si se cumple, hace esto</P></FONT><FONT size=2>
<P>{</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Telefono de "</FONT><FONT size=2> << Persona[k].nombre << </FONT><FONT color=#800000 size=2>": "</FONT><FONT size=2> </P>
<P><< Persona[k].telefono << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Buscar otro telefono? (s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta2;</FONT><FONT color=#008000 size=2>//Te deja contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta2[0] == </FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta2[0] == </FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000 size=2>//Si se cumple, vuelves a empezar</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] == </FONT><FONT color=#800000 size=2>'c'</FONT><FONT size=2> || opcion[0] == </FONT><FONT color=#800000 size=2>'C'</FONT><FONT size=2>)</FONT><FONT color=#008000 size=2>//Si respondes c</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(n = 0; n <= 99; n ++)</P>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el telefono:"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> ctelefono;</FONT><FONT color=#008000 size=2>//Te deja meter el nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <=99; k ++)</FONT><FONT color=#008000 size=2>//Bucle para buscar el telefono</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(ctelefono == Persona[k].telefono)</FONT><FONT color=#008000 size=2>//Si se cumple, hace esto</P></FONT><FONT size=2>
<P>{</P>
<P>cout << </FONT><FONT color=#800000 size=2>"El telefono es de"</FONT><FONT size=2> << </FONT><FONT color=#800000 size=2>": "</FONT><FONT size=2> </P>
<P><< Persona[k].nombre << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>break</FONT><FONT size=2>;</FONT><FONT color=#008000 size=2>//Corta el bucle</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Buscar otro? (s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta3;</FONT><FONT color=#008000 size=2>//Te deja contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta3[0] == </FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta3[0] == </FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000 size=2>//Si se cumple, vuelves a empezar</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P>cin.get();</FONT><FONT color=#008000 size=2>//Mantiene abierto el programa</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> 0;</P>
<P>}</P></FONT></DIV>
<DIV> </DIV>
<DIV>Gracias por adelantado y un saludo.</DIV></div><br>
                <hr size=1><br><font face="Verdana" size="-2">LLama Gratis a cualquier PC del Mundo.<br>Llamadas a fijos y móviles desde 1 céntimo por minuto.<br><a href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/">http://es.voice.yahoo.com</a></font></body></html>