-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
128 lines (104 loc) · 3.82 KB
/
Copy pathmain.cpp
File metadata and controls
128 lines (104 loc) · 3.82 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
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
#include <iostream>
#include "Graph.cpp"
vector<Node*> pageCount(int min, int max, vector<Node*> &books) {
vector<Node*> newBooks;
//deletes all old books and adds new books w/ correct page to vector
for (int i=0; i<books.size();i++) {
if (books.back()->pageCount>=min && books.back()->pageCount<=max)
newBooks.push_back(books.back());
books.pop_back();
}
books = newBooks; //now the new books will be filtered
return newBooks;
}
vector<Node*> ratingSort(vector<Node*> &books) {
//utilize ordered map
map<double,vector<Node*>>rankedList;
for (int i=0;i<books.size();i++) {
rankedList[books[i]->rating].push_back(books[i]);
}
vector<Node*> recList;
for (auto i=rankedList.begin();i!=rankedList.end();i++){
copy(i->second.begin(),i->second.end(),back_inserter(recList));
// recList now contains all books sorted in order
}
return recList;
}
int main() {
Graph obj;
//this should probably be moved into the graph function itself
obj.readFile();
obj.constructMatrix();
//sort by value later if wanted
cout<<"Genre List"<<endl;
int counter=1;
for (auto i=obj.genreList.begin();i!=obj.genreList.end();i++){
// recList now contains all books sorted in order
cout<<i->first<<". ";
i++;
counter++;
if (counter==100) {
cout << endl;
break;
}
}
bool repeat = true;
while (repeat) {
repeat = false;
string userinput;
string genre1;
string genre2;
int min;
int max;
cout<<endl;
cout << "BookLook: The Fastest Book Recommendation Database." << endl;
cout << "Type your favorite genre from the ones listed above!" << endl;
cin >> genre1;
cout << "Type your second favorite genre!" << endl;
cin >> genre2;
obj.Search(genre1, genre2);
cout << "Thank you! We used two search algorithms to create two recommendation lists with the top rated books based on your liking.....Enjoy!" << endl;
cout<<"BFS took "<< obj.bfstime<<" nanoseconds"<<endl;
cout<<"DFS took "<< obj.dfstime<<" nanoseconds"<<endl;
//int pageNum;
//cin >> pageNum;
auto y = obj.recBooksDFS;
auto x = obj.recBooksBFS;
x = ratingSort(x);
y = ratingSort(y);
cout << endl;
cout << "We have found " << y.size() << " books for specifically for you!" << endl;
cout << endl;
cout << "Would you like to add a page count parameter? (Y/N)" << endl;
cin >> userinput;
if (userinput == "Y" || userinput == "y" ) {
cout << "What is the minimum page count you would like?" << endl;
cin >> min;
cout << "What is the maximum page count you would like?" << endl;
cin >> max;
x = pageCount(min,max,x);
y = pageCount(min,max,y);
}
for (int i = y.size() - 1; i > y.size() - 6; i--) {
cout << "Title = " << y[i]->title << endl;
cout << "Author = " << y[i]->author << endl;
cout << "Rating = " << y[i]->rating << endl;
cout << "Page Count = " << y[i]->pageCount << endl;
cout << endl;
if (y[i]->title!=x[i]->title) {
cout << "Title = " << x[i]->title << endl;
cout << "Author = " << x[i]->author << endl;
cout << "Rating = " << x[i]->rating << endl;
cout << "Page Count = " << x[i]->pageCount << endl;
cout << endl;
}
}
cout << "Would you like to find another tailored book? (Y/N)" << endl;
cin >> userinput;
if (userinput == "Y") {
obj.dfsvisited.clear();
repeat = true;
}
}
return 0;
}