-
Notifications
You must be signed in to change notification settings - Fork 0
/
CBS1.CPP
1327 lines (1291 loc) · 30.2 KB
/
CBS1.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Computerised Billing System
//----------------------------------------------------------------------------
// Header Files Included
//----------------------------------------------------------------------------
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
#include<graphics.h>
#include<conio.h>
//Function prototype declaration
void listallm();
void listallp();
void products_enter();
void members_enter();
void readp();
void readm();
void billing();
void sales();
void modifyp();
void modifym();
void instructions();
//----------------------------------------------------------------------------
// Function for GRAPHICS slide (cover page)
//----------------------------------------------------------------------------
int gmode,gdriver,r;
//----------------------------------------------------------------------------
// Structure for the products' records
//----------------------------------------------------------------------------
struct products_record
{
float rate;
int stock;
int no;
char name[20];
}; //end of structure
//Global variable
products_record ob1,ob2; //declaring objects of the structure
fstream pro1,pro2; //declaring a file stream
//----------------------------------------------------------------------------
// Structure for members' records
//----------------------------------------------------------------------------
struct members_record
{
int no;
char name[20];
char add[50];
long int tel;
long int card;
float amt ;
}; //end of structure
members_record m1,m2; //creating objects
fstream mem1,mem2; //declaring streams;
//----------------------------------------------------------------------------
//structure for store opertaions
//----------------------------------------------------------------------------
struct tables
{
int no;
int qty;
char name[20];
float rate;
float total;
};
tables n1,n2;
int i=0;
float discount=0.0;
//Welcome screen of computerized billing system
void welcome()
{
gdriver=DETECT; //request auto detection
initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); //initialising graph
setbkcolor(7);
setcolor(15);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,5);
settextstyle(7,HORIZ_DIR,7);
moveto(60,100);
outtext("COMPUTERISED");
moveto(160,210);
outtext("BILLING ");
moveto(160,320);
outtext("SYSTEM");
delay(700);
setcolor(7);
int i=0;
while(i<=2*getmaxx()-460)
{
line(0,i,i,0);
i++;
delay(5);
}
setcolor(RED);
for (r=150;r<230;r+=15)
{ circle (315,239,r);
delay(25);
}
settextstyle(8,HORIZ_DIR,1);
setcolor(GREEN);
delay(5);
moveto(245,160);
outtext("Submitted By :");
moveto(185,180);
outtext("SAKSHI & NITIKA");
moveto(240,250);
setcolor(RED);
outtext("Guided By : ");
moveto(240,270);
outtext("RUCHIKA VOHRA");
moveto(10,450);
cin.get();
closegraph(); //closing graphics screen
}
//----------------------------------------------------------------------------
// Function for screen setting
//----------------------------------------------------------------------------
void border()
{
clrscr();
textcolor(WHITE);
for (int i=2;i<80;i++) //drawing horizontal lines
{
gotoxy(i,3);
cprintf("-");
gotoxy(i,23);
cprintf("-");
}
for (i=4;i<23;i++) //drawing vertical lines
{
gotoxy(2,i);
cprintf("|");
gotoxy(79,i);
cprintf("|");
}
}
//----------------------------------------------------------------------------
// Main program
//----------------------------------------------------------------------------
void main()
{
clrscr();
void highvideo(); //setting the intensity of text charaters to high
welcome(); // calling the function for making the cover page
remove("sale.dat");
int n;
char l='y';
do
{
textcolor(LIGHTGREEN);
border(); //making the border of the screen
textcolor(LIGHTGREEN);
gotoxy(30,5);
cprintf("MAIN MENU");
for (int z=29;z<=40;z++)
{
gotoxy(z,6);
cprintf("-");
}
gotoxy(20,7);
cprintf("1:ADD NEW PRODUCTS");
gotoxy(20,8);
cprintf("2:ADD NEW MEMBERS");
gotoxy(20,9);
cprintf("3:VIEW AN EXISTING PRODUCT RECORD ");
gotoxy(20,10);
cprintf("4:VIEW AN EXISTING MEMBER'S RECORD ");
gotoxy(20,11);
cprintf("5:BILLING ");
gotoxy(20,12);
cprintf("6:TODAY'S SALES ");
gotoxy(20,13);
cprintf("7:MODIFY PRODUCT RECORD ");
gotoxy(20,14);
cprintf("8:MODIFY MEMBER'S RECORD ");
gotoxy(20,15);
cprintf("9:INSTRUCTIONS ");
gotoxy(20,16);
cprintf("10:LIST ALL PRODUCTS ");
gotoxy(20,17);
cprintf("11:LIST ALL MEMBERS ");
gotoxy(20,18);
cprintf("0:EXIT");
gotoxy(20,20);
cprintf("Enter your choice:");
cin>>n;
switch(n)
{
case 1: products_enter();
break;
case 2: members_enter();
break;
case 3: readp();
break;
case 4: readm();
break;
case 5: billing();
break;
case 6: sales();
break;
case 7: modifyp();
break;
case 8: modifym();
break;
case 9: instructions();
break;
case 10: listallp();break;
case 11: listallm();break;
case 0: l='n';
}
} while (l=='y');
clrscr();
}
//----------------------------------------------------------------------------
// Function for getting the products' records
//----------------------------------------------------------------------------
void products_enter()
{
int q=0;
char l='y';
pro1.open("products.dat",ios::in); //opening file in stream
pro1.seekg(0,ios::end); //determining end of file
q=pro1.tellg()/sizeof(products_record); //finding size of file
q+=1255;
pro1.close();
pro1.open("products.dat" ,ios::app);
do
{
textcolor(LIGHTBLUE);
clrscr();
border();
textcolor(LIGHTBLUE);
gotoxy(28,2);
cprintf("ENTERING PRODUCT RECORDS ");
gotoxy(15,6);
cprintf("Name :");
gets(ob1.name);
if (!ob1.name[0]) //to undo entering if name is not entered
return;
gotoxy(15,7);
cprintf("Stock :");
cin>>ob1.stock;
gotoxy(15,8);
cprintf("Rate (Rs.):");
cin>>ob1.rate;
ob1.no = q++;
gotoxy(15,9);
cprintf("Number :");
cout<<ob1.no;
pro1.write((char*)&ob1,sizeof(products_record));
gotoxy(10,15);
cprintf("Do you want to enter more (Y/N) ");
l=getch();
} while (tolower(l)=='y');
pro1.close();
}
//--------------------------------------------------------------
//Function for searching in the file
//--------------------------------------------------------------
products_record products_search(int no)
{
fstream pro1; //declaring stream
pro1.open("products.dat" ,ios::in||ios::nocreate); //opening the file
while(pro1)
{
pro1.read((char*)&ob1,sizeof(products_record));
//reading from file
if (ob1.no==no)
return ob1; //returning the searched record
}
pro1.close();
ob1.no=0;
return ob1;
}
//----------------------------------------------------------------------------
//Function for modifying records
//----------------------------------------------------------------------------
void products_modify(int no)
{
ob2.no=0;
pro1.open("products.dat",ios::in); //opening the file
pro2.open("product1.dat",ios::app); //opening another file
pro1.seekg(0,ios::beg); //locating beggining of file
pro1.read((char*)&ob1,sizeof(products_record));
//reading from file
while (!pro1.eof() ) //testing for end of file
{
if (ob1.no!=no )
pro2.write((char*)&ob1,sizeof(products_record));
//writing in file
else
ob2=ob1;
pro1.read((char*)&ob1,sizeof(products_record));
//reading from file
}
//displaying previous reccords and entering new records
if (ob2.no)
{
gotoxy(13,7);
cprintf("CURRENT RECORDS ARE ");
gotoxy(15,8);
cprintf("NAME :");
puts(ob2.name);
gotoxy(15,9);
cprintf("RATE :(Rs.)");
cout<<ob2.rate;
gotoxy(15,10);
cprintf("STOCK :");
cprintf("%d",ob2.stock);
gotoxy(13,12);
cprintf("ENTER NEW PRODUCT RECORDS");
gotoxy(15,13);
cprintf("NAME :");
ob1.no=ob2.no;
gets(ob1.name);
if (!isalnum(ob1.name[0])) //testing for an entry
strcpy(ob1.name,ob2.name); //retaining previous name when no entry
gotoxy(15,14);
cprintf("RATE :(Rs.)");
cin>>ob1.rate;
if (!ob1.rate)
ob1.rate=ob2.rate;
gotoxy(15,15);
cprintf("STOCK :");
cin>>ob1.stock;
if (!ob1.stock)
ob1.stock=ob2.stock;
pro2.write((char*)&ob1,sizeof(products_record)); //writing in file
}
else
{
gotoxy(20,9);
cprintf("NO ENTRY\a");
}
pro1.close(); //closing file
pro2.close(); //closing file
remove ("products.dat"); //deleting file
rename ("product1.dat","products.dat"); //renaming file
}
//----------------------------------------------------------------------------
// Function to enter members' records
//----------------------------------------------------------------------------
void members_enter()
{
int m;
char l='y';
//determining number of enteries in the file
mem1.open("members.dat",ios::in);
mem1.seekg(0,ios::end);
m=mem1.tellg()/sizeof(members_record);
mem1.close();
m+=10;
clrscr();
mem1.open("members.dat",ios::app); //opening file
do
{
textcolor(LIGHTCYAN);
clrscr();
border();
textcolor(LIGHTCYAN);
gotoxy(28,2);
cprintf("ENTERING MEMBER RECORDS ");
gotoxy(15,6);
cprintf("Name :");
gets(m1.name);
if (!m1.name[0])
return; //undo entering when no name is entered
gotoxy(15,7);
cprintf("Card number :");
cin>>m1.card;
gotoxy(15,8);
cprintf("Address :");
gets(m1.add);
gotoxy(15,9);
cprintf("Tel. :");
cin>>m1.tel;
gotoxy(15,10);
cprintf("Amount Deposited (Rs.):");
cin>>m1.amt;
if (m1.amt<=100)
{
gotoxy(15,11);
cprintf("Amount less\a");
gotoxy(15,12);
cprintf("Try Again");
goto end;
}
m1.no = m++;
gotoxy(15,11);
cprintf("Membership number :");
cout<<m1.no;
mem1.write((char*)&m1,sizeof(members_record)); //writing in file
end:
gotoxy(10,15);
cprintf("Do you want to enter more (Y/N) ");
l=getch();
} while (tolower(l)=='y');
mem1.close();
}
//----------------------------------------------------------------------------
// Function for searching in the file
//----------------------------------------------------------------------------
members_record members_search(int no)
{
fstream mem2; //declaring stream
mem2.open("members.dat",ios::in); //opening file
while (mem2)
{
mem2.read((char*)&m1,sizeof(members_record)); //reading from file
if (m1.no==no)
return m1; //returning the searched record
}
mem2.close();
m1.no=0;
return m1;
}
//----------------------------------------------------------------------------
// Function to modify members' records
//----------------------------------------------------------------------------
void members_modify(int no)
{
m2.no=0;
mem1.open("members.dat",ios::in); //opening a file
mem2.open("member1.dat",ios::app); //opening another file
mem1.seekg(0,ios::beg);
mem1.read((char*)&m1,sizeof(members_record));
while (!mem1.eof()) //testing for end of file
{
if (m1.no!=no)
mem2.write((char*)&m1,sizeof(members_record));
else
m2=m1;
mem1.read((char*)&m1,sizeof(members_record));
}
//displaying current records and entering new records
if (m2.no)
{
gotoxy(13,7);
cprintf("CURRENT RECORDS ARE ");
gotoxy(15,8);
cprintf("NAME :");
puts(m2.name);
gotoxy(15,9);
cprintf("CARD NUMBER :");
cout<<m2.card;
gotoxy(15,10);
cprintf("ADDRESS :");
puts(m2.add);
gotoxy(15,11);
cprintf("TELEPHONE :");
cout<<m2.tel;
gotoxy(15,12);
cprintf("AMOUNT :(Rs.)");
cout<<m2.amt;
gotoxy(13,14);
cprintf("ENTER NEW RECORDS");
gotoxy(15,15);
cprintf("NAME :");
m1.no=m2.no;
gets(m1.name);
if (!m1.name[0])
strcpy(m1.name,m2.name);
gotoxy(15,16);
cprintf("ADDRESS :");
gets(m1.add);
if (!m1.add[0])
strcpy(m1.add,m2.add);
gotoxy(15,17);
cprintf("CARD NUMBER :");
cin>>m1.card;
if (!m1.card)
m1.card=m2.card;
gotoxy(15,18);
cprintf("TELEPHONE :");
cin>>m1.tel;
if (!m1.tel)
m1.tel=m2.tel;
gotoxy(15,19);
cprintf("AMOUNT ADDED :(Rs.)");
cin>>m1.amt;
m1.amt+=m2.amt;
mem2.write((char*)&m1,sizeof(members_record));
}
else
{
gotoxy(20,10);
cprintf("NO ENTRY\a");
}
mem1.close(); //closing file
mem2.close(); //closing file
remove ("members.dat"); //removing file
rename ("member1.dat","members.dat"); //renaming file
}
//----------------------------------------------------------------------------
// Function for reading product records
//----------------------------------------------------------------------------
void readp()
{
char l='y';
do
{
textcolor(LIGHTBLUE);
clrscr();
border();
textcolor(LIGHTBLUE);
gotoxy(28,2);
cprintf("VIEWING PRODUCT RECORDS ");
gotoxy(15,6);
cprintf("Enter product number:");
int no;
cin>>no;
ob1=products_search(no); //calling for search in the file
// displaying records
if (ob1.no)
{
gotoxy(18,9);
cprintf("The record is");
gotoxy(20,10);
cprintf(" Number :");
cout<<ob1.no;
gotoxy(20,11);
cprintf(" Stock :");
cout<<ob1.stock;
gotoxy(20,12);
cprintf(" Name : ");
puts(ob1.name);
gotoxy(20,13);
cprintf(" Rate :(Rs.)");
cout<<ob1.rate;
}
else
{
gotoxy(20,10);
cprintf("NO ENTRY \a");
}
gotoxy(15,16);
cprintf("Any more records desired (Y/N)");
l=getch();
} while(tolower(l)=='y');
}
//----------------------------------------------------------------------------
// Function to pruduce screen for 'modify product records'
//----------------------------------------------------------------------------
void modifyp()
{
char l='y';
do
{
textcolor(LIGHTBLUE);
clrscr();
border();
textcolor(LIGHTBLUE);
gotoxy(25,2);
cprintf("MODIFYING A PRODUCT RECORD");
gotoxy(15,5);
cprintf("Enter the product number:");
int no;
cin>>no;
products_modify(no); //calling for modifications
gotoxy(13,20);
cprintf("Any more modifications desired(Y/N)");
l=getch();
} while (tolower(l)=='y');
}
//----------------------------------------------------------------------------
// Function to read members' records
//----------------------------------------------------------------------------
void readm()
{
char l='y';
do
{
textcolor(LIGHTCYAN);
clrscr();
border();
textcolor(LIGHTCYAN);
gotoxy(25,2);
cprintf("VIEWING A MEMBER'S RECORD ");
gotoxy(15,6);
cprintf("Enter membership number:");
int no;
cin>>no;
m1=members_search(no); //calling for search
//displaying records
if (m1.no)
{
gotoxy(18,9);
cprintf("The record is");
gotoxy(20,10);
cprintf("Number :");
cout<<m1.no;
gotoxy(20,11);
cprintf("Name :");
puts(m1.name);
gotoxy(20,12);
cprintf("Card number :");
cout<<m1.card;
gotoxy(20,13);
cprintf("Address :");
puts(m1.add);
gotoxy(20,14);
cprintf("Telephone :");
cout<<m1.tel;
gotoxy(20,15);
cout<<"Amount :(Rs.)"<<m1.amt;
}
else
{
gotoxy(17,12);
cprintf("NO ENTRY\a ");
}
gotoxy(15,18);
cprintf("Any more records desired (Y/N)");
l=getch();
} while(tolower(l)=='y');
}
//----------------------------------------------------------------------------
// Function to display screen for 'modify members' records
//----------------------------------------------------------------------------
void modifym()
{
char l='y';
do
{
textcolor(LIGHTCYAN);
clrscr();
border();
gotoxy(25,2);
cprintf("MODIFYING MEMBER'S RECORDS ");
gotoxy(15,5);
cprintf("Enter the membership number:");
int no;
cin>>no;
members_modify(no); //calling for modifications
gotoxy(13,22);
cprintf("Any more modifications desired(Y/N)");
l=getch();
} while(tolower(l)=='y');
}
//----------------------------------------------------------------------------
// Function for creating 'sale.dat'
//----------------------------------------------------------------------------
// Function for billing
//----------------------------------------------------------------------------
void billing()
{
textcolor(LIGHTRED);
clrscr();
border();
textcolor(LIGHTRED);
fstream b1; //declaring stream
b1.open("sale.dat",ios::app); //opening file
gotoxy(30,2);
cprintf("BILLING ");
gotoxy(15,7);
cprintf("Are you a member(Y/N):");
float less=1.0;
char m;
int no;
long card;
m=getche();
if (tolower(m)=='y')
{
gotoxy(18,9);
cprintf("Enter membership number:");
cin>>no;
gotoxy(18,10);
cprintf("Enter card number:");
cin>>card;
m1=members_search(no);
if (card!=m1.card) //checking for authenticity of the details
{
gotoxy(20,12);
cprintf("Incorrect \a");
getch();
return; //undoing billing process
}
else
if (m1.amt>100)
{
less=0.95;
m1.amt-=5;
}
else
{
gotoxy(20,12);
cprintf("Amount Less\a");
gotoxy(15,15);
cprintf("Continue with normal billing(Y/N)");
m=getch();
if (tolower(m)=='n')
return;
}
//decreasing the members' amount if the details are correct
fstream t3,t4;
t3.open("members.dat",ios::in);
t4.open("member1.dat",ios::app);
t3.seekg(0,ios::beg);
t3.read((char*)&m2,sizeof(members_record));
while (!t3.eof())
{
if (m2.no!=m1.no)
t4.write((char*)&m2,sizeof(members_record));
else
t4.write((char*)&m1,sizeof(members_record));
t3.read((char*)&m2,sizeof(members_record));
}
t3.close();
t4.close();
remove("members.dat");
rename("member1.dat","members.dat");
}
clrscr();
float total=0.0;
textcolor(LIGHTGREEN);
gotoxy(60,1);
cprintf("PRESS 0 :Exit Billing");
textcolor(LIGHTRED);
gotoxy(30,1);
cprintf("BILLING");
i=0;
void table1(); //function declaration for making table
beg: //giving line a name for further reference
table1(); //calling function for making table
gotoxy(4,6+i);
cin>>n1.no;
ob1=products_search(n1.no); //searching for product record
gotoxy(56,6+i);
float output1(products_record); //declaring a nested function
if (n1.no>0)
{
if(ob1.no>0)
{
cin>>n1.qty;
strcpy(n1.name,ob1.name);
n1.rate=ob1.rate;
n1.total=output1(ob1);
total+=n1.total;
fstream t3,t4;
t3.open("sale.dat",ios::in);
t4.open("sale1.dat",ios::app);
t3.seekg(0,ios::beg);
int qty=n1.qty;
n1.qty=n1.total/n1.rate;
char test='y';
t3.read((char*)&n2,sizeof(tables));
while (!t3.eof())
{
if (n1.no==n2.no)
{
n2.qty+=n1.qty;
n2.total+=n1.total;
test='n';
}
t4.write((char*)&n2,sizeof(tables));
t3.read((char*)&n2,sizeof(tables));
}
if (test=='y')
{
t4.seekg(0,ios::end);
t4.write((char*)&n1,sizeof(tables));
}
t3.close();
t4.close();
remove("sale.dat");
rename("sale1.dat","sale.dat");
n1.qty=qty;
if (n1.total)
{
//reducing the products' stock
fstream temp3,temp4;
temp3.open("products.dat",ios::in);
temp4.open("product1.dat",ios::app);
temp3.seekg(0,ios::beg);
temp3.read((char*)&ob1,sizeof(products_record));
while (!temp3.eof())
{
if (ob1.no==n1.no)
ob1.stock-=n1.qty;
temp4.write((char*)&ob1,sizeof(products_record));
temp3.read((char*)&ob1,sizeof(products_record));
}
temp3.close();
temp4.close();
remove("products.dat");
rename("product1.dat","products.dat");
}
i++;
goto beg;
}
else
if (ob1.no==0)
{
gotoxy(10,6+i);
cprintf("No entry\a");
i++;
goto beg;
}
}
else
if (n1.no==0)
{
textcolor(WHITE);
for (int j=0;j<81;j++) //ending table
{
gotoxy(j,6+i);
cprintf("-");
}
}
textcolor(LIGHTRED);
gotoxy(5,9+i);
cprintf("Number of items = ");
cout<<i;
gotoxy(5,10+i);
cprintf("Grand total = Rs.");
cout<<total;
//giving discount
if (less!=1)
{
discount+=0.05*total;
gotoxy(5,12+i);
cprintf("Discount = Rs.");
printf("%.2f",0.05*total);
gotoxy(5,13+i);
cprintf("Net total = Rs.");
printf("%.2f",less*total);
}
b1.close();
getch();
}
//----------------------------------------------------------------------------
// nested function of 'billing'
//----------------------------------------------------------------------------
float output1(products_record ob1)
{
if (ob1.no==0) //if no entry then return to billing
return 0;
float stotal;
stotal=ob1.rate*n1.qty; //determining the cost of the particular item
//putting the values on the screen
gotoxy(4,6+i);
cout<<ob1.no;
gotoxy(10,6+i);
puts(ob1.name);
gotoxy(38,6+i);
cout<<ob1.rate;
gotoxy(43,6+i);
cout<<" ";
gotoxy(56,6+i);
if (n1.qty>ob1.stock) //checking for the item being in stock
{
gotoxy(50,6+i);
cprintf("Out of stock\a");
return 0;
}
cout<<n1.qty;
gotoxy(68,6+i);
cout<<stotal;
gotoxy(74,6+i);
cout<<" ";
return stotal;
}
//----------------------------------------------------------------------------
// Function for making table
//----------------------------------------------------------------------------
void table1()
{
textcolor(WHITE);
//drawing vertical lines
for (int a=1;a<=80;a++)
{
gotoxy(a,2);
cprintf("_");
gotoxy(a,5);
cprintf("-");
}
//drawing horizontal lines(always)
for (a=3;a<=5;a++)
{
gotoxy(1,a);
cprintf("|");
gotoxy(9,a);
cprintf("|");
gotoxy(31,a);
cprintf("|");
gotoxy(49,a);
cprintf("|");
gotoxy(64,a);
cprintf("|");
gotoxy(80,a);
cprintf("|");
}
/* drawing horizontal lines
(depending upon the s.no. of item in purchase list)*/
gotoxy(1,6+i);
cprintf("|");
gotoxy(9,6+i);
cprintf("|");
gotoxy(31,6+i);
cprintf("|");
gotoxy(49,6+i);
cprintf("|");
gotoxy(64,6+i);
cprintf("|");
gotoxy(80,6+i);
cprintf("|");
textcolor(LIGHTRED);
//giving column titles
gotoxy(2,3);
cprintf("Product");
gotoxy(14,3);
cprintf("Product name ");
gotoxy(35,3);
cprintf("Rate (Rs.)");
gotoxy(53,3);
cprintf("Quantity");
gotoxy(67,3);
cprintf("Total (Rs.)");
gotoxy(2,4);
cprintf("number");
gotoxy(53,4);
cprintf("(Kgs/pcs)");
}
//----------------------------------------------------------------------------
// Function for viewing the day's sale
//----------------------------------------------------------------------------
void sales()
{
textcolor(LIGHTRED);
clrscr();
textcolor(LIGHTRED);
gotoxy(28,1);
cprintf("TODAY'S SALES");
float sales=0.0;
fstream sal1;
sal1.open("sale.dat",ios::in);
i=0;
sal1.read((char*)&n1,sizeof(n1));
while(!sal1.eof() && n2.no!=n1.no)
{
table1();
gotoxy(4,6+i);
cout<<n1.no;
gotoxy(10,6+i);
puts(n1.name);
gotoxy(38,6+i);
cout<<n1.rate;
gotoxy(43,6+i);
cout<<" ";
gotoxy(56,6+i);
cout<<n1.qty;
gotoxy(68,6+i);
cout<<n1.total;
sales+=n1.total;
gotoxy(74,6+i);
cout<<" ";
i++;
n2.no=n1.no;
sal1.read((char*)&n1,sizeof(n1));
}
textcolor(WHITE);
gotoxy(1,6+i);
for(int n=1;n<=80;n++)
cprintf("-");
textcolor(LIGHTRED);
gotoxy(5,8+i);
cprintf("Grand total = Rs.");
cout<<sales;
gotoxy(5,10+i);
cprintf("Discount = Rs.");
cout<<discount;
gotoxy(5,11+i);
cprintf("Net total = Rs.");
cout<<(sales-discount);
getch();