-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider.cpp
257 lines (216 loc) · 6.47 KB
/
provider.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
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
// Linh Nguyen
#include "chocan.h"
// initialize
provider::provider() : num_consul(000), total_fee(000), provider_ID(000) , service_provided(nullptr)
{
}
// copy constructor for provider class
provider::provider(const provider ©) : model(copy), num_consul(copy.num_consul),
total_fee(copy.total_fee), provider_ID(copy.provider_ID)
{
this -> service_provided = new service_list(*copy.service_provided);
}
provider:: provider (const string& p_first, const string& p_last, const string & p_address, const string & p_city,
const string & p_state,int p_zip, const string & p_email, int num, int p_ID,float fee, service_list *list) :
model(p_first, p_last, p_address, p_state, p_city, p_zip, p_email), num_consul(num), provider_ID(p_ID), total_fee(fee)
{
}
provider::~provider()
{
if (service_provided) {
//delete service_provided;
service_provided = NULL;
}
}
void provider:: input()
{
int ID;
int num;
int fee;
cout << "\n\t\t[ADDING A NEW PROVIDER]";
//call the model input to ask personal data of provider
model::input();
cout << "\n\tEnter the ID of the membership: ";
cin >> ID;
cout << "\n\tEnter the number of consultant: ";
cin >> num;
cout << "\n\tEnter the fee of consultant: ";
cin >> fee;
cout << "\n\tThe service list: ";
service_provided = new service_list();
service_provided -> add_new_service_record();
setInput(ID, num, fee);
}
void provider:: setInput(int ID, int num, int fee)
{
provider_ID = ID;
num_consul = num;
total_fee = fee;
}
void provider:: display(std::ostream& cout = std::cout) const
{
//same input () we need to call the function from the model to display some info
model::display();
cout << "\n\tThe ID of the provider: " << provider_ID;
cout << "\n\tThe number of consultations: " << num_consul;
cout << "\n\tThe fee of the membership: " << total_fee;
cout << "\n\tThe services list: ";
service_provided -> display_all_services();
cout << "\n\n";
}
void provider:: display_summary () const
{
float total_fee;
int total_num;
total_num = service_provided -> num_services();
cout << "\n\t2.The total number of consultations: " << total_num;
total_fee = service_provided ->total_cost();
cout << "\n\t3.The overall fee " << total_fee;
}
void provider:: write_file()
{
float total_fee;
int total_num;
char fileNameOut [] = "p_report.txt";
ofstream outfile(fileNameOut);
total_num = service_provided -> num_services();
total_fee = service_provided ->total_cost();
outfile << "2.The total number of consultations: " << total_num << '\n';
outfile << "3.The overall fee " << total_fee << '\n';
outfile.close();
}
void provider:: display_directory()
{
service_provided -> display_all_services();
}
/*bool provider::check_service_code ()
{
int check;
cout << "Please enter service code that you want to check "<< check;
//service_provided -> check_code(check);
}*/
void provider::read(const string &file_name) const
{
string p_first;
string p_last;
string p_address;
string p_city;
string p_state;
int p_zipcode;
string p_email;
int num_consul;
float total_fee;
int provider_ID;
//service_list *list;
string eachLine;
ifstream INFILE(file_name);
if(INFILE.is_open())
{
while(getline(INFILE, eachLine))
{
stringstream readFile(eachLine);
getline(readFile, p_first, '|');
getline(readFile, p_last, '|');
getline(readFile, p_address, '|');
getline(readFile, p_city, '|');
getline(readFile, p_state, '|');
readFile >> p_zipcode;
readFile.ignore(1, '|');
getline(readFile, p_email, '|');
readFile >> num_consul;
readFile.ignore(1,'|');
readFile >> total_fee;
readFile.ignore(1,'|');
readFile >> provider_ID;
service_list * t_list = new service_list();
t_list->read_from_disk(INFILE);
//provider new_provider(p_first, p_last, p_address, p_city, p_state
// , p_zipcode, p_email, num_consul,total_fee, provider_ID, t_list);
//provider* temp_prov = &new_provider;
//this would have worked similarly to member class' read function
}
return;
}
cerr << "ERROR: unable to open file " << file_name << " for loading data!!!\n";
exit(1);
}
void provider::update_info()
{
model::update_info();
}
// verify ID provider
bool provider::verify_provider_ID(int ID)
{
if (this->provider_ID == ID)
return true;
return false;
}
void provider::set_ID(int ID)
{
this->provider_ID = ID;
}
//operator overloading
/*
bool provider::operator < (const provider &to_compare) const{
if(provider_ID < to_compare.provider_ID){
return true;
}
return false;
}
bool provider::operator > (const provider &to_compare) const{
if(provider_ID > to_compare.provider_ID){
return true;
}
return false;
}
bool provider::operator == (const provider &to_compare) const{
if(provider_ID == to_compare.provider_ID){
return true;
}
return false;
}
*/
bool provider::operator<(const provider &to_compare) const{
if(provider_ID < to_compare.provider_ID){
return true;
}
return false;
}
bool provider::operator>(const provider &to_compare) const{
if(provider_ID > to_compare.provider_ID){
return true;
}
return false;
}
bool provider::operator>(const int ID_compare) const
{
if(provider_ID > ID_compare)
return true;
return false;
}
//needed for BST
bool provider::operator==(const provider &to_compare) const
{
if(provider_ID == to_compare.provider_ID)
return true;
return false;
}
//needed for BST
bool provider::operator==(const int ID_compare) const
{
if(provider_ID == ID_compare)
return true;
return false;
}
int provider::get_provider_ID() const
{
return this->provider_ID;
}
float provider::get_total_fee() const
{
return this->total_fee;
}
int provider::get_num_consul() const
{
return this->num_consul;
}