Repository navigation
Expand file tree
/
Copy pathBiling_System.cpp
More file actions
256 lines (235 loc) · 6.09 KB
/
Copy pathBiling_System.cpp
File metadata and controls
256 lines (235 loc) · 6.09 KB
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
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdlib.h>
//#include<windows.h>
using namespace std;
class hard;
class tools{
friend class hard;
private:
char id[5];
char tname[15];
char cost[10];
public:
char quantity[5];
char* getid(){
return id;
}
void getinput()
{
cout<<"\nEnter the ID_no : ";
cin>>id;
cout<<"\nEnter the ITEM NAME: ";
cin>>tname;
cout<<"\nEnter ITEM COST : ";
cin>>cost;
}
void disptoolso()
{
cout<<"\t\t"<<id<<" "<<tname<<" "<<quantity<<" "<<cost<<"\n\n\n";
}
void disptools(){
cout<<"\t\t"<<id<<" "<<tname<<"\t\t"<<cost<<"\n\n";
}
};
class hard{
public:
void del();
void del(char);
void update();
void viewall();
void inputinfile();
void placeorder();
};
void hard::update(){
fstream file("t.txt",ios::in|ios::out|ios::app);
tools t;
cout<<"\nSpecify tool ID_no to update : ";
char i[5];
cin>>i;
ofstream temp;
temp.open("temp.txt");
int flag=0;
file.seekg(0,ios::beg);
temp.seekp(0,ios::beg);
while(file.read((char*)&t,sizeof(t)))
{
if(strcmp(t.id,i)!=0)//if not same
{
temp.write((char*)&t,sizeof(t));
}
else
flag=1;//if same deleted
}
if(flag==0)
{
cout<<"\nTool ID"<<" "<<i<<" not present";
}
else{
tools b;
b.getinput();
temp.write((char*)&b,sizeof(b));
cout<<"Record Updated";
}
file.clear();
file.close();
temp.close();
remove("t.txt");
rename("temp.txt","t.txt");
}
void hard::del()
{
fstream file("t.txt",ios::in|ios::out|ios::app);
tools t;
cout<<"\nSpecify tool ID_no to delete : ";
char i[5];
cin>>i;
ofstream temp;
temp.open("temp.txt");
int flag=0;
file.seekg(0,ios::beg);
temp.seekp(0,ios::beg);
while(file.read((char*)&t,sizeof(t)))
{
if(strcmp(t.id,i)!=0)//if not same
{
temp.write((char*)&t,sizeof(t));
}
else
flag=1;//if same deleted
}
if(flag==0)
{
cout<<"\nTool ID"<<" "<<i<<" not present";
}
else
cout<<"Record Deleted";
file.clear();
file.close();
temp.close();
remove("t.txt");
rename("temp.txt","t.txt");
}
void hard::placeorder(){
char name[20];
cout<<"\nEnter your name : ";
cin>>name;
strcat(name,".txt");
fstream file("t.txt",ios::in |ios::out|ios::app);
file.seekg(0,ios::beg);
cout<<"\nEnter the item_ID to buy the item\n";
cout<<"Enter -1 to end the item list";
fstream newfile(name,ios::out |ios::in | ios::trunc );
int sum=0,price=0;
if(newfile.is_open()){
while(true){
xyz:cout<<"\nEnter another item_ID : ";
char it[5];
cin>>it;
char mi[3]={'-','1'};
if(!strcmp(it,mi)) {goto abc;}
tools t;
file.seekg(0,ios::beg);
while(file.read((char*)&t,sizeof(t))){
if(!strcmp(t.getid(),it)){
//cout<<"got";
cout<<"Enter quantity : ";
cin>>t.quantity;
price=atoi(t.quantity)*atoi(t.cost);
sum+=price;
cout<<price;
newfile.write((char*)&t,sizeof(t));goto xyz;
}
}
cout<<"\nNo such item left in the store";
file.clear();
file.seekg(0,ios::beg);goto xyz;
newfile.clear();
}
abc:
newfile.clear();
newfile.seekg(0,ios::beg);
cout<<"\nYou ordered :\n ";
tools t1;
while(newfile.read((char*)&t1,sizeof(t1))){
t1.disptoolso();cout<<"\n";
}
cout<<"\nTotal Price is "<<sum;
}
else
cout<<"\nFailed opening the file for ORDERING";
}
void hard::viewall()
{
fstream file("t.txt",ios::in);
file.seekg(0,ios::beg);
tools t;
while(file.read((char*)&t,sizeof(t)))
{
t.disptools();
}
file.clear();
file.close();
}
void hard::inputinfile()
{
ifstream file("t.txt");
ofstream file1("t.txt",ios::app);
tools t;
t.getinput();
file.seekg(0,ios::beg);
file1.seekp(0,ios::end);
tools r;
int flag=0;
while(file.read((char*)&r,sizeof(r))){
if(strcmp(t.getid(),r.getid())==0){
cout<<"\nItem ID already exist !!";
flag=1;
break;
}
}
if(flag==0){
file1.seekp(0,ios::end);
file1.write((char*)&t,sizeof(t));
t.disptools();
}
file.seekg(0,ios::beg);
file.clear();
file.close();
}
int main(){
cout<<"********************************BILLING SYSTEM******************************";
system("color 4d");
hard obj;
while(true){
cout<<"\n\nEnter the choice : \n";
int k;
cout<<"1. VIEW All Items : \n";
cout<<"2. INPUT an Item : \n";
cout<<"3. UPDATE an Item : \n";
cout<<"4. REMOVE an Item : \n";
cout<<"5. PLACE an Order: \n";
cout<<"6. EXIT\n";
cin>>k;
if(k==1){
cout<<"\t\tID Item_Name Price\n ";
obj.viewall();
cout<<"\n***************************************************************************";
}
if(k==2){obj.inputinfile();
cout<<"\n***************************************************************************";
}
if(k==3){obj.update();
cout<<"\n***************************************************************************";
}
if(k==4){obj.del();
cout<<"\n***************************************************************************";
}
if(k==5){obj.placeorder();
cout<<"\n***************************************************************************";
}
if(k==6){exit(1);}
}
return 0;
}