forked from ravya1108/hactoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer_Billing_System.c
218 lines (206 loc) · 4.91 KB
/
Customer_Billing_System.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void input();
void writefile();
void search();
void output();
struct date{
int month;
int day;
int year;
};
struct account {
int number;
char name[100];
int acct_no;
float mobile_no;
char street[100];
char city[100];
char acct_type;
float oldbalance;
float newbalance;
float payment;
struct date lastpayment;
}customer;
int tl,sl,ts;
void main()
{
int i,n;
char ch;
clrscr();
_setcursortype(_NOCURSOR);
printf(" CUSTOMER BILLING SYSTEM:\n\n");
printf("===============================\n");
printf("\n1: to add account on list\n");
printf("2: to search customer account\n");
printf("3: exit\n");
printf("\n================================\n");
do{
printf("\nselect what do you want to do?");
ch=getche();
}while(ch<='0' || ch>'3');
switch(ch){
case '1':
clrscr();
printf("\nhow many customer accounts?");
scanf("%d",&n);
for(i=0;i<n;i++){
input();
if(customer.payment>0)
customer.acct_type=(customer.payment<0.1*customer.oldbalance)? 'O': 'D';
else
customer.acct_type=(customer.oldbalance>0)?'D' : 'C';
customer.newbalance=customer.oldbalance - customer.payment;
writefile();
}
main();
case '2':
clrscr();
printf("search by what?\n");
printf("\n1 --- search by customer number\n");
printf("2 --- search by customer name\n");
search();
ch=getche();
main();
case '3':
clrscr();
delay(700);
textcolor(RED);
gotoxy(25,25);
cprintf("\nA PROJECT BY BIDUR & SUJAN");
delay(1500);
exit(1);
}
}
void input()
{
FILE *fp=fopen("bidur.dat","rb");
fseek (fp,0,SEEK_END);
tl=ftell(fp);
sl=sizeof(customer);
ts=tl/sl;
fseek(fp,(ts-1)*sl,SEEK_SET);
fread(&customer,sizeof(customer),1,fp);
printf("\ncustomer no:%d\n",++customer.number);
fclose(fp);
printf(" Account number:");
scanf("%d",&customer.acct_no);
printf("\n Name:");
scanf("%s",customer.name);
printf("\n mobile no:");
scanf("%f",&customer.mobile_no);
printf(" Street:");
scanf("%s",customer.street);
printf(" City:");
scanf("%s",customer.city);
printf(" Previous balance:");
scanf("%f",&customer.oldbalance);
printf(" Current payment:");
scanf("%f",&customer.payment);
printf(" Payment date(mm/dd/yyyy):");
scanf("%d/%d/%d",&customer.lastpayment.month,&customer.lastpayment.day,&customer.lastpayment.year);
return;
}
void writefile()
{
FILE *fp;
fp=fopen("bidur.dat","ab");
fwrite(&customer,sizeof(customer),1,fp);
fclose(fp);
return;
}
void search()
{
char ch;
char nam[100];
int n,i,m=1;
FILE *fp;
fp=fopen("bidur.dat","rb");
do{
printf("\nenter your choice:");
ch=getche();
}while(ch!='1' && ch!='2');
switch(ch){
case '1':
fseek(fp,0,SEEK_END);
tl=ftell(fp);
sl=sizeof(customer);
ts=tl/sl;
do{
printf("\nchoose customer number:");
scanf("%d",&n);
if(n<=0 || n>ts)
printf("\nenter correct\n");
else{
fseek(fp,(n-1)*sl,SEEK_SET);
fread(&customer,sl,1,fp);
output();
}
printf("\n\nagain?(y/n)");
ch=getche();
}while(ch=='y');
fclose(fp);
break;
case '2':
fseek(fp,0,SEEK_END);
tl=ftell(fp);
sl=sizeof(customer);
ts=tl/sl;
fseek(fp,(ts-1)*sl,SEEK_SET);
fread(&customer,sizeof(customer),1,fp);
n=customer.number;
do{
printf("\nenter the name:");
scanf("%s",nam);
fseek(fp,0,SEEK_SET);
for(i=1;i<=n;i++)
{
fread(&customer,sizeof(customer),1,fp);
if(strcmp(customer.name,nam)==0)
{
output();
m=0;
break;
}
}
if(m!=0)
printf("\n\ndoesn't exist\n");
printf("\nanother?(y/n)");
ch=getche();
}while(ch=='y');
fclose(fp);
}
return;
}
void output()
{
printf("\n\n Customer no :%d\n",customer.number);
printf(" Name :%s\n",customer.name);
printf(" Mobile no :%.f\n",customer.mobile_no);
printf(" Account number :%d\n",customer.acct_no);
printf(" Street :%s\n",customer.street);
printf(" City :%s\n",customer.city);
printf(" Old balance :%.2f\n",customer.oldbalance);
printf(" Current payment:%.2f\n",customer.payment);
printf(" New balance :%.2f\n",customer.newbalance);
printf(" Payment date :%d/%d/%d\n\n",customer.lastpayment.month,customer.lastpayment.day,customer.lastpayment.year);
printf(" Account status :");
textcolor(128+RED);
switch(customer.acct_type)
{
case 'C':
cprintf("CURRENT\n\n");
break;
case 'O':
cprintf("OVERDUE\n\n");
break;
case 'D':
cprintf("DELINQUENT\n\n");
break;
default:
cprintf("ERROR\\n\n");
}
textcolor(WHITE);
return;
}