📄 transac2.cpp
字号:
/*************Function To Record Transaction Made On Books ******************/
# include"liba.h"
void transac2(int mid,int bno,int gno,int no,char c)
{
struct transaction T;
struct date d;
FILE *ft;
ft=fopen("E:\\cpp\\trans.dat","a+");
FILE *tt1;
tt1=fopen("E:\\cpp\\tempo","w");
rewind(ft);
while(fread(&T,sizeof(T),1,ft) ==1)
;
T.tid+=1; T.mid=mid; T.reason=c;
T.b.bno=bno; T.b.gno=gno; T.b.no=no;
getdate(&d);
T.i.day=d.da_day; T.i.mon=d.da_mon; T.i.year=d.da_year;
if(c=='I')
{
T.r.day=T.i.day; T.r.mon=T.i.mon+1; T.r.year=T.i.year;
if(T.r.mon>12 && T.r.mon!=12)
{
T.r.year+=1; T.r.mon=(T.r.mon-12);
}
if(T.r.day==31)
{
if(T.r.mon==4 || T.r.mon==6 || T.r.mon==9 || T.r.mon==11)
{
T.r.day=1;
T.r.mon+=1;
}
if(T.r.mon==2)
{
if( (T.r.year%4)==0)
{
T.r.day=31-29; T.r.mon+=1;
}
else
{
T.r.day=31-28; T.r.mon+=1;
}
}
}
T.fine=0;
fwrite(&T,sizeof(T),1,ft);
}
else if(c=='U')
{
T.r.day=T.i.day; T.r.mon=T.i.mon+1; T.r.year=T.i.year;
if(T.r.mon>12 && T.r.mon!=12)
{
T.r.year+=1; T.r.mon=(T.r.mon-12);
}
if(T.r.day==31)
{
if(T.r.mon==4 || T.r.mon==6 || T.r.mon==9 || T.r.mon==11)
{
T.r.day=1;
T.r.mon+=1;
}
if(T.r.mon==2)
{
if( (T.r.year%4)==0)
{
T.r.day=31-29; T.r.mon+=1;
}
else
{
T.r.day=31-28; T.r.mon+=1;
}
}
}
T.fine=0;
fwrite(&T,sizeof(T),1,ft);
}
else if(c=='R')
{
rewind(ft);
while(fread(&T,sizeof(T),1,ft)==1)
{
if(T.mid==mid && T.b.bno==bno && T.b.gno==gno && T.b.no==no && T.reason=='I')
{
T.r.day=d.da_day; T.r.mon=d.da_mon; T.r.year=d.da_year;
T.reason='R';
printf("\n\t Enter Fine::");
scanf("%f",&T.fine);
fwrite(&T,sizeof(T),1,tt1);
}
else
{
fwrite(&T,sizeof(T),1,tt1);
}
}
fclose(ft);
fclose(tt1);
tt1=fopen("E:\\cpp\\tempo","r");
rewind(tt1);
ft=fopen("E:\\cpp\\trans.dat","w");
while(fread(&T,sizeof(T),1,tt1)==1)
{
fwrite(&T,sizeof(T),1,ft);
}
fclose(ft);
ft=fopen("E:\\cpp\\trans.dat","a+");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -