Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define CANT_REGISTROS 3000
- #define ARCHIVO_ENTRADA "STOCK.dat"
- #define ARCHIVO_UPDATE "STOCK_ACT.dat"
- struct registro{
- int articulo;
- char descripcion[25];
- float precio_unitario;
- int punto_pedido;
- int stock;
- };
- void test_prepare(){
- FILE *f = fopen(ARCHIVO_ENTRADA, "w");
- struct registro test[] = {{1, "uno", 1.0, 5, 5},
- {2, "dos", 2.0, 2, 7},
- {3, "tres", 4.0, 75, 5},
- {4, "cuatro", 59.9, 3, 5}};
- fwrite(test, sizeof(struct registro), 4, f);
- fclose(f);
- }
- float calculo_porcentaje(int n1, int n2){
- return (n1*100)/n2;
- }
- int read_articulo(struct registro registros_generales[]){
- FILE *f = fopen(ARCHIVO_ENTRADA, "r");
- if(f == NULL)
- return -1;
- struct registro r;
- int i=0;
- while(fread(&r, sizeof(struct registro), 1, f)){
- registros_generales[i] = r;
- i++;
- }
- fclose(f);
- return i;
- }
- int actualizar_articulo_array(int cant_vendida, int id, int cant_registros_leidos, struct registro registros_generales[]){
- int i;
- for(i=0;i<cant_registros_leidos;i++){
- if(registros_generales[i].articulo == id){
- registros_generales[i].stock -= cant_vendida;
- return (registros_generales[i].stock < registros_generales[i].punto_pedido ? 0 : 1);
- }
- }
- return -1;
- }
- void actualizar_articulo_archivo(int cant_registros_leidos, struct registro registros_generales[]){
- FILE *f = fopen(ARCHIVO_UPDATE, "w");
- if(f == NULL)
- return;
- fwrite(registros_generales, sizeof(struct registro), cant_registros_leidos, f);
- fclose(f);
- }
- int validar(int b, int u, char data[]){
- int v;
- scanf("%d", &v);
- while(v < b && v > u){
- printf("Error: reingrese el %s:/n", data);
- scanf("%d", &v);
- }
- return v;
- }
- int main(){
- int i;
- int vendedor, n_articulo, dia;
- float cant_vendida;
- float importe_vendido_julio[31] = {0.0};
- int menor_vendida = 1000, menor_vendedor=0;
- int rechazado=0, total_ventas=0, pedido_inferior=0;
- int estado_venta;
- struct registro registros_generales[CANT_REGISTROS];
- test_prepare();
- int cant_registros_leidos = read_articulo(registros_generales);
- if(cant_registros_leidos == -1){
- printf("Error leyendo el archivo inicial. Abra de nuevo el programa");
- return 0;
- }
- printf("Ingrese El codigo del vendedor: \n");
- vendedor = validar(0, 20, "vendedor");
- while(vendedor != 0){
- printf("Ingrese el numero del articulo: \n");
- scanf("%d", &n_articulo);
- printf("Ingrese el dia: \n");
- dia = validar(1, 30, "dia");
- printf("Ingrese la cantidad vendida: \n");
- scanf("%f", &cant_vendida);
- if(menor_vendida > cant_vendida){
- menor_vendida = cant_vendida;
- menor_vendedor = vendedor;
- }
- importe_vendido_julio[dia] += cant_vendida;
- estado_venta = actualizar_articulo_array(cant_vendida, n_articulo, cant_registros_leidos, registros_generales);
- if(estado_venta == 0)
- pedido_inferior++;
- else if(estado_venta == -1)
- rechazado++;
- total_ventas++;
- printf("Ingrese El codigo del vendedor: \n");
- vendedor = validar(0, 20, "vendedor");
- }
- actualizar_articulo_archivo(cant_registros_leidos, registros_generales);
- if(menor_vendida != 1000)
- printf("El vendedor %d vendio lo minimo: %d\n", menor_vendedor, menor_vendida);
- if(total_ventas > 0){
- printf("Dia\tImporte Vendido\n");
- for(i=1;i<31;i++)
- if(importe_vendido_julio[i] > 0)
- printf("%d \t %.2f\n", i, importe_vendido_julio[i]);
- }
- if(total_ventas > 0)
- printf("Porcentaje de movimientos rechazados: %.2f\n", calculo_porcentaje(rechazado, total_ventas));
- if(cant_registros_leidos >0)
- printf("Porcentaje de articulos debajo del punto de pedido: %.2f\n", calculo_porcentaje(pedido_inferior, cant_registros_leidos));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement