Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>//Biblioteca estándar de entrada y salida, para utilizar cout y cin
- #include <stdio.h>
- #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 */
- #include <conio.h> //
- #include <windows.h>// para utilizar la funcion sleep y copy
- #include <string.h>// libreria para utilizar la funcion que compara dos cademas
- #include <time.h>
- using namespace std;
- #define MAX_PRODUCTOS 100
- int PROD_DEF = 5; // YA DEFINIDOS EN CODIGO
- char productos[MAX_PRODUCTOS][30] =
- {
- "Soda", // 0
- "Hamburguesa", // 1
- "Papas Fritas", // 2
- "Doritos", // 3
- "Palomitas" // 4
- };
- int precios[MAX_PRODUCTOS] = {
- 1, // soda
- 3, // hamburguesa
- 2, // papas fritas
- 3, //doritos
- 5 //palomitas
- };
- char fechas[MAX_PRODUCTOS][30] = {
- "Mon Oct 14 07:53:05 2019",
- "Mon Oct 14 07:53:05 2019",
- "Mon Oct 14 07:53:05 2019",
- "Mon Oct 14 07:53:05 2019",
- "Mon Oct 14 07:53:05 2019"
- };
- int registrar_producto(char *prod_name, int prod_precio);
- void mostrar_productos();
- int modificar_producto(int prod_id, char *prod_name, int prod_precio);
- main()
- {
- int opc;//Declaración de variable de tipo entero
- do{ system("cls");
- char *name = (char *)malloc(sizeof(char)*30);
- int price = 0;
- int id_mod = 0;
- cout<<"\tEMPRESA ALMAFIN S.A"<<endl;
- cout<<"\t ALMACEN"<<endl<<endl;
- cout<<"MENU DE OPCIONES"<<endl<<endl;
- cout<<" 1. Registrar articulos. "<<endl;
- cout<<" 2. Ver lista de articulos. "<<endl;
- cout<<" 3. Modificar articulos. "<<endl;
- cout<<" 4. Salir. "<<endl;
- cout<<endl<<endl<<" Por favor elija una de las opciones: "<<endl<<endl;
- cin>>opc;
- switch(opc)
- {
- case 1: system("cls");
- cout<<endl<<"1. Registrar articulo " <<endl;
- cout << "ingresa el nombre del producto nuevo: ";
- cin >> name;
- cout << "ingresa el precio del nuevo producto: ";
- cin >> price;
- registrar_producto(name, price);
- cout << "ID:" << PROD_DEF-1 << "- Nombre: " << productos[PROD_DEF-1] << " - precio: " << precios[PROD_DEF-1] << " - Fecha de registro: " << fechas[PROD_DEF-1]<< endl;
- opc = 0;
- system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
- break;
- case 2: system("cls");
- cout<<endl<<"2. Ver lista de articulos. "<<endl;
- mostrar_productos();
- opc = 0;
- system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
- break;
- case 3: system("cls");
- cout<<endl<<" 3. modificar articulos . "<<endl;
- cout << "ingresa el ID del producto a modificar: ";
- cin >> id_mod;
- cout << "ingresa el nuevo nombre del producto: ";
- cin >> name;
- cout << "ingresa el nuevo precio del producto: ";
- cin >> price;
- modificar_producto(id_mod, name, price);
- opc = 0;
- system("pause");//Detiene la ejecución del programa hasta que el usuario digite una tecla
- break;
- default:
- break;
- }
- }
- while(opc!=4);
- system("pause");
- return 0;
- }
- void mostrar_productos(){
- for(int i = 0; i != PROD_DEF; i++){
- cout << "ID: " <<i<<" - Nombre: " <<productos[i]<< " - Precio:"<< precios[i] << " Fecha de registro:" << fechas[i] <<endl;
- }
- }
- int modificar_producto(int prod_id, char *prod_name, int prod_precio){
- time_t t,i;
- char *prod_time;
- i = time (&t);
- prod_time = ctime (&i);
- for(int i = 0; i != PROD_DEF-1; i++){
- if(strcmp(prod_name, productos[i]) == 0){
- cout <<"Ya existe el producto " << prod_name <<". (ID:" << i <<")" << endl;
- return 1; // FALLA CREACION
- }
- }
- 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)
- for(int i = 0; i != 30; i++) fechas[prod_id][i] = 0x00; // LLENAR DE VACIOS LA VARIABLE FECHAS
- sprintf(productos[prod_id], "%s", prod_name);
- precios[prod_id] = prod_precio;
- sprintf(fechas[prod_id], "%s", prod_time);
- return 0; // CREACION EXITOSA
- }
- int registrar_producto(char *prod_name, int prod_precio){
- time_t t,i;
- char *prod_time;
- i = time (&t);
- prod_time = ctime (&i);
- for(int i = 0; i != PROD_DEF-1; i++){
- if(strcmp(prod_name, productos[i]) == 0){
- cout <<"Ya existe el producto " << prod_name <<". (ID:" << i <<")" << endl;
- return 1; // FALLA CREACION
- }
- }
- sprintf(productos[PROD_DEF], "%s", prod_name);
- precios[PROD_DEF] = prod_precio;
- sprintf(fechas[PROD_DEF], "%s", prod_time);
- PROD_DEF++;
- return 0; // CREACION EXITOSA
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement