-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
45 lines (44 loc) · 1.05 KB
/
Copy pathMain.cpp
File metadata and controls
45 lines (44 loc) · 1.05 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
#include "Admin.h"
#include "Customer.h"
void read_users(vector<unique_ptr<User>>& v) {
string temp;
vector<string>p;
ifstream file("users.csv");
for (int i = 0; i < CountInFile("users.csv"); i++) {
getline(file, temp);
p = split(temp, ';');
if (p[0] == "admin")
v.push_back(unique_ptr<User>(new Admin(
stoi(p[1]), p[2], p[3], p[4], stoi(p[5]), p[6]
)));
else v.push_back(unique_ptr<User>(new Customer(
stoi(p[1]), p[2], p[3], p[4], stoi(p[5])
)));
}
file.close();
}
void read_contacts(vector<unique_ptr<User>>& v) {
string temp;
vector<string>p;
int n = CountInFile("contact.csv");
ifstream file("contact.csv");
for (int i = 0; i < n; i++) {
getline(file, temp);
p = split(temp, ';');
for (auto& item : v) {
if (stoi(p[0]) == item->getId()) {
item->setContact(Contacts(
stoi(p[0]), p[1], p[2], p[3]
));
}
}
}
file.close();
}
int main() {
vector<unique_ptr<User>> users;
read_users(users);
read_contacts(users);
for (auto& item : users) item->print();
return 0;
}