-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
201 lines (185 loc) · 6.49 KB
/
Main.cpp
File metadata and controls
201 lines (185 loc) · 6.49 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
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
/*
* Main.cpp
*
* Created on: Feb 11, 2016
* Modified on March 4, 2016
* Authors: Radhika Khatod, Drew Taylor
*/
#include "ProfileData.h"
#include "FriendNetwork.h"
#include "BTreeNetwork.h"
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
vector<string> split(string str, char delimiter)
{
vector<string> internal;
stringstream ss(str); // turn the string into a stream.
string tok;
while(getline(ss, tok, delimiter))
{
internal.push_back(tok);
}
return internal;
}
int main ()
{
ProfileData profiles;
FriendNetwork friendList;
BTreeNetwork tree;
profiles.createFile();
ifstream f;
f.open("Generated.txt", ios::in);
if(!f) cerr << "File not found" << endl;
else {
string line;
while(std::getline(f, line)) {
vector<string> words = split(line, ',');
int key = friendList.insertPerson(words[0]);
profiles.insertProfile(key, words[0], words[1], words[2]);
Profile *profile = new Profile(key, words[0]);
tree.insert(profile, tree.root);
for (int i = 3; i < words.size(); i++) {
friendList.addFriend(key, words[i]);
}
}
}
cout << " #####\n";
cout << " #######\n";
cout << " ###### ######## #####\n";
cout << " ##################### #############\n";
cout << " ######################--#####################\n";
cout << " #### ###################### #####\n";
cout << "## #### ############# ###\n";
cout << "# #### ############ ##\n";
cout << " ### $$$$$$ #### #\n";
cout << " ## $$$$$$ ###\n";
cout << " # $$$$$$ ##\n";
cout << " $$$$$$ ##\n";
cout << " $$$$$$ #\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " $$$$$$\n";
cout << " WELCOME TO THE \n";
cout << "**************************\n";
cout << "╔╦╗┌─┐┬ ╔═╗┬ ┌─┐┬ ┬┌─┐\n ║║├┤ │ ╠═╝│ ├─┤└┬┘├─┤\n═╩╝└─┘┴─┘ ╩ ┴─┘┴ ┴ ┴ ┴ ┴\n"\
;
cout << "**************************\n";
cout << " SOCIETY \n";
/*
for (int i = 0; i < 211; i++) {
string entireProfile = "";
entireProfile += profiles.retrieveProfile(i);
entireProfile += friendList.retrieveFriends(i);
if (entireProfile != "") {
cout << entireProfile << endl;
}
}*/
try
{
while(true) {
cout << "Type one of the following options to continue:\n> Insert\n> AddFriend\n> ListFriendsInfo\n> ListInfo\n> PrintAll\n";
string x;
getline(cin, x);
string* argument = new string[5];
int index = 0;
string value = "";
for (int i = 0; i < x.length(); i++) {
if (index == 3) {
if (x[i] == '"') {
for (int j = i+1; j < x.length()-1; j++) {
value += x[j];
}
}
}
else {
if (x[i] != ' ') {
value += x[i];
}
else {
argument[index] = value;
value = "";
index++;
}
}
if (i == x.length() - 1) {
argument[index] = value;
value = "";
index++;
}
}
if(argument[0] == "INSERT" || argument[0] == "insert" || argument[0] == "Insert") {
int key2 = friendList.insertPerson(argument[1]);
profiles.insertProfile(key2, argument[1], argument[2], argument[3]);
Profile *profile2 = new Profile(key2, argument[1]);
tree.insert(profile2, tree.root);
}
if(argument[0] == "ADDFRIEND" || argument[0] == "addfriend" || argument[0] == "AddFriend") {
if (friendList.findPerson(argument[1]) != -1 && friendList.findPerson(argument[2]) != -1) {
friendList.addFriend(friendList.findPerson(argument[1]), argument[2]);
friendList.addFriend(friendList.findPerson(argument[2]), argument[1]);
}
}
//lists name, age, and occupation of friends of some user
if(argument[0] == "ListFriendsInfo" || argument[0] == "list friends info" || argument[0] == "List friends info") {
if (friendList.findPerson(argument[1]) != -1) {
string friendArray = friendList.retrieveFriends(friendList.findPerson(argument[1]));
string friendProfile;
for (int i = 0; i < friendArray.length(); i++) {
if (friendArray[i] != ',') {
friendProfile += friendArray[i];
}
else {
cout << profiles.retrieveProfile(friendList.findPerson(friendProfile)) << endl;
friendProfile = "";
}
}
}
}
//List all users' information with names e.g. Alice <= name <= Bob, ListInfo lowerBound upperBound,
//where lowerBound and upperBound are names that may or may not be in the system
if(argument[0] == "ListInfo" || argument[0] == "list info") {
string keys = tree.range(argument[1], argument[2], tree.root);
string aKey;
for (int i = 0; i < keys.length(); i++) {
if (keys[i] != ',') {
aKey += keys[i];
}
else {
cout << profiles.retrieveProfile(atoi(aKey.c_str())) << endl;
aKey = "";
}
}
}
if(argument[0] == "PrintAll" || argument[0] == "print all" || argument[0] == "Print all") {
for (int i = 0; i < 211; i++) {
string entireProfile = "";
entireProfile += profiles.retrieveProfile(i);
string check = friendList.retrieveFriends(i);
if (check != "") {
entireProfile += ",";
}
entireProfile += check;
if (entireProfile != "") {
cout << entireProfile << endl;
}
}
}
}
}
catch(exception& ex) {
// cerr < ex.what() << endl;
}
return 0;
}