Está en la página 1de 2

#include"stdio.

h"
class C_COSTOS
{
public : int k_prod;int cant_prod;float cost_unit;
void agregar(void);
void eliminar(int cod);
};
void C_COSTOS::agregar(void)
{
FILE *f1,*f2,*f3;
f1=fopen("COSTOS.txt","a");
f2=fopen("COSTOS.txt","r");
f3=fopen("duplicado.txt","a");
int wk_prod,wcant_prod;float wcost_unit;int sw=0;
while(fscanf(f2,"%d %d %f\n",&wk_prod,&wcant_prod,&wcost_unit)>0)
{
if(wk_prod==k_prod){
fprintf(f3,"%d\n",k_prod); sw=1;
}
}
if(sw==0){
fprintf(f1,"%d\t%d\t%f\n",k_prod,cant_prod,cost_unit);
}
fclose(f1);fclose(f2);fclose(f3);
}
void C_COSTOS::eliminar(int c)
{
FILE *f1,*f2;
f1=fopen("au.txt","w");
f2=fopen("COSTOS.txt","r");
int wk_prod,wcant_prod;float wcost_unit;
while(fscanf(f2,"%d %d %f\n",&wk_prod,&wcant_prod,&wcost_unit)>0)
{
fprintf(f1,"%d\t%d\t%f\n",wk_prod,wcant_prod,wcost_unit);
}
fclose(f2);
fclose(f1);
f1=fopen("au.txt","r");
f2=fopen("COSTOS.txt","w");
while(fscanf(f1,"%d %d %f\n",&wk_prod,&wcant_prod,&wcost_unit)>0)
{
if(wk_prod!=c){
fprintf(f2,"%d\t%d\t%f\n",wk_prod,wcant_prod,wcost_unit);
}

fclose(f1);fclose(f2);
}
main(){
FILE *f1;
f1=fopen("COSTOS.txt","w");
C_COSTOS x1;
printf("DATOS A AGREGAR\n");
for(int i=0;i<5;i++){
scanf("%d %d %f",&x1.k_prod,&x1.cant_prod,&x1.cost_unit);
x1.agregar();
}
printf("borrar producto, ingresar codigo\n");
int cod;
scanf("%d",&cod);
x1.eliminar(cod);
fclose(f1);
}

También podría gustarte

  • Analísis Literario
    Analísis Literario
    Documento5 páginas
    Analísis Literario
    Christopher Chuquín
    Aún no hay calificaciones
  • BOHLER
    BOHLER
    Documento24 páginas
    BOHLER
    Christopher Chuquín
    Aún no hay calificaciones
  • Bohler
    Bohler
    Documento9 páginas
    Bohler
    Christopher Chuquín
    Aún no hay calificaciones
  • Analísis Literario
    Analísis Literario
    Documento5 páginas
    Analísis Literario
    Christopher Chuquín
    0% (1)
  • PRODUCTOS
    PRODUCTOS
    Documento20 páginas
    PRODUCTOS
    Christopher Chuquín
    Aún no hay calificaciones
  • Informe Desorción
    Informe Desorción
    Documento27 páginas
    Informe Desorción
    Christopher Chuquín
    Aún no hay calificaciones
  • Aplicaciones Industriales
    Aplicaciones Industriales
    Documento5 páginas
    Aplicaciones Industriales
    Christopher Chuquín
    Aún no hay calificaciones