Dev - C++ - programa para registrar los productos, ayuda por favor

 
Vista:
sin imagen de perfil

programa para registrar los productos, ayuda por favor

Publicado por carlos alexis (8 intervenciones) el 02/05/2022 03:43:23
Se requiere crear una aplicación que permita registrar productos, los atributos que define un producto
son:
1. Código, tipo de dato entero
2. Descripción, tipo de dato, string.
3. Cantidad en existencia, tipo de dato double
4. Cantidad mínima, tipo de dato, double
5. Cantidad máxima, tipo de dato, double.
6. Activo, tipo de dato, boleano.
La aplicación debe permitir:
a) Registrar productos nuevos.
b) Modificar productos existentes.
c) Consultar un producto por código.
d) Listar todos los productos ordenados por la descripción.
e) El programa debe utilizar un vector el cual contendrá los productos,
Std::vector<StProducto> lstProducto;
Requisitos.
a) El código del producto no se puede repetir.
b) El campo descripción debe tener un mínimo de cuatro caracteres.
c) Los Atributos: cantidad en existencia, cantidad minina y cantidad máxima no admiten valores
negativos.
d) El valor del campo o atributo cantidad mínima debe ser un valor menor o igual al valor del
campo cantidad máxima.
e) Debe crear un programa (archivo) que contenga
a. la especificación del producto.
b. Las funciones
i. Adicionar
ii. Modificar
iii. Consultar
iv. Listar
c. Cada funcionalidad debe recibir por referencia el vector de productos.
f) Debe crear un programa que utilice las funcionalidades del punto (e).
Diseño pantalla.
--- Registro de productos –
1. Nuevo
2. Modificar
3. Consultar
4. Listar
5. Salir
Opción : __
--- Nuevo Registro de producto –
Código : 1
Descripción : Martillo neumatico
Cantidades
En existencia : 4
Mínima : 1
Máxima : 2
El programa debe realizar las validaciones de lugar, si todos los valores de los atributos son
correctos entonces se incluirá el producto en el vector en caso contrario se desplegara el
mensaje <El producto no puede ser registrado, Existe un producto con el código introducido> .
El programa retornara el control al punto donde se invocó la funcionalidad.
--- Modificar Registro de productos –
Código : 1
Descripción : Martillo de percusión mecánica
Cantidades
En existencia : 4
Mínima : 1
Máxima : 2
El programa debe realizar las validaciones de lugar, si todos los valores de los atributos son
correctos y existe en el vector un producto con el código introducido entonces se reemplazaran
los datos de los atributos con los nuevos valores, en caso de no existir un producto con el código
introducido el programa desplegara el mensaje <El producto no puede ser modificado, NO
Existe un producto con el código introducido> .
El programa retornara el control al punto donde se invocó la funcionalidad.
--- Consultar Registro de productos –
Código : 1 [ Si existe en el vector un producto con código 1 entonces la aplicación desplegara
los datos <valores de los atributos> de dicho producto ]
Descripción : Martillo de percusión mecánica
Cantidades
En existencia : 4
Mínima : 1
Máxima : 2
[Si no existe un producto registrado con el código introducido se desplegara el mensaje :
Producto no existe , retornando el control del programa al lugar donde se invocó la
funcionalidad [Consultar]
--- Listar Registro de productos –
Código Descripción CantExistencia CantMaxima CantMinima Activo
10 Martillo Neumatico 4 6 2 S
11 Taladro XYZ 10 20 4 N
…. …………… .. .. .. ..
1. Luego de desplegar los productos el control del programa debe ser retornado al punto donde se
invocó la funcionalidad [Listar
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder
sin imagen de perfil

programa para registrar los productos, ayuda por favor

Publicado por Carlos (8 intervenciones) el 03/05/2022 13:20:44
Alguien que me ayude? Lo necesito para mañana
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar

programa para registrar los productos, ayuda por favor

Publicado por Jaja (1 intervención) el 03/05/2022 15:12:57
Jajajajajajaja

Que desatinado eres.

Que tranquilo y relajado.

Francamente te pasas....
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

programa para registrar los productos, ayuda por favor

Publicado por Carlos (8 intervenciones) el 03/05/2022 21:33:32
pude hacer la tarea, comprueben alguien si, o si no, que me corriga

#include<iostream>
#include<iomanip>
#include <string.h>

using namespace std;

const int MAX_P = 999; // max number of products in the database
const int L_ID = 999; // max >= ID
const int L_NM = 15; // max length of name ... a-z i AZ 09
const int L_CAT = 15; // max characters of each category ... """""
const int L_PR = 999; // max price >0 2 decimales
const int L_DAT = 8; // date yyyy-mm 1-12-dd-1-31
const int L_QUA = 999; // maximun quantity
const int L_SUPP = 999; // maximun supply
const int L_ID_T = L_ID + 1; // to be used in the definition of null-terminated string
const int L_CAT_T = L_CAT + 1; // -- || --
const int L_NM_T = L_NM + 1; // -- || --
const int L_PR_T = L_PR + 1;
const int L_DAT_T = L_DAT + 1;
const int L_QUA_T = L_QUA + 1;
const int L_SUPP_T = L_SUPP + 1;


struct product{
char ID[L_ID_T];
char name[L_NM_T];
char category[L_CAT_T];
char price[L_PR_T];
char date[L_DAT_T];
char quantity[L_QUA_T];
char supply[L_SUPP_T];
};

void initialize ( product L[], int &prod_cnt );

void show_menu ( int opc );
void menu_main ( product L[], int prod_cnt );
void menu_search ( const product L[], const int prod_cnt );
void menu_remove ( product L[], int &prod_cnt );
void menu_modify ( product L[], int &prod_cnt );

void write_listing_header ();
void show_product ( const product );
void list_products ( const product L[], const int prod_cnt );
void list_products_ind ( const product L[], const int Ind[], const int ind_cnt );

void insert_product ( product L[], int &prod_cnt );

void remove_product_ID ( product L[], int &prod_cnt );
void n_remove_product_ID ( product L[], int &prod_cnt );

void bsort ( product L[], int n );

int search_ID ( const product L[], const int prod_cnt, char ID [] );
int search_cate ( const product L[], const int prod_cnt, char category[], int Ind[] );

void search_wrt_ID ( const product L[], const int prod_cnt );
void search_wrt_cate ( const product L[], const int prod_cnt );


// ------------------------------------------------------
int main()
{
product L[MAX_P];
int prod_cnt;

initialize(L,prod_cnt);
menu_main(L,prod_cnt);
}



int search_ID (const product L[], const int prod_cnt, char ID[])
{
for (int i = 0; i < prod_cnt; i++)
if (strcmp( L[i].ID, ID ) == 0) return i;
return -1 ;
}



void search_wrt_ID (const product L[], const int prod_cnt)
{
char ID[L_ID_T];
int ind;

cout << "Enter ID: ";
cin >> ID;
if ((ind = search_ID(L,prod_cnt,ID)) != -1 )
{
write_listing_header();
show_product(L[ind]);
}
else
{
cout << "No product with ID " << ID << endl;
system("pause");
}
}


int search_cate (const product L[], const int prod_cnt, char category[], int ind[])
{
int cnt = 0;
for (int i = 0; i < prod_cnt; i++)
if ( strcmp(L[i].category, category ) == 0) ind[cnt++] = i;
return cnt;
}


void search_wrt_cate (const product L[], const int prod_cnt)
{
char category[L_CAT_T];
int Ind[MAX_P];
int ind_cnt;

cout << "Enter category: ";
cin >> category;
if ( (ind_cnt = search_cate(L,prod_cnt,category,Ind)) != 0 )
list_products_ind(L,Ind,ind_cnt);
else
{
cout << "No product in category " << category << endl;
system("pause");
}
}



void insert_product (product L[], int &prod_cnt)
{
char ID[L_ID_T];
int ind;

if (prod_cnt < MAX_P)
{
cout << "ID: ";
cin >> ID;
if ( (ind = search_ID(L,prod_cnt,ID)) == -1)
{
strcpy(L[prod_cnt].ID,ID);
cout << "category: ";
cin >> L[prod_cnt].category;
cout << "Name: ";
cin >> L[prod_cnt].name;
cout << "Price: ";
cin >> L[prod_cnt].price;
cout << "Date: ";
cin >> L[prod_cnt].date;
cout << "Quantity: ";
cin >> L[prod_cnt].quantity;
cout << "Supply: ";
cin >> L[prod_cnt].supply;
prod_cnt ++;
}
else
{
cout << "product with ID " << ID
<< " already exists in the database " << endl;
show_product( L[ind] );
system("pause");
}
}
else
{
cout << "Impossible to insert new product - out of storage ;)" << endl;
system("pause");
}
}


void remove_product_ID (product L[], int &prod_cnt)
{
char ID[L_ID_T];
int ind;

cout << "Enter ID of a product to be removed: ";
cin >> ID;
if ( (ind = search_ID( L, prod_cnt, ID )) != -1 ) // found!
{
for( int i = ind; i < prod_cnt - 1; i++ )
L[i] = L[i+1];
prod_cnt--;
}
else
{
cout << "No product with ID " << ID << endl;
system("pause");
}
}

// Deleting product with a given ID

// -----------------------------------------------------
void n_remove_product_ID (product L[], int &prod_cnt)
{
char ID[L_ID_T];
int ind;

cout << "Enter ID of a product to be removed: ";
cin >> ID;
if ( (ind = search_ID( L, prod_cnt, ID )) != -1 )
{
L[ind] = L[prod_cnt-1];
prod_cnt--;
}
}

// ------------------------------------------------------------- LISTINGS

void show_product (const product p)
{
cout << setw(5) << p.ID;
cout << setw(11) << p.name;
cout << setw(10) << p.category;
cout << setw(10) << p.price;
cout << setw(10) << p.date;
cout << setw(10) << p.quantity;
cout << setw(10) << p.supply;
cout << endl;
}


// -----------------------------------------------------
void write_listing_header()
{
cout << endl;
cout << " ID | Name | Category | Price | Date | Quantity | Supply |" << endl;
cout << "-------------------------------------------------------------------------" << endl;
}


// -----------------------------------------------------
void list_products (const product L[], const int prod_cnt)
{
write_listing_header();
for (int i = 0; i < prod_cnt; i++)
show_product( L[i] );
cout << "------------------------------------------------------------------------" << endl;
cout << "Number of products = " << prod_cnt << endl;
cout << endl;
}

// -----------------------------------------------------
void list_products_ind (const product L[], const int ind[], const int ind_cnt)
{
write_listing_header();
for (int i = 0; i < ind_cnt; i++)
show_product( L[ind[i]] );
cout << "---------------------------------------------------" << endl;
cout << "Number of products = " << ind_cnt << endl;
cout << endl;
}

// --------------------------------------------------------------- OTHER

// sorting nondecreasingly wrt category
// ------------------------------------------------------
void bsort (product L[], int n)
{
product buf;

for (int j=n-2; j>=0; j--)
for (int i=0; i<=j; i++)
if ( strcmp(L[i].category,L[i+1].category) > 0)
{
buf = L[i+1];
L[i+1] = L[i];
L[i] = buf;
}
}

// ------------------------------------------------------
void initialize (product L[], int &prod_cnt)
{
strcpy(L[0].ID,"001");
strcpy(L[0].name,"Hairband");
strcpy(L[0].category,"Kids");
strcpy(L[0].price,"10");
strcpy(L[0].date,"2014/12/25");
strcpy(L[0].quantity,"45");
strcpy(L[0].supply,"32");


strcpy(L[1].ID,"002");
strcpy(L[1].name,"Skirt");
strcpy(L[1].category,"Woman");
strcpy(L[1].price,"220");
strcpy(L[1].date,"2014/12/25");
strcpy(L[1].quantity,"100");
strcpy(L[1].supply,"32");


strcpy(L[2].ID,"003");
strcpy(L[2].name,"Blazer");
strcpy(L[2].category,"Man");
strcpy(L[2].price,"570");
strcpy(L[2].date,"2015/1/01");
strcpy(L[2].quantity,"75");
strcpy(L[2].supply,"2");


strcpy(L[3].ID,"004");
strcpy(L[3].name,"Minisocks");
strcpy(L[3].category,"Kids");
strcpy(L[3].price,"35");
strcpy(L[3].date,"2014/12/30");
strcpy(L[3].quantity,"100");
strcpy(L[3].supply,"30");


strcpy(L[4].ID,"005");
strcpy(L[4].name,"Dress");
strcpy(L[4].category,"Woman");
strcpy(L[4].price,"90");
strcpy(L[4].date,"2014/12/25");
strcpy(L[4].quantity,"80");
strcpy(L[4].supply,"2");


strcpy(L[5].ID,"006");
strcpy(L[5].name,"Shrit");
strcpy(L[5].category,"Man");
strcpy(L[5].price,"120");
strcpy(L[5].date,"2014/12/20");
strcpy(L[5].quantity,"200");
strcpy(L[5].supply,"20");

strcpy(L[6].ID,"007");
strcpy(L[6].name,"Sweter");
strcpy(L[6].category,"Man");
strcpy(L[6].price,"210");
strcpy(L[6].date,"2014/12/20");
strcpy(L[6].quantity,"200");
strcpy(L[6].supply,"71");


prod_cnt = 6;
}


// -------------------------------------------------------------- MENU
void show_menu (int opc)
{
switch(opc)
{
case 1: {
cout << endl;
cout << "\n\t\t DATABASE" << endl;
cout << "\t ===========" << endl;
cout << "\n\t Please select an option:" <<endl<< endl;
cout << "1 - Add a new product to the database" << endl;
cout << "2 - Remove a product" << endl;
cout << "3 - Display the list of all products" << endl;
cout << "4 - Sort products" << endl;
cout << "5 - Search for a product" << endl;
cout << "6 - Modify a product" << endl;
cout << "0 - Exit the program" << endl;
cout << " \n Option: ";
break;
}
case 2: {
cout << endl;
cout << "SEARCH menu" << endl;
cout << "----------------------" << endl;
cout << "1 - search wrt name" << endl;
cout << "2 - search wrt ID" << endl;
cout << "0 - main menu";
cout << "> ";
break;
}
case 3: {
cout << endl;
cout << "REMOVE menu" << endl;
cout << "----------------------" << endl;
cout << "1 - remove wrt category" << endl;
cout << "2 - remove wrt ID" << endl;
cout << "0 - main menu";
cout << "> ";
break;
}
}
}


void menu_modify (product L[], int &prod_cnt)
{
// ...
}


// --------------------------------------------------------
void menu_remove (product L[], int &prod_cnt)
{
int choice;
do {
show_menu(3);
cin >> choice;
switch(choice)
{
case 1: // ..........
break;
case 2: remove_product_ID(L,prod_cnt);
break;
}
} while (choice != 0);
}

// --------------------------------------------------------
void menu_search (const product L[], const int prod_cnt)
{
int choice;
do {
show_menu(2);
cin >> choice;
switch(choice)
{
case 1: search_wrt_cate(L,prod_cnt);
break;
case 2: search_wrt_ID(L,prod_cnt);
break;
}
} while (choice != 0);
}

// --------------------------------------------------------
void menu_main (product L[], int prod_cnt)
{
int choice;

do {
show_menu(1);
cin >> choice;
switch(choice)
{
case 1: insert_product(L,prod_cnt);
break;
case 2: menu_remove(L,prod_cnt);
break;
case 3: list_products(L,prod_cnt);
break;
case 4: bsort(L,prod_cnt);
break;
case 5: menu_search(L,prod_cnt);
break;
case 6: menu_modify(L,prod_cnt);
break;
}
} while(choice!=0);
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar