Professional Documents
Culture Documents
TH C Hành 1 - KTLT - File
TH C Hành 1 - KTLT - File
fscanf(f,"%d\n",&n);
printf("n=%d\n",n);
ds = (TTKhachTK*)malloc (sizeof (TTKhachTK)*(n+1));
for(int i=0 ; i<n ; ++i){
fgets(ds[i].ma,12,f);
fgets(ds[i].ht,30,f);
fgets(ds[i].sdt,11,f);
fscanf(f,"%ld\n",&ds[i].sotien);
ds[i].sdt[strlen(ds[i].sdt)-1]='\0';
fscanf(f,"%d\n",&ds[i].tgg);
printf("%s %s %s %ld %d\n",ds[i].ma,ds[i].ht,ds[i].sdt,ds[i].sotien,ds[i].tgg);
}
}puts("loi doc tep");
fclose(f);
printf("nhap so dien thoai cua khach can tim ");
gets(dienthoai);
dem=0;
for(i=0;i<n;i++)
if(strcmp(ds[i].sdt,dienthoai)==0)//(ds[i].sdt==dienthoai)
{
float ls;
switch(ds[i].tgg)
{
case 1:{
ls=0.03;
break;
}
case 2:{
ls=0.04;
break;
}case 3:{
ls=0.045;
break;
}
case 6:{
ls=0.05;
break;
}
case 9:{
ls=0.06;
break;
}
case 12:{
ls=0.07;
break;
}
}
float lai=ds[i].sotien*ls*ds[i].tgg/12;
printf("ho ten %s sdt: %s tien lai %.0f tong tien %.0f",
ds[i].ht,ds[i].sdt,lai,lai+ds[i].sotien);
dem=1;
}
if(dem==0) puts("k tim thay");
//tao tepj khach hang than thiet
//FILE *f;
f=fopen("khachhangthanthiet.txt","w");
dem=0;
for(i=0;i<n;i++)
if(ds[i].tgg>6 && ds[i].sotien>1000000000)
{
fprintf(f,"%s %s %s %ld %d\n",ds[i].ma,ds[i].ht,ds[i].sdt,ds[i].sotien,ds[i].tgg);
dem++;
}
if(dem==0)
fputs("k co khach hang than thiet",f);
fclose(f);
}
Bước 2: Tạo tệp khanhguitietkiem.txt như sau:
2
KH01
Ten 1
091233333
6
500000000
KH02
Ten 2
031233333
12
5000000000
Bước 3: chạy chương trình
Bước 4: tạo tệp inputKH.txt có 5 khách hàng và chạy là chương trình để theo dõi kết quả
Bước 5: Bổ sung thêm chức năng tìm khách hàng có số tiền gửi nhiều nhất