-
Notifications
You must be signed in to change notification settings - Fork 0
/
Librarian.cpp
79 lines (64 loc) · 1.91 KB
/
Librarian.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
//
// Librarian.cpp
//
#include "Librarian.h"
#include "User.h"
#include <iostream>
#include <list>
#include <string>
#include <fstream>
Librarian::Librarian() {
}
Librarian::Librarian(string tempusername, string temppassword) {
set_username(tempusername);
set_password(temppassword);
}
void Librarian::printlibrarian() {
print_user();
}
void Librarian::printlibrarians(list<Librarian>& mylibrarians) {
list<Librarian>::iterator iterl;
for (iterl=mylibrarians.begin(); iterl!=mylibrarians.end(); iterl++) {
Librarian templibrarian=*iterl;
templibrarian.printlibrarian();
cout << endl;
}
}
// overload operator to input librarian
void Librarian::operator>>(list<Librarian>& mylibrarians) {
ifstream input;
string tempusername, blankline, temppassword;
input.open("librarianfinal.dat");
if(input.fail()){
cerr << "Error opening librarianfinal.dat for input...\n" << endl;
}
while(input >> tempusername) {
getline(input, blankline);
getline(input, temppassword);
Librarian templibrarian = Librarian(tempusername, temppassword);
mylibrarians.push_back(templibrarian);
}
input.close();
}
void Librarian::operator<<(list<Librarian>& mylibrarians) {
ofstream output;
list<Librarian>::iterator iterl;
output.open("librarianfinal.dat");
if(output.fail()) {
cerr << "Error opening librarianfinal.dat for output...\n" << endl;
}
for(iterl=mylibrarians.begin();iterl!=mylibrarians.end();iterl++) {
Librarian templibrarian = *iterl;
output << templibrarian.get_username() << endl << templibrarian.get_password() << endl << endl;
}
output.close();
}
bool Librarian::operator==(const Librarian& rhs) {
Librarian templibrarian = rhs;
if(get_username()==templibrarian.get_username()){
return true;
}
else {
return false;
}
}