elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  TIENDA VIRTUAL
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: TIENDA VIRTUAL  (Leído 2,760 veces)
Jean Pool

Desconectado Desconectado

Mensajes: 5


Ver Perfil
TIENDA VIRTUAL
« en: 12 Julio 2011, 07:37 am »

Buenas estoy tratando de hacer un codigo fuente en c++ de una tienda virtual con sockt y control de invetario es decir tengo sierta cantidad de producto y compro tiene que bajar y cuando llegue a 0 que me salga un mensaje no hay mas productos esto es lo que logrado podrian ayudarme a concluirlo o que aumentar gracias

Código:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

struct datos_clientes
{
char clave[4];
char nombre[40];
char calle[50];
char colonia[40];
char telefono[11];
}clientes;

struct datos_productos
{
char clave[4];
char producto[20];
char descripcion[40];
char precio[10];
}productos;

struct datos_factura
{
char clave[4];
char fecha[15];
char clave_cliente[4];
char clave_producto[4];
char cantidad[5];
}facturas;




void main()
{
int opcion=9;
int cantidadprod;
char opcion_seg[2];
char clavebuscar[4];
FILE *archivo, *auxiliar;
float precioprod;
char variablecomp;
int cont;
float totalpagar;

if((archivo=fopen("c:datoscli.txt","a+b"))==NULL)
{
textattr(279);
cprintf("ntno se puede abrir el archivo");
getch();
exit(1);
}
if((auxiliar=fopen("c:borrador.txt","a+b"))==NULL)
{
textattr(279);
cprintf("ntno se puede abrir el archivo");
getch();
exit(1);
}
do
{
textcolor(MAGENTA);
textbackground(GREEN);
clrscr();
printf("n   Tienda eduardo y el guth             ");
printf("nt######################################");
printf("nn 1.- factura de venta");
printf("nn 2.- ingresar nuevo producto");
printf("nn 3.- ingresar nuevo cliente");
printf("nn 4.- buscar factura de una venta");
printf("nn 5.- Buscar producto");
printf("nn 6.- buscar cliente");
printf("nn 7.- Salir");
printf("n Opcion : ");
gets(opcion_seg);
opcion=atoi(opcion_seg);
switch(opcion)
{
case 1:
textattr(168);
clrscr();
freopen("c:datosfact.txt","a+b",archivo);
printf("ntclave de la factura:  ");fflush(stdin);
gets(facturas.clave);
printf("nt fecha: ");fflush(stdin);
gets(facturas.fecha);
printf("ntclave del cliente: ");fflush(stdin);
gets(facturas.clave_cliente);
freopen("c:datoscli.txt","a+b",archivo);
rewind(archivo);
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&clientes,sizeof(clientes),1,archivo)!=1)
{
printf("nt Errror al leer producto");
getch();
exit(3);
}

if(strcmp(facturas.clave_cliente,clientes.clave)==0)
{
cont=2;
printf("nnt Nombre:  %s",clientes.nombre);
}
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("nnt Clave del cliente no existe");
getch();
}
printf("ntclave del producto:   ");fflush(stdin);
gets(facturas.clave_producto);
freopen("c:datosprod.txt","a+b",archivo);
rewind(archivo);
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&productos,sizeof(productos),1,archivo)!=1)
{
printf("nt Errror al leer producto");
getch();
exit(3);
}

if(strcmp(facturas.clave_producto,productos.clave)==0)
{
cont=2;
precioprod=atof(productos.precio);
printf("nt %s",productos.producto);
printf("ntprecio :     %s",productos.precio);
printf("nt cantidad de productos:   ");
gets(facturas.cantidad);
cantidadprod=atoi(facturas.cantidad);
totalpagar=(precioprod)*(cantidadprod);
printf("nt total a pagar= %f ", totalpagar);
getch();
}
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("nt Clave ingresada no existe");
getch();
}

freopen("c:datosfact.txt","a+b",archivo);
if(fwrite(&facturas,sizeof(facturas),1,archivo)!=1)
{
printf("ntError al escribir sobre el archivo");
getch();
}

break;



case 2:
textattr(169);
clrscr();
freopen("c:datosprod.txt","a+b",archivo);
printf("ntingresa clave del producto:   ");fflush(stdin);
gets(productos.clave);
printf("ntingresa nombre del producto:   ");fflush(stdin);
gets(productos.producto);
printf("ntingresa descripcion del producto:   ");fflush(stdin);
gets(productos.descripcion);fflush(stdin);
printf("ntingresa precio:   ");fflush(stdin);
gets(productos.precio);
if(fwrite(&productos,sizeof(productos),1,archivo)!=1)
{
printf("Error al escribir sobre el archivo");
getch();
}
printf("nt %s",productos.precio);
getch();
break;

case 3:

textattr(169);
clrscr();
freopen("c:datoscli.txt","a+b",archivo);
printf("ntingresa clave del cliente:  ");fflush(stdin);
gets(clientes.clave);
printf("ntingresa nombre: ");fflush(stdin);
gets(clientes.nombre);
printf("ntingresa calle: ");fflush(stdin);
gets(clientes.calle);
printf("ntingresa colonia: ");fflush(stdin);
gets(clientes.colonia);
printf("ntingresa telefono: ");fflush(stdin);
gets(clientes.telefono);

if(fwrite(&clientes,sizeof(clientes),1,archivo)!=1)
{
printf("ntError al escribir sobre el archivo");
getch();
exit(2);
}
break;

case 4:
textattr(357);
clrscr();
freopen("c:datosfact.txt","a+b",archivo);
printf("nntIngresa la clave de la factura");fflush(stdin);
scanf("%s", & clavebuscar);
rewind(archivo);
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&facturas,sizeof(facturas),1,archivo)!=1)
{
printf("nt Falla al leer factura de venta");
getch();
exit(3);
}

if(strcmp(facturas.clave,clavebuscar)==0)
{
cont=2;
printf("nt clave: %s", facturas.clave);
printf("nt fecha: %s", facturas.fecha);
freopen("c:datoscli.txt","a+b",auxiliar);
rewind(auxiliar);
variablecomp=fgetc(auxiliar);
fseek(auxiliar,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&clientes,sizeof(clientes),1,auxiliar)!=1)
{
printf("nt Error al leer cliente");
getch();
exit(3);
}

if(strcmp(facturas.clave_cliente,clientes.clave)==0)
{
cont=2;
printf("n Nombre: %s",clientes.nombre);
}
;variablecomp=fgetc(auxiliar);
fseek(auxiliar,0L,SEEK_SET);
}
if (cont!=2)
{
printf("n Clave del cliente no existe");
getch();
}

freopen("c:datosprod.txt","a+b",auxiliar);
rewind(auxiliar);
variablecomp=fgetc(auxiliar);
fseek(auxiliar,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&productos,sizeof(productos),1,auxiliar)!=1)
{
printf("nt Falla al leer producto");
getch();
exit(3);
}

if(strcmp(facturas.clave_producto,productos.clave)==0)
{
cont=2;
printf("n Producto: %s",productos.producto);
printf("n Precio: %s", productos.precio);
precioprod=atof(productos.precio);
}
variablecomp=fgetc(auxiliar);
fseek(auxiliar,0L,SEEK_SET);
}
if (cont!=2)
{
printf("nnt Clave del cliente no existe");
getch();
}


printf("n cantidad: %s", facturas.cantidad);
cantidadprod=atoi(facturas.cantidad);
totalpagar=(precioprod)*(cantidadprod);
printf("n total: %f", totalpagar);
getch();
}
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("nt Clave ingresada no existe");
getch();
}
break;


case 5:
textattr(158);
clrscr();
freopen("c:datosprod.txt","a+b",archivo);
printf("nIngresa la clave del producto: ");fflush(stdin);
gets(clavebuscar);
rewind(archivo);
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&productos,sizeof(productos),1,archivo)!=1)
{
printf("nt Errror al leer producto");
getch();
exit(3);
}

if(strcmp(clavebuscar,productos.clave)==0)
{
cont=2;
printf("n clave: %s",productos.clave);
printf("n producto: %s",productos.producto);
printf("n Dedscripcion: %s",productos.descripcion);
printf("n precio : %s",productos.precio);
getch();
}
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}

if (cont!=2)
{
printf("nt Clave ingresada no existe");
getch();
}
break;
case 6:
textcolor(BLACK);
textbackground(GREEN);
clrscr();
printf("ntclave de cliente a buscar: ");fflush(stdin);
gets(clavebuscar);
freopen("c:datoscli.txt","a+b",archivo);
rewind(archivo);
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&clientes,sizeof(clientes),1,archivo)!=1)
{
printf("nt Errror al leer producto");
getch();
exit(3);
}

if(strcmp(clavebuscar,clientes.clave)==0)
{
cont=2;
printf("nt Clave: %s",clientes.clave);
printf("nt Nombre:  %s",clientes.nombre);   fflush(stdin);
printf("nt Calle: %s", clientes.calle);
printf("nt Colonia: %s",clientes.colonia);
printf("nt Telefono: %s",clientes.telefono);
getch();
}
fflush(stdin);variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("nnt Clave del cliente no existe");
getch();
}
break;

case 7:
textcolor(RED);
textbackground(YELLOW);
cprintf("n Para Salir presiones cualquier tecla");
getch();
break;

default:
textcolor(RED);
textbackground(BLUE);
cprintf("n esta opcon no es valida");
getch();
break;
}
}
while(opcion!=7);
if(fclose(archivo)!=0)
{
textcolor(159);
textbackground(YELLOW);
cprintf("nterror al abrir el archivo");
getch();
exit(4);
}
}


En línea

PiroskY

Desconectado Desconectado

Mensajes: 76


пирожки


Ver Perfil
Re: TIENDA VIRTUAL
« Respuesta #1 en: 13 Julio 2011, 00:44 am »

Yo creo que si vos hiciste ese código, deberías saber hacer lo que preguntas

Usa un acumulador donde vayas acumulando "total" cada vez que lo muestra

y al final, si ese acumulador es mayor a 300, aplicas el descuento


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
tienda virtual
Desarrollo Web
kakashi20 6 4,186 Último mensaje 18 Abril 2012, 18:34 pm
por OssoH
crear tienda virtual
Programación General
3lineas 4 2,444 Último mensaje 20 Agosto 2012, 07:43 am
por 3lineas
Appserv, y Tienda virtual
Software
Ershin 1 1,307 Último mensaje 12 Noviembre 2012, 23:15 pm
por adgellida
¿Tienda virtual de insumos informáticos?
Foro Libre
TheEGG 89 0 1,122 Último mensaje 27 Diciembre 2012, 01:07 am
por TheEGG 89
Montar tienda virtual a nivel local en un cd-rom con vmare
Software
mulero_19 1 1,496 Último mensaje 21 Abril 2013, 22:43 pm
por mulero_19
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines