This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Supermarket_Database_Management.CPP
153 lines (134 loc) · 2.95 KB
/
Supermarket_Database_Management.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
#include <conio.h>
#include <fstream.h>
#include <ctype.h>
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <stdlib.h>
class Billing
{
public: //All public for Program efficiency
float price;
unsigned long int id;
char name[20];
Billing()
{
id=0;
price=0;
strcpy(name,"NOT FOUND");
}
void input() //Input into OBJ
{
cout<<"\n\t\t Input ";
cout<<"\n\t\t=========\n";
cout<<"ID:"; cin>>id;
cout<<"Name:"; gets(name);
cout<<"Price:"; cin>>price;
}
void output() //Output from OBJ
{
cout<<"\n\t\t Output ";
cout<<"\n\t\t=========\n";
cout<<"ID:"<<id<<"\n";
cout<<"\nName: ";
puts(name);
cout<<"Price: Rs "<<price;
}
};
void Borders() //To draw borders
{
cleardevice();
setfillstyle(SOLID_FILL,RED);
bar(0,0,getmaxx(),10);
setfillstyle(SOLID_FILL,BLUE);
bar(0,getmaxy()-10,getmaxx(),getmaxy());
}
void DataIN() //Input DataBase
{
ofstream item("DataBase.dat",ios::binary|ios::app);
Billing obj;
obj.input();
item.write((char*)&obj,sizeof(obj));
item.close();
}
Billing DataCHECK(unsigned long int id) //Check for existing data
{
unsigned long int temp_id;
ifstream item("DataBase.dat",ios::binary);
Billing obj,obj1; //Obj1 is 'NULL OBJECT'
item.seekg(0,ios::beg);
for(int i=0;i>=0;i++)
{ item.read((char*)&obj,sizeof(obj));
temp_id=obj.id;
if(temp_id==id)
{
cout<<"\nMatched ID: "<<temp_id;
item.close();
return obj;
}
}
item.close();
return obj1;
}
void bill()
{
float sum=0,price[20];
char ch='y',name[20][20];
Billing obj;
unsigned long int temp_id;
for(int i=0;ch=='y';i++)
{ Borders();
clrscr();
cout<<"\n\t\t Billing";
cout<<"\n\t\t=========";
cout<<"\nEnter ID: ";
cin>>temp_id;
obj=DataCHECK(temp_id);
sum+=obj.price;
price[i]=obj.price;
strcpy(name[i],obj.name);
cout<<"\n\n More Products ? (Y/N):";
cin>>ch;
tolower(ch);
}
clrscr();
cout<<"\n\t\t Summary";
cout<<"\n\t\t=========\n";
for(int j=0;j<i;j++)
{ Borders();
cout<<"\t"<<name[i]<<"\t\tRs."<<price[i]<<endl;
}
cout<<"\n\n\nTotal Bill: Rs."<<sum;
cout<<"\n\nPress Any key to exit....";
getch();
}
void main() //Contains menu
{
int choice;unsigned long int a;Billing obj;
X:clrscr();
int gd= DETECT, gm, err,i;
initgraph(&gd, &gm, "C:\\TC\\BGI");
Borders();
cout<<"\n\t\t\t SuperMarket Database Management ";
cout<<"\n\t\t\t===================================\n";
cout<<"\t1.Enter Data into database (*)"<<endl;
cout<<"\t2.Verify with Database (*)"<<endl;
cout<<"\t3.Billing"<<endl;
cout<<"\t4.Exit (*)"<<endl<<"\n\n\tEnter Any Choice: ";
//Borders();
cin>>choice;
switch(choice)
{
case 1: DataIN();break;
case 2: cout<<"\n\tEnter Item Id to be verified:";
cin>>a;obj=DataCHECK(a);
obj.output();break;
case 3: bill();break;
case 4: exit(0);
default:cout<<"\tInvalid Input....";getch();goto X;
}
getch();
goto X;
}