-
Notifications
You must be signed in to change notification settings - Fork 0
/
规划.c
97 lines (80 loc) · 2.2 KB
/
规划.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdio.h"
#include "string.h"
#define N 100
struct rest
{
int num;
int year;
int month;
int day;
int hour;
int min;
int sec;
int tnum;
int cnum;
char name[10];
int money;
float discount;
float fmoney;
}rest[N],a[N];
int main(int argc, char const *argv[])
{
char ch[200];
int s,t;
FILE *fp;
int i;
fp=fopen("restaurant.txt","r");
fgets(ch,200,fp);
printf("%s", ch);
for(i=0;i<N;i++)
{
fread(&a[i],sizeof(struct rest),1,fp);
if(a[i].tnum==0)
break;
// if(s==a[i].month&&t==a[i].day)
//if(0==strcmp(str,a[i].name))
printf("%-5d| %d/%02d/%02d | %d:%02d:%02d| %-7d | %-9d| %-11s| %-9d| %-7.1f| %.1f\n",a[i].num,a[i].year,a[i].month,a[i].day,a[i].hour,a[i].min,a[i].sec,a[i].tnum,a[i].cnum,a[i].name,a[i].money,a[i].discount,a[i].fmoney);
}
// fclose(fp);
// fp=fopen("restaurant.txt","r");
rewind(fp);
scanf("%d",&t);
fgets(ch,200,fp);
printf("%s", ch);
for(i=0;i<N;i++)
{
fread(&a[i],sizeof(struct rest),1,fp);
if(t==i+1)
{
scanf("%d",&a[i].money);
if(a[i].money>=0&&a[i].money<=100)
rest[i].discount=10;
else if(a[i].money>100&&a[i].money<=200)
rest[i].discount=9.5;
else if(a[i].money>200&&a[i].money<=500)
a[i].discount=9;
else a[i].discount=8;
a[i].fmoney=a[i].money*a[i].discount/10;
//fseek(fp,-sizeof(struct rest),1);
//fwrite(&a[i],sizeof(struct rest),1,fp);
//fseek(fp,-sizeof(struct rest),1);
}
if(a[i].tnum==0)
break;
//if(s==a[i].month&&t==a[i].day)
//if(0==strcmp(str,a[i].name))
printf("%-5d| %d/%02d/%02d | %d:%02d:%02d| %-7d | %-9d| %-11s| %-9d| %-7.1f| %.1f\n",a[i].num,a[i].year,a[i].month,a[i].day,a[i].hour,a[i].min,a[i].sec,a[i].tnum,a[i].cnum,a[i].name,a[i].money,a[i].discount,a[i].fmoney);
}
fclose(fp);
fp=fopen("restaurant.txt","w");
fputs("编号 | 日期 | 时间 | 台面号 | 顾客数量 | 接待服务生 | 消费金额 | 折扣率 | 实收金额\n",fp);
for ( i = 0; i < N; ++i)
{
if(fwrite(&a[i],sizeof(struct rest),1,fp)==0)
printf("file write error\n");
if(a[i].tnum==0)
break;
}
fclose(fp);
return 0;
}