SlideShare una empresa de Scribd logo
1 de 10
#include <ctype.h> // isdigit
#include <stdlib.h> // atoi
#include <string.h> // strlen
#include <stdio.h> // printf, fgets, stdin, BUFSIZ
#include<iostream> //cout, cin
#include<fstream>
#include<stdlib> //system()
#include<stdio>
#include<conio> //gotoxy
#include<cstring>
//funciones
int nuevaFactura();
void menu();
int BDFactura();
int Buscar_Factura();
int Buscar_Clientes();
int Ingreso_Menu(char buffer[BUFSIZ]);
int demeNumero(int y,int x);
bool ingreso_cadena_con_espacio(char letras2[]);
bool ingreso_cadena(char letras[]);
//Estructura para el detalle
struct
{
int nProducto[30];//es el numero de producto osea Num.
int numFactura; //numero de la factura
int cantidad[30];//se puede almacenar hasta 30 cantidades
char nomProducto[30][30]; //almaceno caracteres con espacio; es el nombre
del producto
char medida[10][30]; //almaceno caracteres con espacio; es la medida
del producto
int numProductos; //es cuantos productos voy a ingresar
double precioUnitario[30];
double precioTotal[30];
double SubTotal;
double IVA;
double Total;
} Detalle;
//Estructura para la factura
struct
{
int numFactura;
char nombre[30];
char apellido[30];
int cedula;
char direccion[70];
int telefono;
char fecha[12];
char vendedor[30];
double total;
} Facturas;
int main(void)
{
int opcion;
do //ciclo repetir asta que
{
system("cls");//borrar pantalla
menu();//menu de opciones
char buffer[BUFSIZ];//hacemos el nuevaFactura numerico con buffer
opcion=Ingreso_Menu(buffer);//en la funcion Ingreso_Menu(buffer) se hace
el nuevaFactura
system("cls");//borrar pantalla
switch(opcion)//seleccion de en caso que respuesta se
{
case 1:
nuevaFactura();
break;//sea uno llama al procedimiento nuevaFactura arriba
case 2:
Buscar_Factura();
system("pause");
break;//llama ala funcion ver datos
case 3:
Buscar_Clientes();
system("pause");
break;//llama ala funcion ver datos
case 4:
BDFactura();
system("pause");
break;//llama ala funcion ver datos
case 5:
system("cls");
cout<<"nnnntQue tenga buenos diasnnn";
system("pause");
exit(1);
break;//cierra el programa
default:
cout<<"nn numero incorrecto intente nuevamente!nn";
system("pause");
break;//lanza un mensaje y vuelve a mostrar los datos
}
}
while(opcion!=5);
system("pause");
return 0;
}
//Menu
void menu(){
//menu para que el usuario se guie.
gotoxy(19,19);printf("%c", 201);//esquina superior izquierda
gotoxy(61,19);printf("%c", 187);//esquina superior derecha
gotoxy(19,39);printf("%c", 200);//esquina inferior izquierda
gotoxy(61,39);printf("%c", 188);//esquina inferior derecha
for(int k=20; k<61; k++){//dibujamos las lineas horizontales
gotoxy(k,19);printf("%c", 205);
gotoxy(k,39);printf("%c", 205);
}
for(int k=20; k<39; k++){//dijumos las lineas verticales
gotoxy(19,k);printf("%c", 186);
gotoxy(61,k);printf("%c", 186);
}
gotoxy(22,22);cout<<" * La tienda xxxxxxxx S.A. * ";
for(int k=20; k<61; k++){//dibujamos linea horizontal
gotoxy(k,24);printf("%c", 205);
}
gotoxy(24,26);cout<<" FACTURACION ";
gotoxy(20,27);cout<<"_________________________________________";
gotoxy(26,30);cout<<"1 - Nueva Factura ";
gotoxy(26,31);cout<<"2 - Buscar numero de factura ";
gotoxy(26,32);cout<<"3 - Buscar apellido de Cliente";
gotoxy(26,33);cout<<"4 - Base de datos ";
gotoxy(26,34);cout<<"5 - Exit ";
gotoxy(27,36);printf("Ingrese opcion %c ", 175 );//solicitud de su
respuesta
}
//opcion 1
int nuevaFactura()
{
char numero[10];
system("cls");//borrar pantalla
gotoxy(1,1); printf("%c", 201);//esquina superior izquierda
gotoxy(80,1); printf("%c", 187);//esquina superior derecha
gotoxy(1,44); printf("%c", 200);//esquina inferior izquierda
gotoxy(80,44);printf("%c", 188);//esquina inferior derecha
for(int k=2; k<80; k++){//dibujamos las lineas horizontales
gotoxy(k,1); printf("%c", 205);
gotoxy(k,6); printf("%c", 205);
gotoxy(k,44);printf("%c", 205);
gotoxy(k,9); printf("_");
gotoxy(k,14);printf("_");
}
for(int k=2; k<44; k++){//dijumos las lineas verticales
gotoxy(1,k); printf("%c", 186);
gotoxy(80,k);printf("%c", 186);
}
gotoxy(25,4);cout<<" * La tienda xxxxxxxx S.A. * ";
gotoxy(34,8);cout<<" NUEVA FACTURA ";
// captura de campos
gotoxy(10,12);cout << "Fecha : ";
gotoxy(37,12);cout << "Vendedor : ";
gotoxy(10,13);cout << "Factura No: ";
gotoxy(18,12);cin >> Facturas.fecha;
char letras[10];
do{
gotoxy(48,12);gets(letras);
if(ingreso_cadena_con_espacio(letras)==true){
strcpy(Facturas.vendedor,letras);
}else{
gotoxy(48,12);clreol();
}
}while(ingreso_cadena_con_espacio(letras)==false);
gotoxy(22,13);Facturas.numFactura=demeNumero(22,13);
gotoxy(30,14);cout << " DATOS DEL CLIENTE ";
gotoxy(10,16);cout << "Nombre : ";
gotoxy(37,16);cout << "Apellido : ";
gotoxy(37,17);cout << "Cedula : " ;
gotoxy(10,17);cout << "Direccion : ";
gotoxy(10,18);cout << "Telefono : ";
do{
gotoxy(19,16);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Facturas.nombre,letras);
}else{
gotoxy(19,16);clreol();
gotoxy(37,16);cout << "Apellido : ";
}
}while(ingreso_cadena(letras)==false);
do{
gotoxy(48,16);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Facturas.apellido,letras);
}else{
gotoxy(48,16);clreol();
}
}while(ingreso_cadena(letras)==false);
do{
gotoxy(22,17);gets(letras);
if(ingreso_cadena_con_espacio(letras)==true){
strcpy(Facturas.direccion,letras);
}else{
gotoxy(22,17);clreol();
gotoxy(37,17);cout << "Cedula : " ;
}
}while(ingreso_cadena_con_espacio(letras)==false);
gotoxy(46,17);Facturas.cedula=demeNumero(46,17);
gotoxy(21,18);Facturas.telefono=demeNumero(21,18);
Detalle.numFactura = Facturas.numFactura;
gotoxy(3,21);printf("Ingrese el numero de productos: ");
gotoxy(35,21);Detalle.numProductos=demeNumero(35,21);
//aqui estan las lineas del nembrete del detalle
gotoxy(2,22);
printf("________________________________________________________________________
______");
gotoxy(2,25);
printf("________________________________________________________________________
______");
//dibujo las lineas verticales del nembrete del detalle
for(int i=0; i<4; i++){
gotoxy(8,23+i); printf("%c", 179);
gotoxy(28,23+i);printf("%c", 179);
gotoxy(39,23+i);printf("%c", 179);
gotoxy(49,23+i);printf("%c", 179);
gotoxy(64,23+i);printf("%c", 179);//espacio para P. Total
}
//ubicamos en pantalla los rotulos del detalle
gotoxy(3,24);printf("Num.");
gotoxy(10,24);cout << "DETALLE PRODUCTO";
gotoxy(30,24);cout << "CANTIDAD";
gotoxy(40,24);cout << "Kg,lbs..";
gotoxy(52,24);cout << "P. Unitario";
gotoxy(67,24);cout << "P. Total";
int i=27,j=0;//posiciones en pantalla
Detalle.SubTotal= Detalle.nProducto[j];//acumula el preciototal
while(j<Detalle.numProductos)
{
gotoxy(3,i);printf(" %d ",j+1); Detalle.nProducto[j]=j+1;//numero
de articulo
char nombreProducto[30],medida_kg_lts[10];
gotoxy(11,i);gets(nombreProducto);strcpy(Detalle.nomProducto[j],nombreProducto);
gotoxy(33,i);Detalle.cantidad[j]=demeNumero(33,i);
do{
gotoxy(44,i);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Detalle.medida[j],letras);
}else{
gotoxy(44,i);clreol();
}
}while(ingreso_cadena(letras)==false);
gotoxy(57,i); cin>> Detalle.precioUnitario[j]; //puede ser entero o
flotante hay que hacer validacion
Detalle.precioTotal[j]= Detalle.cantidad[j] *
Detalle.precioUnitario[j];//calculo del subtotal
gotoxy(70,i);printf("%5.2f",Detalle.precioTotal[j]);
Detalle.SubTotal= Detalle.precioTotal[j] +
Detalle.SubTotal;//acumulo en SubTotal los precios Totales
gotoxy(2,i+1);printf("- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - ");
gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle
gotoxy(28,i); printf("%c", 179);
gotoxy(39,i); printf("%c", 179);
gotoxy(49,i); printf("%c", 179);
gotoxy(64,i); printf("%c", 179);
i=i+1; //contador para las posiciones de las lineas en pantalla
gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle
gotoxy(28,i); printf("%c", 179);
gotoxy(39,i); printf("%c", 179);
gotoxy(49,i); printf("%c", 179);
gotoxy(64,i); printf("%c", 179);
i=i+1;
j=j+1; //acumulador para el numero de productos
}
gotoxy(2,i-
1);printf("_____________________________________________________________________
_________");
i=i+2;
Detalle.IVA=Detalle.SubTotal*0.12;
Detalle.Total= Detalle.SubTotal+Detalle.IVA;
Facturas.total=Detalle.Total;
gotoxy(52,i); printf("Subtotal : $ %5.2f",Detalle.SubTotal);
gotoxy(52,i+2);cout <<"IVA. 12% : ";printf("$ %5.2f",Detalle.IVA);
gotoxy(52,i+4);printf("- - - - - - - - - -n");
gotoxy(52,i+6); printf(" Total -> $ %5.2f",Detalle.Total);
gotoxy(2,i+8);printf("__________________________________________________________
____________________");
getch();
//Grabamos a disco la estructura factura
FILE *archdisco_factura;
archdisco_factura = fopen("c:factura.txt","at+");
fwrite(&Facturas,sizeof(Facturas),1,archdisco_factura);
fclose(archdisco_factura);
//avisando usuario
// cout << "nntfactura insertada " << endl;
//Grabamos a disco la estructura detalle
FILE *archdisco_detalle;
archdisco_detalle = fopen("c:detalle.txt","at+");
fwrite(&Detalle,sizeof(Detalle),1,archdisco_detalle);
fclose(archdisco_detalle);
//avisando usuario
cout << "tFactura guardada con exito n" << endl;
system("pause");
return 0;
}
//opcion 2
int Buscar_Factura()
{
int factura;
cout << "nnIngrese numero de factura a buscar: ";
gotoxy(37,3);factura=demeNumero(37,3);
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_detalles;
archdisco_open_detalles = fopen("c:detalle.txt","r");
//leemos el archivo de datos
bool encontrado = false;
cout << "n"<< endl;
while(fread(&Detalle,sizeof(Detalle),1,archdisco_open_detalles)==1)
{
if (factura == Detalle.numFactura)
{
cout << "|| Factura No = " << Detalle.numFactura << endl;
for(int j=0; j <Detalle.nProducto[j]; j++){
cout << "|| Num." << Detalle.nProducto[j] << endl;
cout << "|| "<<endl;
cout << "|| Producto = " << Detalle.nomProducto[j] << endl;
cout << "|| Cantidad = " << Detalle.cantidad[j] << endl;
cout << "|| Medida = " << Detalle.medida[j] << endl;
printf("|| P. Unit. = %5.2f",Detalle.precioUnitario[j]);
printf("n");
printf("|| P. Total = %5.2f",Detalle.precioUnitario[j]);
printf("n");
}
cout << "||"<<endl;
cout << "|| SUBTOTAL = " << Detalle.SubTotal << endl;
cout << "|| IVA. 12% = ";printf("$ %5.2f",Detalle.IVA);
printf("n");
printf("|| TOTAL -> $ %5.2f",Detalle.Total);
cout << "n________________________________________________________n"
<< endl;
encontrado = true;
}
};
if (encontrado==false)
{
cout <<"nnLa factura: " << factura << " no fue hallada" << endl;
}
//Cerramos el archivo.
fclose(archdisco_open_detalles);
return 0;
}
//opcion 3
int Buscar_Clientes()
{
char apellido_a_buscar[30];
char * pch;
int caracter;
bool encontrado = false;
char texto_a_buscar[30];
cout << "nnIngrese parte del Apellido a buscar: ";
do{
gotoxy(38,3);gets(texto_a_buscar);
if(ingreso_cadena(texto_a_buscar)==false){
gotoxy(38,3);clreol();
}
}while(ingreso_cadena(texto_a_buscar)==false);
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_Facturas;
archdisco_open_Facturas = fopen("c:factura.txt","r");
//leemos el archivo de datos e informamos
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
strcpy (apellido_a_buscar, Facturas.apellido);
pch = strstr (apellido_a_buscar, texto_a_buscar);
caracter = pch - apellido_a_buscar + 1;
if (caracter >= 0)
{
cout << " nnApellido : " << texto_a_buscar << " fue encontrado..."
<< endl;
cout <<
"n________________________________________________________n" << endl;
cout << "|| - Fecha = " << Facturas.fecha << endl;
cout << "|| Fact. No = " << Facturas.numFactura << endl;
cout << "|| Apellido = " << Facturas.apellido << endl;
cout << "|| Nombre = " << Facturas.nombre << endl;
cout << "|| Cedula = " << Facturas.cedula << endl;
cout << "|| Direccion = " << Facturas.direccion << endl;
cout << "|| Telefono = " << Facturas.telefono << endl;
cout << "|| "<<endl;
printf(" || TOTAL -> $ %5.2f",Facturas.total);
cout <<
"n________________________________________________________n" << endl;
encontrado=true;
}
};
if (encontrado==false)
{
cout <<"nnEl apellido buscado: " << texto_a_buscar << " no fue
encontrado" << endl;
}
//Cerramos el archivo.
fclose(archdisco_open_Facturas);
return 0;
}
//opcion 4
int BDFactura()
{
int cantidad = 0;
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_Facturas;
archdisco_open_Facturas = fopen("c:factura.txt","r");
//verificamos el numero de elementos de la misma.
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
cantidad++;
};
//Lo informamos al usuario
cout << "nn" << endl;
printf("La base de datos contiene %d facturasn", cantidad);
cout << "nn" << endl;
system("pause");
rewind(archdisco_open_Facturas);
//volvemos a leer el archivo de datos e informamos
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
cout << "|| - Fecha = " << Facturas.fecha << endl;
cout << "|| Fact. No = " << Facturas.numFactura << endl;
cout << "|| Nombre = " << Facturas.nombre << endl;
cout << "|| Apellido = " << Facturas.apellido << endl;
cout << "|| Cedula = " << Facturas.cedula << endl;
cout << "|| Direccion = " << Facturas.direccion << endl;
cout << "|| Telefono = " << Facturas.telefono << endl;
cout << "|| Vendedor = " << Facturas.vendedor << endl;
cout << "||"<<endl;
printf("|| Total -> $ %5.2f",Facturas.total);
cout << "n________________________________________________________n"
<< endl;
};
//Cerramos el archivo.
fclose(archdisco_open_Facturas);
return 0;
}
int Ingreso_Menu(char buffer[BUFSIZ]){
int number;
unsigned n;
bool found_nondigit, valid;
valid = false;
while (!valid) {
//printf ( "Enter an integer: " );
if (fgets (buffer, sizeof buffer, stdin) != NULL) {
buffer[strlen(buffer)-1] = '0';
found_nondigit = false;
if (strlen(buffer) == 0)
found_nondigit = true;
for (n=0; n<strlen(buffer); n++)
if (!isdigit(buffer[n]))
found_nondigit = true;
if (!found_nondigit) {
number = atoi(buffer);
//printf ("%dn", number);
valid = true;
} else{
system("cls");//borrar pantalla
menu();
gotoxy(26,36);
cout<< "Re-ingrese numero -> ";
}
}
}
// system("pause");
return number;
}
int demeNumero(int y,int x){
int t,valcomplex;
bool valida=false;
int digito=0,i=0,a=0;
do{
while ((t = getchar()) != 'n'){
if(isdigit(t)){
valcomplex=t-'0';
t=getchar();
digito++;
while(isdigit(t)){
valcomplex=valcomplex*10+t-'0';
t=getchar();
digito++;
i++;
}
ungetc(t,stdin);
}
i++;
}
if(i==digito){
valida =true;
}else{
digito=0;
i=0;
valida =false;
gotoxy(y,x);
clreol();
}
}while(valida==false);
return valcomplex;
}
bool ingreso_cadena(char letras[]){
int i=0,abc=0;
while(letras[i]){
if (isalpha(letras[i])){
abc++;
}
i++;
}
if(i==abc){
return true; //esta bien ingresado el numero
}else{
return false;
}
}
bool ingreso_cadena_con_espacio(char letras2[]){
int i=0,abc=0,blanco=0;
while(letras2[i]){
if (isalpha(letras2[i])){
abc++;
}
else
{
if(letras2[i]=' ');
blanco++;
}
i++;
}
if(blanco==0){
if(abc==i)
return true; //esta bien ingresado el numero
}
else
{
if(blanco==1){
if(i==(blanco+abc))
return true; //esta bien ingresado el numero
}
else
{
return false;
}
}
}
}
i++;
}
if(i==abc){
return true; //esta bien ingresado el numero
}else{
return false;
}
}
bool ingreso_cadena_con_espacio(char letras2[]){
int i=0,abc=0,blanco=0;
while(letras2[i]){
if (isalpha(letras2[i])){
abc++;
}
else
{
if(letras2[i]=' ');
blanco++;
}
i++;
}
if(blanco==0){
if(abc==i)
return true; //esta bien ingresado el numero
}
else
{
if(blanco==1){
if(i==(blanco+abc))
return true; //esta bien ingresado el numero
}
else
{
return false;
}
}
}

Más contenido relacionado

La actualidad más candente

Measuring Effectiveness with Causal Impact Analysis
Measuring Effectiveness with Causal Impact AnalysisMeasuring Effectiveness with Causal Impact Analysis
Measuring Effectiveness with Causal Impact AnalysisForward3D
 
Cajero en C++
Cajero en C++Cajero en C++
Cajero en C++IngridBs
 
Sistmas de 7x7
Sistmas de 7x7Sistmas de 7x7
Sistmas de 7x7Edgar Mata
 
Sistmas de 6x6
Sistmas de 6x6Sistmas de 6x6
Sistmas de 6x6Edgar Mata
 
Fuzzy c-means clustering
Fuzzy c-means clusteringFuzzy c-means clustering
Fuzzy c-means clusteringOmar Sanchez
 
7 sustituciones diversas
7 sustituciones diversas7 sustituciones diversas
7 sustituciones diversasHenry Romero
 
51 ejercicios raíces y función raíz cuadrada
51 ejercicios raíces y función raíz cuadrada51 ejercicios raíces y función raíz cuadrada
51 ejercicios raíces y función raíz cuadradaMarcelo Calderón
 
Derivadas "Calculo Diferencial"
Derivadas "Calculo Diferencial"Derivadas "Calculo Diferencial"
Derivadas "Calculo Diferencial"wpio12
 

La actualidad más candente (13)

Measuring Effectiveness with Causal Impact Analysis
Measuring Effectiveness with Causal Impact AnalysisMeasuring Effectiveness with Causal Impact Analysis
Measuring Effectiveness with Causal Impact Analysis
 
Cajero en C++
Cajero en C++Cajero en C++
Cajero en C++
 
Sistmas de 7x7
Sistmas de 7x7Sistmas de 7x7
Sistmas de 7x7
 
Division algebraica # 02
Division algebraica # 02Division algebraica # 02
Division algebraica # 02
 
Sistmas de 6x6
Sistmas de 6x6Sistmas de 6x6
Sistmas de 6x6
 
Fuzzy c-means clustering
Fuzzy c-means clusteringFuzzy c-means clustering
Fuzzy c-means clustering
 
Regla de la cadena
Regla de la cadenaRegla de la cadena
Regla de la cadena
 
7 sustituciones diversas
7 sustituciones diversas7 sustituciones diversas
7 sustituciones diversas
 
Lista de-derivadas
Lista de-derivadasLista de-derivadas
Lista de-derivadas
 
51 ejercicios raíces y función raíz cuadrada
51 ejercicios raíces y función raíz cuadrada51 ejercicios raíces y función raíz cuadrada
51 ejercicios raíces y función raíz cuadrada
 
Funciones ejercicios-resueltos
Funciones ejercicios-resueltosFunciones ejercicios-resueltos
Funciones ejercicios-resueltos
 
Division de expresiones algebraicas
Division de expresiones algebraicasDivision de expresiones algebraicas
Division de expresiones algebraicas
 
Derivadas "Calculo Diferencial"
Derivadas "Calculo Diferencial"Derivadas "Calculo Diferencial"
Derivadas "Calculo Diferencial"
 

Similar a Factura en borland c++

Similar a Factura en borland c++ (20)

PROYECTO DE LISTA LINEAL DOBLE
PROYECTO DE LISTA LINEAL DOBLEPROYECTO DE LISTA LINEAL DOBLE
PROYECTO DE LISTA LINEAL DOBLE
 
(Meta 5.1)función sin parámetros que no retorna valor dev c++
(Meta 5.1)función sin parámetros que no retorna valor dev c++ (Meta 5.1)función sin parámetros que no retorna valor dev c++
(Meta 5.1)función sin parámetros que no retorna valor dev c++
 
Aritmetica
AritmeticaAritmetica
Aritmetica
 
Unidad16 Codigof1
Unidad16 Codigof1Unidad16 Codigof1
Unidad16 Codigof1
 
Ejemplos Importantisimo
Ejemplos  ImportantisimoEjemplos  Importantisimo
Ejemplos Importantisimo
 
Apunfun2
Apunfun2Apunfun2
Apunfun2
 
Codigos de programas
Codigos de programasCodigos de programas
Codigos de programas
 
Codigos de programas
Codigos de programasCodigos de programas
Codigos de programas
 
Codigos de programas
Codigos de programasCodigos de programas
Codigos de programas
 
Laboratorio1 entrada-salida de datos / Lenguance C
Laboratorio1   entrada-salida de datos / Lenguance CLaboratorio1   entrada-salida de datos / Lenguance C
Laboratorio1 entrada-salida de datos / Lenguance C
 
Ejemplos c++
Ejemplos c++Ejemplos c++
Ejemplos c++
 
Programa 14
Programa 14Programa 14
Programa 14
 
programa de matematicas en lenguaje c
programa de matematicas en lenguaje c programa de matematicas en lenguaje c
programa de matematicas en lenguaje c
 
Estructuras punteros
Estructuras punterosEstructuras punteros
Estructuras punteros
 
Ejercicios de programación en C (Estructuras condicionales-Selectivas)
Ejercicios de programación en C (Estructuras condicionales-Selectivas)Ejercicios de programación en C (Estructuras condicionales-Selectivas)
Ejercicios de programación en C (Estructuras condicionales-Selectivas)
 
Algoritmos resueltos
Algoritmos resueltosAlgoritmos resueltos
Algoritmos resueltos
 
Programación C++
Programación C++Programación C++
Programación C++
 
Union y concatenacion
Union y concatenacionUnion y concatenacion
Union y concatenacion
 
algoritmos y Programacion
algoritmos y Programacionalgoritmos y Programacion
algoritmos y Programacion
 
Practica de programacion 21 28
Practica de programacion 21 28Practica de programacion 21 28
Practica de programacion 21 28
 

Último

MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMarjorie Burga
 
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptx
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptxEXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptx
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptxPryhaSalam
 
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Carlos Muñoz
 
GLOSAS Y PALABRAS ACTO 2 DE ABRIL 2024.docx
GLOSAS  Y PALABRAS ACTO 2 DE ABRIL 2024.docxGLOSAS  Y PALABRAS ACTO 2 DE ABRIL 2024.docx
GLOSAS Y PALABRAS ACTO 2 DE ABRIL 2024.docxAleParedes11
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxlclcarmen
 
programa dia de las madres 10 de mayo para evento
programa dia de las madres 10 de mayo  para eventoprograma dia de las madres 10 de mayo  para evento
programa dia de las madres 10 de mayo para eventoDiegoMtsS
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxzulyvero07
 
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADODECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADOJosé Luis Palma
 
Heinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoHeinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoFundación YOD YOD
 
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzel CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzprofefilete
 
cortes de luz abril 2024 en la provincia de tungurahua
cortes de luz abril 2024 en la provincia de tungurahuacortes de luz abril 2024 en la provincia de tungurahua
cortes de luz abril 2024 en la provincia de tungurahuaDANNYISAACCARVAJALGA
 
codigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinacodigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinavergarakarina022
 
Clasificaciones, modalidades y tendencias de investigación educativa.
Clasificaciones, modalidades y tendencias de investigación educativa.Clasificaciones, modalidades y tendencias de investigación educativa.
Clasificaciones, modalidades y tendencias de investigación educativa.José Luis Palma
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadAlejandrino Halire Ccahuana
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosCesarFernandez937857
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxjosetrinidadchavez
 
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARO
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARONARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARO
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFAROJosé Luis Palma
 
CALENDARIZACION DE MAYO / RESPONSABILIDAD
CALENDARIZACION DE MAYO / RESPONSABILIDADCALENDARIZACION DE MAYO / RESPONSABILIDAD
CALENDARIZACION DE MAYO / RESPONSABILIDADauxsoporte
 
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdf
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdfSELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdf
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdfAngélica Soledad Vega Ramírez
 

Último (20)

MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grande
 
Repaso Pruebas CRECE PR 2024. Ciencia General
Repaso Pruebas CRECE PR 2024. Ciencia GeneralRepaso Pruebas CRECE PR 2024. Ciencia General
Repaso Pruebas CRECE PR 2024. Ciencia General
 
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptx
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptxEXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptx
EXPANSIÓN ECONÓMICA DE OCCIDENTE LEÓN.pptx
 
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
 
GLOSAS Y PALABRAS ACTO 2 DE ABRIL 2024.docx
GLOSAS  Y PALABRAS ACTO 2 DE ABRIL 2024.docxGLOSAS  Y PALABRAS ACTO 2 DE ABRIL 2024.docx
GLOSAS Y PALABRAS ACTO 2 DE ABRIL 2024.docx
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
 
programa dia de las madres 10 de mayo para evento
programa dia de las madres 10 de mayo  para eventoprograma dia de las madres 10 de mayo  para evento
programa dia de las madres 10 de mayo para evento
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
 
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADODECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
 
Heinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoHeinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativo
 
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzel CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
 
cortes de luz abril 2024 en la provincia de tungurahua
cortes de luz abril 2024 en la provincia de tungurahuacortes de luz abril 2024 en la provincia de tungurahua
cortes de luz abril 2024 en la provincia de tungurahua
 
codigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinacodigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karina
 
Clasificaciones, modalidades y tendencias de investigación educativa.
Clasificaciones, modalidades y tendencias de investigación educativa.Clasificaciones, modalidades y tendencias de investigación educativa.
Clasificaciones, modalidades y tendencias de investigación educativa.
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdad
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos Básicos
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
 
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARO
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARONARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARO
NARRACIONES SOBRE LA VIDA DEL GENERAL ELOY ALFARO
 
CALENDARIZACION DE MAYO / RESPONSABILIDAD
CALENDARIZACION DE MAYO / RESPONSABILIDADCALENDARIZACION DE MAYO / RESPONSABILIDAD
CALENDARIZACION DE MAYO / RESPONSABILIDAD
 
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdf
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdfSELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdf
SELECCIÓN DE LA MUESTRA Y MUESTREO EN INVESTIGACIÓN CUALITATIVA.pdf
 

Factura en borland c++

  • 1. #include <ctype.h> // isdigit #include <stdlib.h> // atoi #include <string.h> // strlen #include <stdio.h> // printf, fgets, stdin, BUFSIZ #include<iostream> //cout, cin #include<fstream> #include<stdlib> //system() #include<stdio> #include<conio> //gotoxy #include<cstring> //funciones int nuevaFactura(); void menu(); int BDFactura(); int Buscar_Factura(); int Buscar_Clientes(); int Ingreso_Menu(char buffer[BUFSIZ]); int demeNumero(int y,int x); bool ingreso_cadena_con_espacio(char letras2[]); bool ingreso_cadena(char letras[]); //Estructura para el detalle struct { int nProducto[30];//es el numero de producto osea Num. int numFactura; //numero de la factura int cantidad[30];//se puede almacenar hasta 30 cantidades char nomProducto[30][30]; //almaceno caracteres con espacio; es el nombre del producto char medida[10][30]; //almaceno caracteres con espacio; es la medida del producto int numProductos; //es cuantos productos voy a ingresar double precioUnitario[30]; double precioTotal[30]; double SubTotal; double IVA; double Total; } Detalle; //Estructura para la factura struct { int numFactura; char nombre[30]; char apellido[30]; int cedula; char direccion[70]; int telefono; char fecha[12]; char vendedor[30]; double total; } Facturas; int main(void) { int opcion; do //ciclo repetir asta que { system("cls");//borrar pantalla menu();//menu de opciones char buffer[BUFSIZ];//hacemos el nuevaFactura numerico con buffer opcion=Ingreso_Menu(buffer);//en la funcion Ingreso_Menu(buffer) se hace el nuevaFactura
  • 2. system("cls");//borrar pantalla switch(opcion)//seleccion de en caso que respuesta se { case 1: nuevaFactura(); break;//sea uno llama al procedimiento nuevaFactura arriba case 2: Buscar_Factura(); system("pause"); break;//llama ala funcion ver datos case 3: Buscar_Clientes(); system("pause"); break;//llama ala funcion ver datos case 4: BDFactura(); system("pause"); break;//llama ala funcion ver datos case 5: system("cls"); cout<<"nnnntQue tenga buenos diasnnn"; system("pause"); exit(1); break;//cierra el programa default: cout<<"nn numero incorrecto intente nuevamente!nn"; system("pause"); break;//lanza un mensaje y vuelve a mostrar los datos } } while(opcion!=5); system("pause"); return 0; } //Menu void menu(){ //menu para que el usuario se guie. gotoxy(19,19);printf("%c", 201);//esquina superior izquierda gotoxy(61,19);printf("%c", 187);//esquina superior derecha gotoxy(19,39);printf("%c", 200);//esquina inferior izquierda gotoxy(61,39);printf("%c", 188);//esquina inferior derecha for(int k=20; k<61; k++){//dibujamos las lineas horizontales gotoxy(k,19);printf("%c", 205); gotoxy(k,39);printf("%c", 205); } for(int k=20; k<39; k++){//dijumos las lineas verticales gotoxy(19,k);printf("%c", 186); gotoxy(61,k);printf("%c", 186); } gotoxy(22,22);cout<<" * La tienda xxxxxxxx S.A. * "; for(int k=20; k<61; k++){//dibujamos linea horizontal gotoxy(k,24);printf("%c", 205); } gotoxy(24,26);cout<<" FACTURACION "; gotoxy(20,27);cout<<"_________________________________________"; gotoxy(26,30);cout<<"1 - Nueva Factura "; gotoxy(26,31);cout<<"2 - Buscar numero de factura "; gotoxy(26,32);cout<<"3 - Buscar apellido de Cliente"; gotoxy(26,33);cout<<"4 - Base de datos "; gotoxy(26,34);cout<<"5 - Exit "; gotoxy(27,36);printf("Ingrese opcion %c ", 175 );//solicitud de su respuesta }
  • 3. //opcion 1 int nuevaFactura() { char numero[10]; system("cls");//borrar pantalla gotoxy(1,1); printf("%c", 201);//esquina superior izquierda gotoxy(80,1); printf("%c", 187);//esquina superior derecha gotoxy(1,44); printf("%c", 200);//esquina inferior izquierda gotoxy(80,44);printf("%c", 188);//esquina inferior derecha for(int k=2; k<80; k++){//dibujamos las lineas horizontales gotoxy(k,1); printf("%c", 205); gotoxy(k,6); printf("%c", 205); gotoxy(k,44);printf("%c", 205); gotoxy(k,9); printf("_"); gotoxy(k,14);printf("_"); } for(int k=2; k<44; k++){//dijumos las lineas verticales gotoxy(1,k); printf("%c", 186); gotoxy(80,k);printf("%c", 186); } gotoxy(25,4);cout<<" * La tienda xxxxxxxx S.A. * "; gotoxy(34,8);cout<<" NUEVA FACTURA "; // captura de campos gotoxy(10,12);cout << "Fecha : "; gotoxy(37,12);cout << "Vendedor : "; gotoxy(10,13);cout << "Factura No: "; gotoxy(18,12);cin >> Facturas.fecha; char letras[10]; do{ gotoxy(48,12);gets(letras); if(ingreso_cadena_con_espacio(letras)==true){ strcpy(Facturas.vendedor,letras); }else{ gotoxy(48,12);clreol(); } }while(ingreso_cadena_con_espacio(letras)==false); gotoxy(22,13);Facturas.numFactura=demeNumero(22,13); gotoxy(30,14);cout << " DATOS DEL CLIENTE "; gotoxy(10,16);cout << "Nombre : "; gotoxy(37,16);cout << "Apellido : "; gotoxy(37,17);cout << "Cedula : " ; gotoxy(10,17);cout << "Direccion : "; gotoxy(10,18);cout << "Telefono : "; do{ gotoxy(19,16);gets(letras); if(ingreso_cadena(letras)==true){ strcpy(Facturas.nombre,letras); }else{ gotoxy(19,16);clreol(); gotoxy(37,16);cout << "Apellido : "; } }while(ingreso_cadena(letras)==false); do{ gotoxy(48,16);gets(letras); if(ingreso_cadena(letras)==true){ strcpy(Facturas.apellido,letras); }else{ gotoxy(48,16);clreol(); } }while(ingreso_cadena(letras)==false); do{ gotoxy(22,17);gets(letras);
  • 4. if(ingreso_cadena_con_espacio(letras)==true){ strcpy(Facturas.direccion,letras); }else{ gotoxy(22,17);clreol(); gotoxy(37,17);cout << "Cedula : " ; } }while(ingreso_cadena_con_espacio(letras)==false); gotoxy(46,17);Facturas.cedula=demeNumero(46,17); gotoxy(21,18);Facturas.telefono=demeNumero(21,18); Detalle.numFactura = Facturas.numFactura; gotoxy(3,21);printf("Ingrese el numero de productos: "); gotoxy(35,21);Detalle.numProductos=demeNumero(35,21); //aqui estan las lineas del nembrete del detalle gotoxy(2,22); printf("________________________________________________________________________ ______"); gotoxy(2,25); printf("________________________________________________________________________ ______"); //dibujo las lineas verticales del nembrete del detalle for(int i=0; i<4; i++){ gotoxy(8,23+i); printf("%c", 179); gotoxy(28,23+i);printf("%c", 179); gotoxy(39,23+i);printf("%c", 179); gotoxy(49,23+i);printf("%c", 179); gotoxy(64,23+i);printf("%c", 179);//espacio para P. Total } //ubicamos en pantalla los rotulos del detalle gotoxy(3,24);printf("Num."); gotoxy(10,24);cout << "DETALLE PRODUCTO"; gotoxy(30,24);cout << "CANTIDAD"; gotoxy(40,24);cout << "Kg,lbs.."; gotoxy(52,24);cout << "P. Unitario"; gotoxy(67,24);cout << "P. Total"; int i=27,j=0;//posiciones en pantalla Detalle.SubTotal= Detalle.nProducto[j];//acumula el preciototal while(j<Detalle.numProductos) { gotoxy(3,i);printf(" %d ",j+1); Detalle.nProducto[j]=j+1;//numero de articulo char nombreProducto[30],medida_kg_lts[10]; gotoxy(11,i);gets(nombreProducto);strcpy(Detalle.nomProducto[j],nombreProducto); gotoxy(33,i);Detalle.cantidad[j]=demeNumero(33,i); do{ gotoxy(44,i);gets(letras); if(ingreso_cadena(letras)==true){ strcpy(Detalle.medida[j],letras); }else{ gotoxy(44,i);clreol(); } }while(ingreso_cadena(letras)==false); gotoxy(57,i); cin>> Detalle.precioUnitario[j]; //puede ser entero o flotante hay que hacer validacion Detalle.precioTotal[j]= Detalle.cantidad[j] * Detalle.precioUnitario[j];//calculo del subtotal gotoxy(70,i);printf("%5.2f",Detalle.precioTotal[j]); Detalle.SubTotal= Detalle.precioTotal[j] + Detalle.SubTotal;//acumulo en SubTotal los precios Totales gotoxy(2,i+1);printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle
  • 5. gotoxy(28,i); printf("%c", 179); gotoxy(39,i); printf("%c", 179); gotoxy(49,i); printf("%c", 179); gotoxy(64,i); printf("%c", 179); i=i+1; //contador para las posiciones de las lineas en pantalla gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle gotoxy(28,i); printf("%c", 179); gotoxy(39,i); printf("%c", 179); gotoxy(49,i); printf("%c", 179); gotoxy(64,i); printf("%c", 179); i=i+1; j=j+1; //acumulador para el numero de productos } gotoxy(2,i- 1);printf("_____________________________________________________________________ _________"); i=i+2; Detalle.IVA=Detalle.SubTotal*0.12; Detalle.Total= Detalle.SubTotal+Detalle.IVA; Facturas.total=Detalle.Total; gotoxy(52,i); printf("Subtotal : $ %5.2f",Detalle.SubTotal); gotoxy(52,i+2);cout <<"IVA. 12% : ";printf("$ %5.2f",Detalle.IVA); gotoxy(52,i+4);printf("- - - - - - - - - -n"); gotoxy(52,i+6); printf(" Total -> $ %5.2f",Detalle.Total); gotoxy(2,i+8);printf("__________________________________________________________ ____________________"); getch(); //Grabamos a disco la estructura factura FILE *archdisco_factura; archdisco_factura = fopen("c:factura.txt","at+"); fwrite(&Facturas,sizeof(Facturas),1,archdisco_factura); fclose(archdisco_factura); //avisando usuario // cout << "nntfactura insertada " << endl; //Grabamos a disco la estructura detalle FILE *archdisco_detalle; archdisco_detalle = fopen("c:detalle.txt","at+"); fwrite(&Detalle,sizeof(Detalle),1,archdisco_detalle); fclose(archdisco_detalle); //avisando usuario cout << "tFactura guardada con exito n" << endl; system("pause"); return 0; } //opcion 2 int Buscar_Factura() { int factura; cout << "nnIngrese numero de factura a buscar: "; gotoxy(37,3);factura=demeNumero(37,3); //abrimos el archivo que contiene la estructura FILE *archdisco_open_detalles; archdisco_open_detalles = fopen("c:detalle.txt","r"); //leemos el archivo de datos bool encontrado = false; cout << "n"<< endl; while(fread(&Detalle,sizeof(Detalle),1,archdisco_open_detalles)==1) { if (factura == Detalle.numFactura) { cout << "|| Factura No = " << Detalle.numFactura << endl; for(int j=0; j <Detalle.nProducto[j]; j++){
  • 6. cout << "|| Num." << Detalle.nProducto[j] << endl; cout << "|| "<<endl; cout << "|| Producto = " << Detalle.nomProducto[j] << endl; cout << "|| Cantidad = " << Detalle.cantidad[j] << endl; cout << "|| Medida = " << Detalle.medida[j] << endl; printf("|| P. Unit. = %5.2f",Detalle.precioUnitario[j]); printf("n"); printf("|| P. Total = %5.2f",Detalle.precioUnitario[j]); printf("n"); } cout << "||"<<endl; cout << "|| SUBTOTAL = " << Detalle.SubTotal << endl; cout << "|| IVA. 12% = ";printf("$ %5.2f",Detalle.IVA); printf("n"); printf("|| TOTAL -> $ %5.2f",Detalle.Total); cout << "n________________________________________________________n" << endl; encontrado = true; } }; if (encontrado==false) { cout <<"nnLa factura: " << factura << " no fue hallada" << endl; } //Cerramos el archivo. fclose(archdisco_open_detalles); return 0; } //opcion 3 int Buscar_Clientes() { char apellido_a_buscar[30]; char * pch; int caracter; bool encontrado = false; char texto_a_buscar[30]; cout << "nnIngrese parte del Apellido a buscar: "; do{ gotoxy(38,3);gets(texto_a_buscar); if(ingreso_cadena(texto_a_buscar)==false){ gotoxy(38,3);clreol(); } }while(ingreso_cadena(texto_a_buscar)==false); //abrimos el archivo que contiene la estructura FILE *archdisco_open_Facturas; archdisco_open_Facturas = fopen("c:factura.txt","r"); //leemos el archivo de datos e informamos while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1) { strcpy (apellido_a_buscar, Facturas.apellido); pch = strstr (apellido_a_buscar, texto_a_buscar); caracter = pch - apellido_a_buscar + 1; if (caracter >= 0) { cout << " nnApellido : " << texto_a_buscar << " fue encontrado..." << endl; cout << "n________________________________________________________n" << endl; cout << "|| - Fecha = " << Facturas.fecha << endl; cout << "|| Fact. No = " << Facturas.numFactura << endl; cout << "|| Apellido = " << Facturas.apellido << endl; cout << "|| Nombre = " << Facturas.nombre << endl; cout << "|| Cedula = " << Facturas.cedula << endl;
  • 7. cout << "|| Direccion = " << Facturas.direccion << endl; cout << "|| Telefono = " << Facturas.telefono << endl; cout << "|| "<<endl; printf(" || TOTAL -> $ %5.2f",Facturas.total); cout << "n________________________________________________________n" << endl; encontrado=true; } }; if (encontrado==false) { cout <<"nnEl apellido buscado: " << texto_a_buscar << " no fue encontrado" << endl; } //Cerramos el archivo. fclose(archdisco_open_Facturas); return 0; } //opcion 4 int BDFactura() { int cantidad = 0; //abrimos el archivo que contiene la estructura FILE *archdisco_open_Facturas; archdisco_open_Facturas = fopen("c:factura.txt","r"); //verificamos el numero de elementos de la misma. while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1) { cantidad++; }; //Lo informamos al usuario cout << "nn" << endl; printf("La base de datos contiene %d facturasn", cantidad); cout << "nn" << endl; system("pause"); rewind(archdisco_open_Facturas); //volvemos a leer el archivo de datos e informamos while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1) { cout << "|| - Fecha = " << Facturas.fecha << endl; cout << "|| Fact. No = " << Facturas.numFactura << endl; cout << "|| Nombre = " << Facturas.nombre << endl; cout << "|| Apellido = " << Facturas.apellido << endl; cout << "|| Cedula = " << Facturas.cedula << endl; cout << "|| Direccion = " << Facturas.direccion << endl; cout << "|| Telefono = " << Facturas.telefono << endl; cout << "|| Vendedor = " << Facturas.vendedor << endl; cout << "||"<<endl; printf("|| Total -> $ %5.2f",Facturas.total); cout << "n________________________________________________________n" << endl; }; //Cerramos el archivo. fclose(archdisco_open_Facturas); return 0; } int Ingreso_Menu(char buffer[BUFSIZ]){ int number; unsigned n; bool found_nondigit, valid; valid = false;
  • 8. while (!valid) { //printf ( "Enter an integer: " ); if (fgets (buffer, sizeof buffer, stdin) != NULL) { buffer[strlen(buffer)-1] = '0'; found_nondigit = false; if (strlen(buffer) == 0) found_nondigit = true; for (n=0; n<strlen(buffer); n++) if (!isdigit(buffer[n])) found_nondigit = true; if (!found_nondigit) { number = atoi(buffer); //printf ("%dn", number); valid = true; } else{ system("cls");//borrar pantalla menu(); gotoxy(26,36); cout<< "Re-ingrese numero -> "; } } } // system("pause"); return number; } int demeNumero(int y,int x){ int t,valcomplex; bool valida=false; int digito=0,i=0,a=0; do{ while ((t = getchar()) != 'n'){ if(isdigit(t)){ valcomplex=t-'0'; t=getchar(); digito++; while(isdigit(t)){ valcomplex=valcomplex*10+t-'0'; t=getchar(); digito++; i++; } ungetc(t,stdin); } i++; } if(i==digito){ valida =true; }else{ digito=0; i=0; valida =false; gotoxy(y,x); clreol(); } }while(valida==false); return valcomplex; } bool ingreso_cadena(char letras[]){ int i=0,abc=0; while(letras[i]){ if (isalpha(letras[i])){ abc++;
  • 9. } i++; } if(i==abc){ return true; //esta bien ingresado el numero }else{ return false; } } bool ingreso_cadena_con_espacio(char letras2[]){ int i=0,abc=0,blanco=0; while(letras2[i]){ if (isalpha(letras2[i])){ abc++; } else { if(letras2[i]=' '); blanco++; } i++; } if(blanco==0){ if(abc==i) return true; //esta bien ingresado el numero } else { if(blanco==1){ if(i==(blanco+abc)) return true; //esta bien ingresado el numero } else { return false; } } }
  • 10. } i++; } if(i==abc){ return true; //esta bien ingresado el numero }else{ return false; } } bool ingreso_cadena_con_espacio(char letras2[]){ int i=0,abc=0,blanco=0; while(letras2[i]){ if (isalpha(letras2[i])){ abc++; } else { if(letras2[i]=' '); blanco++; } i++; } if(blanco==0){ if(abc==i) return true; //esta bien ingresado el numero } else { if(blanco==1){ if(i==(blanco+abc)) return true; //esta bien ingresado el numero } else { return false; } } }