-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEDairy.cpp
385 lines (353 loc) · 8.8 KB
/
EDairy.cpp
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#include<bits/stdc++.h>
#include<conio.h>
#define size 40
using namespace std;
const string Dudh="Dudh";
const string Ghee="Ghee";
void SearchCustomer();
void addCustomer();
void ListOfCustomer();
void SellProduct();
void title();
void ProductBill();
void ListOfSells();
void MainScreen();
void Exit_program();
/*
ID : Vaibhav123
Pass : 123
Change it from line 45 and 46
*/
void welcome()
{
cout<<"\n\n\n\n\n\n\n\t\t\t\t#########################################";
cout<<"\n\t\t\t\t\t\t WELCOME TO\t\t";
cout<<"\n\t\t\t\t MADHAV DAIRY SYSTEM ";
cout<<"\n\t\t\t\t#########################################";
cout<<"\n\n\n\n\n Press any key to continue......\n";
getch();
system("cls");
}
void title()
{
cout<<"\n\n\n\t\t\t\t---------------------------------------------";
cout<<"\n\t\t\t\t MADHAV DAIRY SYSTEM ";
cout<<"\n\t\t\t\t---------------------------------------------\n\n\n\n";
}
void LockScreen()
{
char orignalID[20]="Vaibhav123";
char orignalPass[20]="123";
char ID[20],Pass[20];
int e=0;
do
{
system("cls");
title();
cout<<"\n\n\t\t\t\tEnter User Id: ";
cin>>ID;
cout<<"\n\n\t\t\t\tEnter Passward: ";
cin>>Pass;
if(strcmp(ID,orignalID) == 0 && strcmp(Pass,orignalPass) == 0)
{
cout<<"\n\n\t\t\t\tLogin succsessful :)\n\n\t\t\t\t<--Press Any key to continue -->";
getch();
MainScreen();
break;
}
else
{
cout<<"\n\n\t\t\t\tWrong id or passward :( Try again";
e++;
getch();
}
}while(e<=2);
if(e>2)
{
cout<<"\n\n\t\t\t\tYou have cross the limit. You can't login any more :(";
getch();
Exit_program();
}
cout<<e;
}
class dairy
{
public:
string name;
string product;
int price;
int quantity;
int total;
void get_data();
}d1;
void dairy::get_data()
{
cout<<"\n\t\t\t\tEnter custemor's name: ";
cin.ignore();
getline(cin,name);
cout<<"\n\n\t\t\t\tEnter Product which he/she want: "<<endl;
cout<<"\n\n\t\t\t\t--Dudh--"<<endl;
cout<<"\n\n\t\t\t\t--Ghee--"<<endl;
cout<<"\n\t\t\t\t-->";
cin>>product;
if(product==Dudh)
price=60;
if(product==Ghee)
price=100;
cout<<"\n\n\t\t\t\tEnter Quantity of product: ";
cin>>quantity;
total=price*quantity;
}
class customer
{
public:
string customername;
char phoneno[10];
string Address;
void getCustomerData();
}c1;
void customer::getCustomerData()
{
cout<<"\n\t\t\t\tEnter Name of customer: ";
cin.ignore();
getline(cin,customername);
int i,valid;
do{
A:
cout<<"\n\n\t\t\t\tEnter phone number of "<<customername<<": ";
cin>>phoneno;
if(strlen(phoneno)!=10)
{
cout<<"\n\n\t\t\t\tPlease enter 10 digit number\n\n";
goto A;
}
else
{
for(i=0;i<strlen(phoneno);i++)
{
if(isdigit(phoneno[i])!=0) //non-zero value if ch is an digit -- zero if ch is not a digit
{
valid=1;
}
else
{
valid=0;
break;
}
}
if(valid==0)
{
cout<<"\n\n\t\t\t\tPhone number contains Invalid charcters -- Please try again\n\n";
goto A;
}
}
}while(valid==0);
cout<<"\n\n\t\t\t\tEnter address: ";
cin.ignore();
getline(cin,Address);
}
void MainScreen()
{
int ch;
system("cls");
title();
cout<<"\n\t\t\t\t1. Add Custemor details\n";
cout<<"\n\t\t\t\t2. List Of Customers\n";
cout<<"\n\t\t\t\t3. Search Customer Record\n";
cout<<"\n\t\t\t\t4. Sell Product to Customer\n";
cout<<"\n\t\t\t\t5. List Of Sells\n";
cout<<"\n\t\t\t\t6. Exit\n";
cout<<"Enter Your choise Here: ";
cin>>ch;
switch(ch)
{
case 1:
addCustomer();
break;
case 2:
ListOfCustomer();
break;
case 3:
SearchCustomer();
break;
case 4:
SellProduct();
break;
case 5:
ListOfSells();
break;
case 6:
Exit_program();
break;
}
}
void Exit_program()
{
system("cls");
title();
cout<<"\n\n\t\t\t\tThanks for Visiting :)";
getch();
}
void ListOfSells()
{
string arr;
system("cls");
title();
cout<<"\n\n\n";
ifstream IFile("Custemor.txt");
while(getline(IFile,arr))
{
if(arr!="")
cout<<arr<<endl;
}
IFile.close();
char ch;
cout<<"\n\n\t\t\t\tWant to continue [Y/N]: ";
cin>>ch;
if(ch=='Y' || ch=='y')
MainScreen();
else if(ch=='N' || ch=='n')
Exit_program();
else
{
cout<<"-----Invalid choice-----";
getch();
Exit_program();
}
}
void SearchCustomer()
{
system("cls");
title();
Search:
char CustomerName[size];
cout<<"Enter customer customername to search: ";
cin>>CustomerName;
ifstream SEARCH("Customer Details.txt");
int flag=0;
string arr;
cout<<"\n\n";
while ( getline (SEARCH,arr) )
{
if (arr.find(CustomerName, 0) != string::npos) //arr.find(CustomerName, 0) != string::npos
{
cout<<arr<<endl;
flag=1;
}
}
char ch;
if(flag==0)
{
cout<<"\t\t\t\tRecord Not Found :(\n";
cout<<"\n\t\t\t\tSearch again [Y/N]: ";
cin>>ch;
if(ch=='Y'||ch=='y')
goto Search;
if(ch=='N' || ch=='n')
Exit_program();
}
SEARCH.close();
if(flag==1)
{
cout<<"\n\n\t\t\t\tWant to continue [Y/N]: ";
cin>>ch;
if(ch=='Y' || ch=='y')
MainScreen();
else if(ch=='N' || ch=='n')
Exit_program();
else
{
cout<<"-----Invalid choice-----";
getch();
Exit_program();
}
}
}
void SellProduct()
{
system("cls");
title();
d1.get_data();
ofstream OFile("Custemor.txt",ios::app);
OFile<<d1.name<<"\t\t\t"<<d1.product<<"\t\t\t"<<d1.price<<"\t\t\t"<<d1.quantity<<"L"<<"\t\t\t"<<d1.total<<"\n";
OFile.close();
cout<<"\n\n\t\t\t\tBill Created Succsessfully.";
char ch;
cout<<"\n\n\t\t\t\tWant to continue [Y/N]: ";
cin>>ch;
if(ch=='Y' || ch=='y')
MainScreen();
else if(ch=='N' || ch=='n')
Exit_program();
else
{
cout<<"-----Invalid choice-----";
getch();
Exit_program();
}
OFile.open("Bill.csv");
OFile<<"\n"",,""Madhav"",""Dairy"<<endl<<"Name:"<<","<<d1.name<<",,,"<<"Date: "",""=TODAY()"<<endl<<",""Description"<<",,""Quantity"","<<"Price"","<<"Total"<<endl<<","<<d1.product<<",,"<<d1.quantity<<","<<d1.price<<","<<d1.total;
// OFile<<endl<<d1.name<<"\t\t\t"<<d1.product<<"\t\t\t"<<d1.price<<"\t\t\t"<<d1.quantity<<"L"<<"\t\t\t"<<d1.total;
OFile.close();
}
void ListOfCustomer()
{
system("cls");
title();
cout<<"\n\n\n";
string arr;
ifstream IFile("Customer Details.txt");
while(getline(IFile,arr))
{
if(strlen((char *) &arr)>0)
cout<<arr<<endl;
}
IFile.close();
char ch;
cout<<"\n\n\t\t\t\tWant to continue [Y/N]: ";
cin>>ch;
if(ch=='Y' || ch=='y')
MainScreen();
else if(ch=='N' || ch=='n')
Exit_program();
else
{
cout<<"-----Invalid choice-----";
getch();
Exit_program();
}
}
void addCustomer()
{
system("cls");
title();
char ans;
Add:
c1.getCustomerData();
ofstream Customerfile("Customer Details.txt",ios::app);
Customerfile<<endl<<setw(10)<<"Name: "<<left<<setw(20)<<c1.customername<<setw(10)<<"Phone No. +91-"<<left<<setw(20)<<c1.phoneno<<setw(8)<<"Address: "<<left<<c1.Address;
cout<<"\n\n\t\t\t\tNew Customer added succsessfully.\n\n";
cout<<"\t\t\t\tYou want to add more customers? [Y/N]: ";
cin>>ans;
if(ans=='Y'||ans=='y')
goto Add;
else if(ans=='N'||ans=='n')
{
cout<<"\n\n\t\t\t\tOkay Thank You :)";
Customerfile.close();
getch();
MainScreen();
}
else
{
cout<<"-----Invalid choice-----";
getch();
Exit_program();
}
}
int main()
{
welcome();
LockScreen();
return 0;
}