-
Notifications
You must be signed in to change notification settings - Fork 1
/
customers.h
196 lines (180 loc) · 5.11 KB
/
customers.h
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
#include <fstream>
#include <iostream>
#include <cstring>
#include <list>
#include <unordered_map>
#include <cstdlib>
using namespace std;
void visit_customer_portal();
// ----------------TRIE--------------------
//Trie for storing customer emails
class trie_node{
public:
char data;
unordered_map <char, trie_node*> children;
bool terminal;
trie_node(char d){
data = d;
terminal = false;
}
};
class Trie{
public:
trie_node* root;
int customer_count;
Trie(){
root = new trie_node('\0');
customer_count = 0;
}
//insert a record into trie
void insert(string email){
trie_node* temp = root;
for(int i=0; email[i]!='@'; i++){
if(email[i]=='\0'){
break;
}
char ch = email[i];
if(temp->children.count(ch)){
//character exists in trie already
temp = temp->children[ch];
}
else{
trie_node* n = new trie_node(ch);
temp->children[ch] = n;
temp = n;
}
}
temp->terminal = true;
customer_count++;
}
//search a record (with email)
bool search(string email){
trie_node* temp = root;
for(int i=0; email[i]!='@'; i++){
if(email[i]=='\0'){
break;
}
char ch = email[i];
if(temp->children.count(ch)==0){
return false;
}
temp = temp->children[ch];
}
return temp->terminal?true:false;
}
};
// -------------------CUSTOMERS----------------------
class Customer{
public:
char name[30] = {'\0'};
char address[30] = {'\0'};
char email[50] = {'\0'};
char phone_no[15] = {'\0'};
char password[20] = {'\0'};
Customer(){
//name = address = email = phone_no = password = "";
}
Customer(string a, string b, string c, string d, string e){
strcpy(name, a.c_str());
strcpy(address, b.c_str());
strcpy(email, c.c_str());
strcpy(phone_no, d.c_str());
strcpy(password, e.c_str());
}
};
void initCustomers(Trie T){
fstream f1;
Customer C;
f1.open("customers.txt", ios::in||ios::binary);
//int i=0;
do{
f1.read( (char*)&C, sizeof(Customer) );
string email = C.email;
T.insert(email);
//i++;
}while(!f1.eof());
cout<<"Initiated customer trie\n";
f1.close();
}
// ---------- create account ------------
bool createAccount(Trie &T){
system("clear");
cin.clear();
fflush(stdin);
string name, address, email, phone, password;
cout<<"Enter name: \n";
getline(cin, name);
cout<<"Enter address: \n";
getline(cin, address);
cout<<"Enter email: \n";
getline(cin, email);
cout<<"Enter phone number: \n";
getline(cin, phone);
cout<<"Enter password: \n";
getline(cin, password);
//check if email already exists
bool p = T.search(email);
if(p){
cout<<"An account with this email already exists. Please choose a different email.\n";
cout<<"Directing you back to the customer portal...\n";
//system("clear");
char c;
cout<<"Press any key, followed by 'enter' key, to continue.\n";
cin>>c;
return false;
}
//new entry
//initializing customer object
Customer C1(name, address, email, phone, password);
//writing customer details in file 'customers.txt'
fstream f1;
f1.open("customers.txt", ios::app||ios::binary);
f1.write( (char*)&C1, sizeof(C1) );
f1.close();
T.insert(email);
system("clear");
cout<<"Successfully created customer account.\n";
cout<<"Directing you back to the customer portal...\n";
char c;
cout<<"Press any key, followed by 'enter' key, to continue.\n";
cin>>c;
//system("clear");
return true;
}
// --------------- BOOKINGS -------------------
class Booking{
public:
char cust_name[30];
char cust_email[50];
char date[20];
char places[10][30]={"\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0"};
int amount;
int no_of_people;
char agent_name[30];
Booking(){
//places = {"\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0", "\0"};
}
void initBooking(string name, string email, string d, list <string> p, float a, int n, string agent){
strcpy(cust_email, email.c_str());
strcpy(cust_name, name.c_str());
strcpy(date, d.c_str());
//places = p;
amount = a;
no_of_people = n;
strcpy(agent_name, agent.c_str());
}
void printBooking(){
cout<<"Customer Name: "<<cust_name<<endl;
cout<<"Customer Email: "<<cust_email<<endl;
cout<<"Date of Booking: "<<date<<endl;
cout<<"Places included in Trip: ";
for(int i=0; i<10; i++){
if(places[i]!='\0'){
cout<<places[i]<<" ";
}
}
cout<<"\nNo of people on trip: "<<no_of_people<<endl;
cout<<"Total amount for Trip: "<<amount<<endl;
cout<<"Agent Name: "<<agent_name<<endl;
}
};