Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Funciones
- #ifndef FUNCIONES_H_INCLUDED
- #define FUNCIONES_H_INCLUDED
- using namespace std;
- int ValidarId(producto *reg,int id_av ){
- int i=0;
- for(i=0;i<tam;i++)
- {
- if(id_av==reg[i].id)
- {return i;};
- }
- return 0;
- };
- void MostrarUno(producto *reg, int pos)
- {
- cout<<"--------------------"<<endl;
- cout<<"|id="<<reg[pos].id<<"|"<<endl;
- cout<<"|nombre="<<reg[pos].nombre<<"|"<<endl;
- cout<<"|precio= $"<<reg[pos].precio<<"|"<<endl;
- cout<<"|stock actual="<<reg[pos].stock<<"|"<<endl;
- if(reg[pos].stockm>reg[pos].stock)cout<<"|OJO QUE QUEDA MENOS QUE EL MINIMO"<<reg[pos].stockm<<"|"<<endl;
- cout<<"--------------------"<<endl;
- }
- void CargaProd(struct producto *reg, int cont)
- {
- cout<<"Bueno, cargar el producto."<<endl;
- int pos=cont-1, id_av;
- cout<<"ID: ";
- cin>>id_av;
- //validar
- if(ValidarId(reg,id_av)==0){
- reg[pos].id=id_av;
- cout<<"Ahora carga el nombre del item"<<endl;
- cin>>reg[pos].nombre;cout<<endl;
- cout<<"Precio: $";
- cin>>reg[pos].precio;cout<<endl;
- cout<<"Stock: ";
- cin>>reg[pos].stock;
- cout<<"Stock minimo?: ";
- cin>>reg[pos].stockm;
- }
- else{
- cout<<"el articulo ya existe brodi, capaz querés editarlo ;)"<<endl;
- };
- }
- void EditarProd(producto *reg)
- {
- int id_av,pos;
- cout<<"Bueno, querés editar algo. Vamos a ello!"<<endl;
- cout<<"ingresa el id del producto que querés editar. ";
- cout<<"ID: ";
- cin>>id_av;cout<<endl;
- pos=ValidarId(reg,id_av);
- if(pos>0){
- cout<<"Ahora carga el nombre del item"<<endl;
- cin>>reg[pos].nombre;cout<<endl;
- cout<<"Precio: $";
- cin>>reg[pos].precio;cout<<endl;
- cout<<"Stock: ";
- cin>>reg[pos].stock;
- cout<<"Stock minimo?: ";
- cin>>reg[pos].stockm;
- }else
- {cout<<"el item no existe, intentá denuevo"<<endl;return;}
- }
- void MostrarxId(producto *reg)
- {
- int id_av,pos;
- cout<<"Bueno, veamos que producto especifico buscás..."<<endl;
- cout<<"ID: ";
- cin>>id_av;
- pos=ValidarId(reg,id_av);
- MostrarUno(reg,pos);
- }
- void MostrarTodo(producto *reg,int cont)
- {
- for(int i=0;i<cont;i++)
- { cout<<"--------------------"<<endl;
- cout<<"|id="<<reg[i].id<<"|"<<endl;
- cout<<"|nombre="<<reg[i].nombre<<"|"<<endl;
- cout<<"|precio= $"<<reg[i].precio<<"|"<<endl;
- cout<<"|stock actual="<<reg[i].stock<<"|"<<endl;
- if(reg[i].stockm>reg[i].stock)cout<<"|OJO QUE QUEDA MENOS QUE EL MINIMO"<<reg[i].stockm<<"|"<<endl;
- cout<<"--------------------"<<endl;
- }
- }
- void OrdenXID(producto *reg, int cont){
- int i,j;
- producto aux;
- for(i=0;i<cont;i++){
- for(j=0;j<cont-1;j++){
- if(reg[j+1].id<reg[j].id){
- aux=reg[j];
- reg[j]=reg[j+1];
- reg[j+1]=aux;}}}}
- #endif // FUNCIONES_H_INCLUDED
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <clocale>///para que permitan los "ñ" o tildes
- using namespace std;
- struct producto{
- int stock;
- int stockm;
- int id;
- char nombre[30];
- float precio;};
- const int tam=10;
- #include"funciones.h"
- int main()
- { setlocale(LC_ALL,"spanish");///necesario para que permitan los ñ y tildes.
- cout << "hola denuevo!" << endl;
- int opcion=-1,contProd=0;
- producto reg[tam];
- while(opcion!=0)
- { system("pause");
- system("cls");
- cout<<"---------------------------------Menú-----------------------------------------"<<endl;
- cout<<"----------------------------1 - Cargar Productos------------------------------"<<endl;
- cout<<"----------------------------2 - Editar Producto x id--------------------------"<<endl;
- cout<<"----------------------------3 - Listar productos x ID-------------------------"<<endl;
- cout<<"----------------------------4 - Listar productos Ordenados por ID-------------"<<endl;
- cout<<"----------------------------5 - Listar productos Ordenados por precio---------"<<endl;
- cout<<"----------------------------0 - Salir-----------------------------------------"<<endl;
- cout<<"------------------------------------------------------------------------------"<<endl;
- cin>>opcion;
- switch (opcion){
- case 1:{
- contProd++;
- system("cls");
- if(contProd==10){cout<<"ya llegaste al maximo de articulos bro"<<endl;}
- CargaProd(reg,contProd);
- }break;
- case 2:{
- system("cls");
- EditarProd(reg);
- }break;
- case 3:{
- system("cls");
- MostrarxId(reg);
- }break;
- case 4:{
- system("cls");
- cout<<"así se ve ahora"<<endl;
- MostrarTodo(reg,contProd);
- system("pause");
- cout<<"Lo ordenamos... "<<endl;
- OrdenXID(reg,contProd);
- cout<<"y queda así"<<endl;
- MostrarTodo(reg, contProd);
- }break;
- case 5:{}break;
- case 0:{return 0;}break;
- default:{cout<<"opcion no valida Rey"<<endl;}break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement