Advertisement
Guest User

axa

a guest
Oct 14th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.37 KB | None | 0 0
  1. #include <iostream>//Biblioteca estándar de entrada y salida, para utilizar cout y cin
  2. #include <stdio.h>
  3. #include <stdlib.h>/*Biblioteca para utilizar system("cls") limpieza de pantalla y system("pause") que detiene la ejecución del programa hasta que el usuario digite una tecla */
  4. #include <conio.h> //
  5. #include <windows.h>// para utilizar la funcion sleep y copy
  6. #include <string.h>// libreria para utilizar la funcion que compara dos cademas
  7. #include <time.h>
  8. using namespace std;
  9.  
  10.  
  11. #define MAX_PRODUCTOS 100
  12.  
  13. int PROD_DEF = 5; // YA DEFINIDOS EN CODIGO
  14.  
  15.  
  16. char productos[MAX_PRODUCTOS][30] =
  17. {
  18. "Soda",  // 0
  19. "Hamburguesa", // 1
  20. "Papas Fritas", // 2
  21. "Doritos", // 3
  22. "Palomitas"  // 4
  23. };
  24.  
  25. int precios[MAX_PRODUCTOS] = {
  26. 1, // soda
  27. 3, // hamburguesa
  28. 2, // papas fritas
  29. 3, //doritos
  30. 5 //palomitas
  31. };
  32.  
  33. char fechas[MAX_PRODUCTOS][30] = {
  34. "Mon Oct 14 07:53:05 2019",
  35. "Mon Oct 14 07:53:05 2019",
  36. "Mon Oct 14 07:53:05 2019",
  37. "Mon Oct 14 07:53:05 2019",
  38. "Mon Oct 14 07:53:05 2019"
  39. };
  40.  
  41. int registrar_producto(char *prod_name, int prod_precio);
  42. void mostrar_productos();
  43. int modificar_producto(int prod_id, char *prod_name, int prod_precio);
  44.  
  45. main()
  46. {
  47.  
  48.  
  49.     int opc;//Declaración de variable de tipo entero
  50.  
  51.     do{ system("cls");
  52.           char *name = (char *)malloc(sizeof(char)*30);
  53.   int price = 0;
  54.   int id_mod = 0;
  55.         cout<<"\tEMPRESA ALMAFIN S.A"<<endl;
  56.         cout<<"\t ALMACEN"<<endl<<endl;
  57.         cout<<"MENU DE OPCIONES"<<endl<<endl;
  58.         cout<<" 1. Registrar articulos. "<<endl;
  59.         cout<<" 2. Ver lista de articulos. "<<endl;
  60.         cout<<" 3. Modificar articulos. "<<endl;
  61.         cout<<" 4. Salir. "<<endl;
  62.         cout<<endl<<endl<<" Por favor elija una de las opciones: "<<endl<<endl;
  63.         cin>>opc;
  64.     switch(opc)
  65. {
  66.     case 1: system("cls");
  67.         cout<<endl<<"1. Registrar articulo " <<endl;
  68.    
  69. cout << "ingresa el nombre del producto nuevo: ";
  70.  cin >> name;
  71. cout << "ingresa el precio del nuevo producto: ";
  72. cin >> price;
  73. registrar_producto(name, price);
  74. cout << "ID:" << PROD_DEF-1 << "- Nombre: " << productos[PROD_DEF-1] << " - precio: " << precios[PROD_DEF-1] << " - Fecha de registro: " << fechas[PROD_DEF-1]<< endl;
  75. opc = 0;
  76.         system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
  77.         break;
  78.    
  79.     case 2: system("cls");
  80.         cout<<endl<<"2. Ver lista de articulos. "<<endl;
  81.         mostrar_productos();
  82.         opc = 0;
  83.         system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
  84.         break;
  85.    
  86.         case 3: system("cls");
  87.         cout<<endl<<" 3. modificar articulos . "<<endl;
  88.         cout << "ingresa el ID del producto a modificar: ";
  89.         cin >> id_mod;
  90. cout << "ingresa el nuevo nombre del producto: ";
  91.  cin >> name;
  92. cout << "ingresa el nuevo precio del producto: ";
  93. cin >> price;
  94. modificar_producto(id_mod, name, price);
  95.         opc = 0;
  96.         system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
  97.         break;
  98.        
  99.         default:
  100.         break;
  101. }
  102. }
  103.     while(opc!=4);
  104.  
  105.   system("pause");
  106. return 0;
  107. }
  108.  
  109. void mostrar_productos(){
  110. for(int i = 0; i != PROD_DEF; i++){
  111. cout << "ID: " <<i<<" - Nombre: " <<productos[i]<< " - Precio:"<< precios[i] << " Fecha de registro:" << fechas[i] <<endl;
  112. }
  113. }
  114.  
  115. int modificar_producto(int prod_id, char *prod_name, int prod_precio){
  116. time_t   t,i;
  117. char *prod_time;
  118. i = time (&t);
  119. prod_time = ctime (&i);
  120. for(int i = 0; i != PROD_DEF-1; i++){
  121. if(strcmp(prod_name, productos[i]) == 0){
  122. cout <<"Ya existe el producto " << prod_name <<". (ID:" << i <<")" << endl;
  123. return 1; // FALLA CREACION
  124. }
  125. }
  126. for(int i = 0; i != 30; i++) productos[prod_id][i] = 0x00; // LLENAR DE VACIOS LA VARIABLE PRODUCTOS[PROD_REF] (PROD_REF ES EL ID DE PRODUCTO)
  127. for(int i = 0; i != 30; i++) fechas[prod_id][i] = 0x00; // LLENAR DE VACIOS LA VARIABLE FECHAS
  128.  
  129. sprintf(productos[prod_id], "%s", prod_name);
  130. precios[prod_id] = prod_precio;
  131. sprintf(fechas[prod_id], "%s", prod_time);
  132. return 0; // CREACION EXITOSA
  133. }
  134.  
  135.  
  136. int registrar_producto(char *prod_name, int prod_precio){
  137.         time_t   t,i;
  138.     char *prod_time;
  139.     i = time (&t);
  140.     prod_time = ctime (&i);
  141. for(int i = 0; i != PROD_DEF-1; i++){
  142. if(strcmp(prod_name, productos[i]) == 0){
  143. cout <<"Ya existe el producto " << prod_name <<". (ID:" << i <<")" << endl;
  144. return 1; // FALLA CREACION
  145. }
  146. }
  147.  
  148. sprintf(productos[PROD_DEF], "%s", prod_name);
  149. precios[PROD_DEF] = prod_precio;
  150. sprintf(fechas[PROD_DEF], "%s", prod_time);
  151. PROD_DEF++;
  152. return 0; // CREACION EXITOSA
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement