-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGuest.cpp
More file actions
361 lines (280 loc) · 7.58 KB
/
Guest.cpp
File metadata and controls
361 lines (280 loc) · 7.58 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
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
#include "Guest.h"
#include "Room.h"
#include <bits/stdc++.h>
#include <fstream>
#include "Date.h"
using namespace std;
int Guest::id1=1;
Guest::Guest()
{
}
Guest::Guest(int a,int b,int c){
room_no=a;
roomType=b;
roomRate=c;
}
void Guest::inputData(){
fstream file;
string na;
char nm[30];
char ph[14];
char ct[30];
file.open("record.txt",ios::out|ios::app);
if(!file)
{
cout<<"Error in creating file.."<<endl;
}
cout<<"\nFile created successfully."<<endl;
while(1){
cout <<"Enter your Check In date(DD-MM-YYYY):\n";
Date d1;
setCheckInDate(d1.d,d1.m,d1.y);
cout <<"Enter your Check Out date:\n";
Date d2;
setCheckOutDate(d2.d,d2.m,d2.y);
int diff=d1.getDifference(d1,d2);
difference=diff;
if(diff>0){
setPrice(diff);
break;
}
else if(diff==0)
cout<<"\nCheck In and Check Out Date can't be same\n";
else cout<<"\nCheck Out can't be before than Check In\n";
}
cout <<"Enter Name:\n";
cin >> nm;
setName(nm);
cout <<"Enter your 10 digit mobile no. :\n";
cin >> ph;
setPhno(ph);
cout <<"Enter City:\n";
cin >> ct;
setCity(ct);
int i;
//Entering the record in the file
file<<name<<" "<<ph_no<<" "<<city<<" "<<room_no<<" "; for(i=0;i<3;i++)
{file<<checkIn[i];
if(i<2)
file<<"-";
}file<<" ";for(i=0;i<3;i++)
{file<<checkOut[i];
if(i<2)
file<<"-";
}file<<" "<<roomType<<" "<<roomRate<<" "<<price<<endl;
file.close();
}
void Guest::setCheckInDate(int d,int m,int y){
checkIn[0] = d;
checkIn[1]= m;
checkIn[2]=y;
}
int* Guest::getCheckInDate(){
return checkIn;
}
void Guest::setCheckOutDate(int d,int m,int y){
checkOut[0] = d;
checkOut[1]= m;
checkOut[2]=y;
}
int* Guest::getCheckOutDate(){
return checkOut;
}
void Guest::setName(char* nm){
for(int i=0; i < 10; ++i){
name[i] = nm[i];
}
}
char* Guest::getName(){
return name;
}
void Guest::setPhno(char* ph){
for(int i=0; i < 10; ++i){
ph_no[i] = ph[i];
}
}
char* Guest::getPhno(){
return ph_no;
}
void Guest::setNewPhone(char* ph){
for(int i=0; i < 10; ++i){
phhhh[i] = ph[i];
}
}
int Guest::getRoomNo(){
return room_no;
}
void Guest::setCity(char* ct){
for(int i=0; i < 10; ++i){
city[i] = ct[i];
}
}
void Guest::setPrice(int pr){
price=pr*roomRate;
}
bool Guest::check(char *a){
int j=0;
char k[6]="123";
for(int i=0;i<3;i++){
if(k[i]==a[i])
j++;
}
if(j==3)
return true;
else
return false;
}
char* Guest::getCity(){
return city;
}
void Guest::orderFood(){
//displaying the food items available along with their price
//storing the total sum and adding it to the total bill
}
string Guest::submitFeedback(){
// A form will be provided to be filled
}
void Guest::putdata()
{
fstream file;
file.open("record.txt",ios::in);
if(!file){
cout<<"No record is present";
}
int q=0;
//while(file.good()){
// while (getline(file, line)){
while(file>>name>>ph_no>>city>>room_no>>checkIn[0]>>checkIn[1]>>checkIn[2]>>checkOut[0]>>checkOut[1]>>checkOut[2]>>roomType>>roomRate>>price){
file>>name;
file>>ph_no;
file>>city;
file>>room_no;
for(int i=0;i<3;i++)
{file>>checkIn[i];
}for(int i=0;i<3;i++)
{file>>checkOut[i];
}
file>>roomType;
file>>roomRate;
file>>price;
int i;
int q=roomType;
string typeOfRoom;
switch(q){
case 1:{typeOfRoom="Single room";
}
break;
case 2:{typeOfRoom="Double room";
}
break;
case 3:{typeOfRoom="Family room";
}
break;
case 4:{typeOfRoom="King sized room";
}
break;}
//Printing all the records
cout<<"\n Cusromer Details";
cout<<"\n ****************";
cout<<"\t Name: "<<name;
cout<<"\t Phone No: "<<ph_no;
cout<<"\t City: "<<city;
cout<<"\t Room No: "<<room_no;
cout<<"\t Check In(DD-MM-YYYY): ";
for(i=0;i<3;i++)
{cout<<checkIn[i];
}
cout<<"\t Check Out(DD-MM-YYYY): ";
for(i=0;i<3;i++)
{cout<<checkOut[i];
}
cout<<"\t Room Type: "<<typeOfRoom;
cout<<"\t Room Rate: "<<roomRate;
cout<<"\t Total Price: "<<price;
cout<<"\n\n";
}
file.close();
}
void Guest::searchRecord(){
fstream file;
file.open("record.txt",ios::in);
if(!file){
cout<<"Error in opening file..";
}
char nm[30];
setName(nm);
char ph[14];
char ct[30];
// while (!file.eof()){
int i=0,j=0;
// cout<<ph_no;
cout<<"Enter the phone no";
cin>>ph;
setNewPhone(ph);
//Searching a record through phone no.
while(file>>name>>ph_no>>city>>room_no>>checkIn[0]>>checkIn[1]>>checkIn[2]>>checkOut[0]>>checkOut[1]>>checkOut[2]>>roomType>>roomRate>>price){
int r=0;
for(int i=0;i<10;i++){
if(phhhh[i]==ph_no[i])
r++;
}
if(r==10){
int i;
j++;
cout<<"\n Cusromer Details";
cout<<"\n ****************";
cout<<"\t Name: "<<name;
cout<<"\t Phone No: "<<ph_no;
cout<<"\t City: "<<city;
cout<<"\t Room No: "<<room_no;
cout<<"\t Check In(DD-MM-YYYY): ";
for(i=0;i<3;i++)
{cout<<checkIn[i];
}
cout<<"\t Check Out(DD-MM-YYYY): ";
for(i=0;i<3;i++)
{cout<<checkIn[i];
}
cout<<"\t Room Type: "<<roomType;
cout<<"\t Room Rate: "<<roomRate;
cout<<"\n\n";
break;
}
}
if(j==0){
cout<<"\n\nNo matching record found!\n\n";
}
file.close();
}
//Deleting the record through room no
void Guest::deleteRecord(){
int a;
cout<<"Enter room no.";
cin>>a;
string line1;
ifstream fp1;
fp1.open("record.txt");
ofstream file;
file.open("temp_room.txt");
int flag=0;
while(fp1>>name>>ph_no>>city>>room_no>>checkIn[0]>>checkIn[1]>>checkIn[2]>>checkOut[0]>>checkOut[1]>>checkOut[2]>>roomType>>roomRate>>price){
if(room_no==a)
flag=1;
if(room_no!=a){
int i;
file<<name<<" "<<ph_no<<" "<<city<<" "<<room_no<<" "; for(i=0;i<3;i++)
{file<<checkIn[i];
}file<<" ";for(i=0;i<3;i++)
{file<<checkIn[i];
}file<<" "<<roomType<<" "<<roomRate<<endl;
}
}
if(flag==0)
cout<<"\nRecord Not Found\n";
else
cout<<"\nRecord Deleted\n";
fp1.close();
file.close();
remove("record.txt");
rename("temp_room.txt","record.txt");
}