-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.h
173 lines (158 loc) · 3.84 KB
/
admin.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
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cstring>
using namespace std;
// ------------------ADMIN FNS-----------------------
class Admin{
string name;
string email;
string phone_no;
string password;
public:
void add_admin(string n, string e, string p, string pass){
name = n;
email = e;
phone_no = p;
password = pass;
}
bool login(string name, string password){
if(name==this->name && this->password==password){
cout<<"here\n";
return true;
}
return false;
}
};
void initAdmins(Admin Ad[]){
//add code
ifstream f1;
f1.open("admins.txt", ios::in);
int i=0;
while(!f1.eof()){
f1.read( (char*)&Ad[i], sizeof(Admin) );
i++;
}
cout<<"Admins information read\n";
f1.close();
}
bool login_admin(Admin Ad[], int no=2){
string name, password;
system("clear");
cout<<"Enter name : ";
cin.ignore();
getline(cin, name);
cout<<"Enter password : ";
cin>>password;
for(int i=0; i<no; i++){
bool p = Ad[i].login(name, password);
if(p){
return true;
}
}
return false;
}
// ----------------AGENTS-------------------
class Agent{
public:
string name;
string email;
string phone_no;
public:
Agent(string n="Alina", string e="[email protected]", string p="9891002255"){
name = n;
email = e;
phone_no = p;
}
void add_details(string a, string b, string c){
name = a;
email = b;
phone_no = c;
}
string getName(){
return name;
}
};
void initAgents(Agent Ag[], int &agent_count){
agent_count=0;
ifstream f1;
f1.open("agents.txt", ios::in);
int i=0;
f1.read( (char*)&Ag[i], sizeof(Agent) );
while(!f1.eof()){
i++;
f1.read( (char*)&Ag[i], sizeof(Agent) );
}
cout<<"Agent details initiated\n";
agent_count = i;
f1.close();
}
string assign_Agent(Agent A[], int no=10){
int c = rand()%(no-1);
return A[c].getName();
}
// -----------------ADMIN FUNCTIONS------------------
//view all customers
void view_all_customers(){
cout<<"*****---------- ALL CUSTOMERS ----------*****\n\n";
int total_cust=0;
ifstream f1;
Customer C1;
f1.open("customers.txt", ios::in);
f1.read( (char*)&C1, sizeof(Customer) );
while(!f1.eof()){
cout<<left;
cout<<setw(30)<<C1.name<<" "<<setw(30)<<C1.address<<" "<<setw(15)<<C1.phone_no<<" "<<setw(30)<<C1.email<<endl;
total_cust++;
f1.read( (char*)&C1, sizeof(Customer) );
}
cout<<"\nTotal customers are: "<<total_cust<<endl;
f1.close();
}
//view all bookings
void view_all_bookings(){
system("clear");
cout<<"*****---------- ALL BOOKINGS ----------*****\n\n";
int total_books=0;
ifstream f1;
Booking B1;
f1.open("bookings.txt", ios::in);
f1.read( (char*)&B1, sizeof(Booking) );
while(!f1.eof()){
B1.printBooking();
cout<<endl;
f1.read( (char*)&B1, sizeof(Booking) );
total_books++;
}
cout<<"Total Bookings are: "<<total_books<<endl;
f1.close();
}
class Edge;
class GraphInt;
class GraphFloat;
//forward declaration
bool add_edge(GraphInt &g1, GraphFloat &g2){
char a[30], b[30];
int cost;
float time;
cout<<"Enter place 1: ";
cin.ignore();
// cin.clear();
// fflush(stdin);
cin.getline(a, 30, '\n');
cout<<"Enter place 2: ";
cin.getline(b, 30, '\n');
cout<<"Enter flight cost: ";
cin>>cost;
cout<<"Enter flight time: ";
cin>>time;
Edge E(a, b, cost, time);
fstream f3;
f3.open("places.txt", ios::app);
f3.write( (char*)&E, sizeof(E) );
f3.close();
g1.addEdge(a, b, cost);
g2.addEdge(a, b, time);
cout<<"Place/Flight added successfully.\n";
return true;
}