elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Problema con reloj en: 19 Marzo 2017, 20:25 pm
Código
  1. #include <iostream>
  2. #include <thread>
  3. #include <chrono>
  4.  
  5. #ifdef _WIN32
  6. #define CLEAR "cls"
  7. #else
  8. #define CLEAR "clear"
  9. #endif
  10.  
  11. using namespace std;
  12. using namespace this_thread;
  13. using namespace chrono;
  14.  
  15. void verTiempoActual ();
  16.  
  17. int main () {
  18.        verTiempoActual();
  19.  
  20.        return 0;
  21. }
  22.  
  23. void verTiempoActual () {
  24. char Decision;
  25. system (CLEAR);
  26. cout << "VER EL TIEMPO Y LA FECHA ACTUALES" << endl;
  27. cout << "--- -- ------ - -- ----- --------" << endl;
  28. system_clock::time_point Actual = system_clock::now();
  29. time_t mostrarTiempo;
  30. mostrarTiempo = system_clock::to_time_t (Actual);
  31. cout << "Ahora estamos en: " << ctime(&mostrarTiempo) << endl;
  32. cout << "\nPonga 'B' para ir al menu o 'E' para salir: ";
  33. sleep_for (seconds(1));
  34. verTiempoActual();
  35. cin >> Decision;
  36. if (Decision == 'B' or Decision == 'b') {
  37. main();
  38. }else if (Decision == 'E' or Decision == 'e') {
  39. Salir();
  40. }else{
  41. cout << "Ponga una opcion valida" << endl;
  42. }
  43. }

Hola, en esta parte del codigo, no se como hacer para poder introducir una b o una e mientras el codigo sigue su curso, es decir, mientras el codigo va añadiendo un segundo a la hora, poder introducirle una orden, Gracias
2  Programación / Programación C/C++ / Como generar dos valores en RAND en: 25 Febrero 2017, 21:14 pm
Hola me gustaría hacer un generador de contraseñas aleatorias, pero no encuentro la manera de poder hacer mayusculas y numeros en una contraseña, ya que necesito la funcion (48+ rand () % 9) i otra (65+ rand()%25). Les agradeceria que me respondiean. Gracias.
3  Programación / Programación C/C++ / Crear contraseña aleatoria en: 23 Diciembre 2016, 20:08 pm
Hola, me gustaría crear un programa que generara contraseñas aleatorias de la longitud seleccionada (entre los caracteres 33 y 125 de la tabla ASCII), el código es el siguiente, pero cuando lo ejecuto, me imprime otros caracteres que no están entre los dos dichos anteriormente, grácias

Código
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. int main () {
  7. int cantidad;
  8. char contrasenya;
  9. cout << "Longitud de la contrasenya: ";
  10. cin >> cantidad;
  11. for (int contador =1 ; contador <= cantidad ; contador++) {
  12. contrasenya = (33+rand() % 125);
  13. cout << contrasenya;
  14.    }
  15. return 0 ;
  16. }
4  Programación / Programación C/C++ / Problema organizando libros en: 31 Octubre 2016, 09:57 am
Buenos dias, me ha surgido un problema creando una base de datos para libro, cuando ejecuto el vois MostrarTodos (en el dash me escribe 3 palabras y crea una nueva linea, mientras que yo quiero que me imprima una linea por libro) el código es este:

Código
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstdio>
  5. #include <stdio.h>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. void entrada ();
  11. void buscarTitulo ();
  12. void buscarAutor ();
  13. void buscarEditorial ();
  14. void buscarTomo ();
  15. void buscarColeccion ();
  16. void salir ();
  17. void mostrarTodos ();
  18. void buscar ();
  19. void borrarLibro ();
  20. void editarLibro ();
  21.  
  22. int main () {
  23. system ("title Libros");
  24. system ("cls");
  25. system ("color 0F");
  26. int eleccion;
  27. cout << "1.Introducir un nuevo libro" << endl;
  28. cout << "2.Buscar un libro" << endl;
  29. cout << "3.Limpiar base de datos" << endl;
  30. cout << "4.Editar un libro" << endl;
  31. cout << "5.Salir" << endl;
  32. cin >> eleccion;
  33. switch (eleccion) {
  34. case 1:
  35. entrada();
  36. break;
  37. case 2:
  38. buscar();
  39. break;
  40. case 3:
  41. borrarLibro();
  42. break;
  43. case 4:
  44. editarLibro();
  45. break;
  46. case 5:
  47. salir();
  48. break;
  49.  
  50. cin.get();
  51. }
  52. }
  53.  
  54. void editarLibro () {
  55. char titulo [100];
  56. char nuevoTitulo [100];
  57. char autor [100];
  58. char nuevoAutor [100];
  59. char editorial [50];
  60. char nuevoEditorial [50];
  61. char coleccion [200];
  62. char nuevaColeccion [200];
  63. int tomo;
  64. int nuevoTomo;
  65. string entrada;
  66. char decision;
  67. ifstream RegistroLibros("Nuevo libro.txt");
  68. if (!RegistroLibros.eof()) {
  69. RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo;
  70. }
  71. system ("cls");
  72.  
  73. cout << "Introduzca el titulo del libro: ";
  74. cin >> entrada;
  75.  
  76. if (entrada == titulo) {
  77. cout << titulo << ' ' << autor << ' ' << editorial << endl;
  78. cout << "Es este el libro correcto S/N:";
  79. cin >> decision;
  80. if (decision == 'S' or decision == 's') {
  81. cout << "Introduzca el nuevo titulo: ";
  82. cin >> nuevoTitulo;
  83. nuevoTitulo == titulo;
  84. cout << "\nIntroduzca el nuevo autor: ";
  85. cin >> nuevoAutor;
  86. autor == nuevoAutor;
  87. cout << "\nIntroduzca el nuevo editorial: ";
  88. cin >> nuevoEditorial;
  89. editorial == nuevoEditorial;
  90. cout << "\nIntroduzca la nueva coleccion: ";
  91. cin >> coleccion;
  92. coleccion == nuevaColeccion;
  93. cout << "\nIntroduzca el nuevo tomo: ";
  94. cin >> tomo;
  95. tomo == nuevoTomo;
  96. }
  97. RegistroLibros.close();
  98. }
  99. ofstream RegistroLibros2 ("NuevoLibro.txt", ios::app);
  100. RegistroLibros2 << titulo << ' ' << autor << ' ' << editorial << ' ' << coleccion << ' ' << tomo << endl;
  101. RegistroLibros2.close();
  102. system ("pause");
  103. main ();
  104. }
  105.  
  106. void entrada () {
  107. char titulo[100];
  108. char autor[100];
  109. char editorial[50];
  110. char coleccion [200];
  111. int tomo;
  112. char decision;
  113.  
  114. ofstream NuevoLibro ("Nuevo Libro.txt", ios::app);
  115. system ("cls");
  116. cin.sync();
  117. cout << "Introduzca el titulo del libro" << endl;
  118. gets (titulo);
  119. system ("cls");
  120. cout << "Introduzca el autor del libro" << endl;
  121. gets (autor);
  122. system ("cls");
  123. cout << "Introduzca la editorial del libro" << endl;
  124. gets (editorial);
  125. system ("cls");
  126.  
  127. cout << "Tiene coleccion S/N: ";
  128. cin >> decision;
  129. if (decision == 'S' or decision == 's'){
  130. cout << "Introduzca el nombre de la coleccion" << endl;
  131. gets (coleccion);
  132. system ("cls");
  133. cout << "Introsuzca el tomo de la coleccion" << endl;
  134. cin >> tomo;
  135.  
  136. NuevoLibro << titulo << ' ' << autor << ' ' << editorial << ' ' << coleccion << ' ' << tomo << endl;
  137. NuevoLibro.close();
  138. main ();
  139. }else{
  140. NuevoLibro << titulo << ' ' << autor << ' ' << editorial << endl;
  141. NuevoLibro.close();
  142. main ();
  143. }
  144.  
  145.  
  146. }
  147.  
  148. void buscarTitulo () {
  149. ifstream RegistroLibros ("Nuevo Libro.txt");
  150. char titulo [100];
  151. char autor [100];
  152. char editorial [50];
  153. char coleccion [200];
  154. int tomo;
  155. char btitulo [100];
  156. system("CLS");
  157. cout << "Introduzca el titulo del libro: ";
  158. gets (btitulo);
  159.  
  160. while (RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo) {
  161. if (btitulo == titulo) {
  162. system ("CLS");
  163. cout << "Libro(s) encontrado" << endl;
  164. cout << "------------------------------\n";
  165. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << endl;;
  166. }
  167. }
  168.  
  169. while (RegistroLibros >> titulo) {
  170. if (btitulo != titulo) {
  171. system ("CLS");
  172. cout << "No hay libros con ese nombre" << endl;
  173. }
  174. }
  175.  
  176. system ("pause");
  177. main ();
  178. }
  179.  
  180. void buscarAutor() {
  181. ifstream RegistroLibros ("Nuevo Libro.txt");
  182. char titulo [100];
  183. char autor [100];
  184. char editorial [50];
  185. char coleccion [200];
  186. int tomo;
  187. char bautor [100];
  188. system ("CLS");
  189. cout << "Introduzca el autor del libro: ";
  190. gets (bautor);
  191.  
  192. while (RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo) {
  193. if (bautor == autor) {
  194. system ("CLS");
  195. cout << "Libro(s) encontrado" << endl;
  196. cout << "------------------------------\n";
  197. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << endl;
  198. }
  199. }
  200.  
  201. while (RegistroLibros >> autor) {
  202. if (bautor != autor) {
  203. system ("CLS");
  204. cout << "No hay libros de ese autor" << endl;
  205. }
  206. }
  207.  
  208. system ("pause");
  209. cin.get();
  210. main ();
  211. }
  212.  
  213. void buscarEditorial() {
  214. ifstream RegistroLibros ("Nuevo Libro.txt");
  215. char titulo [100];
  216. char autor [100];
  217. char editorial [50];
  218. char coleccion [200];
  219. int tomo;
  220. char beditorial [50];
  221. system ("CLS");
  222. cout << "Introduzca un editorial: ";
  223. gets (beditorial);
  224.  
  225. while (RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo) {
  226. if (beditorial == editorial) {
  227. system ("cls");
  228. cout << "Libro(s) encontrado" << endl;
  229. cout << "------------------------------\n";
  230. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << " " << endl;
  231. }
  232. }
  233.  
  234. while (RegistroLibros >> editorial) {
  235. if (beditorial != editorial) {
  236. system ("CLS");
  237. cout << "No hay libros de esa editorial" << endl;
  238. }
  239. }
  240.  
  241. system ("pause");
  242. cin.get();
  243. main ();
  244. }
  245.  
  246. void buscarColeccion () {
  247. ifstream RegistroLibros ("Nuevo Libro.txt");
  248. char titulo [100];
  249. char autor [100];
  250. char editorial [50];
  251. char coleccion [200];
  252. int tomo;
  253. char bcoleccion [200];
  254. system ("CLS");
  255. cout << "Introduzca una coleccion: ";
  256. gets (bcoleccion);
  257.  
  258. while (RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo) {
  259. if (bcoleccion == coleccion) {
  260. system ("cls");
  261. cout << "Libro(s) encontrado" << endl;
  262. cout << "------------------------------\n";
  263. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << " " << endl;
  264. }
  265. }
  266. while (RegistroLibros >> coleccion) {
  267. if (bcoleccion != coleccion) {
  268. system ("CLS");
  269. cout << "No hay libros de esa coleccion" << endl;
  270. }
  271. }
  272.  
  273. system ("pause");
  274. cin.get();
  275. main ();
  276. }
  277.  
  278. void buscarTomo () {
  279. ifstream RegistroLibros ("Nuevo Libro.txt");
  280. char titulo [100];
  281. char autor [100];
  282. char editorial [50];
  283. char coleccion [200];
  284. int tomo;
  285. int btomo;
  286. system ("CLS");
  287. cout << "Introduzca un tomo: ";
  288. cin >> btomo;
  289.  
  290. while (RegistroLibros >> titulo >> autor >> editorial >> coleccion >> tomo) {
  291. if (btomo == tomo) {
  292. system ("cls");
  293. cout << "Libro(s) encontrado" << endl;
  294. cout << "------------------------------\n";
  295. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << " " << endl;
  296. }
  297. }
  298. while (RegistroLibros >> tomo) {
  299. if (btomo != tomo) {
  300. system ("CLS");
  301. cout << "No hay libros con ese numero de tomo" << endl;
  302. }
  303. }
  304.  
  305. system ("pause");
  306. cin.get();
  307. main ();
  308. }
  309.  
  310. void salir () {
  311. system ("CLS");
  312. cout << ("Gracias por usar esta base de datos");
  313. system ("pause");
  314. cin.get();
  315. }
  316.  
  317. void mostrarTodos() {
  318. ifstream RegistroLibro ("Nuevo Libro.txt");
  319. char titulo [100];
  320. char autor [100];
  321. char editorial [50];
  322. char coleccion [200];
  323. int tomo;
  324. system ("cls");
  325. cout << "Todos los libros\n";
  326. cout << "-------------------------------------\n";
  327.  
  328. while (RegistroLibro >> titulo >> autor >> editorial) {
  329. system ("cls");
  330. cout << titulo << " " << autor << " " << editorial << " " << coleccion << " " << tomo << endl;
  331. }
  332.  
  333. system ("pause");
  334. cin.get();
  335. main ();
  336. }
  337.  
  338. void buscar () {
  339. char titulo [100];
  340. char autor [100];
  341. char editorial [50];
  342. char coleccion [200];
  343. int tomo;
  344. int eleccion2;
  345. system ("CLS");
  346.  
  347. cout << "1.Buscar por titulo" << endl;
  348. cout << "2.Buscar por autor" << endl;
  349. cout << "3.Buscar por editorial" << endl;
  350. cout << "4.Buscar por coleccion" << endl;
  351. cout << "5.Buscar por tomo" << endl;
  352. cout << "6.Todos los libros" << endl;
  353. cout << "7.Atras" << endl;
  354. cout << "8.Salir" << endl;
  355. cin >> eleccion2;
  356.  
  357. switch (eleccion2) {
  358. case 1:
  359. buscarTitulo ();
  360. break;
  361. case 2:
  362. buscarAutor ();
  363. break;
  364. case 3:
  365. buscarEditorial ();
  366. break;
  367. case 4:
  368. buscarColeccion ();
  369. break;
  370. case 5:
  371. buscarTomo ();
  372. break;
  373. case 6:
  374. mostrarTodos ();
  375. break;
  376. case 7:
  377. main ();
  378. break;
  379. case 8:
  380. salir ();
  381. break;
  382. }
  383. }
  384.  
  385. void borrarLibro () {
  386. char decision;
  387. cout << "Estas seguro? S/N" << endl;
  388. cin >> decision;
  389. if (decision == 'S' or decision == 's') {
  390. ofstream RegistroLibros ("Nuevo Libro.txt");
  391. system ("cls");
  392. cout << "Accion realizada con exito" << endl;
  393. system ("pause");
  394. RegistroLibros.close();
  395. main ();
  396. }else{
  397. main ();
  398. }
  399. }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines