-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (67 loc) · 2.73 KB
/
main.cpp
File metadata and controls
80 lines (67 loc) · 2.73 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
#include <map>
#include "TwitterData.hpp"
using namespace std;
int main(int argc, char *argv[])
{
// Schema: UserName,Last,First,Email,NumTweets,MostViewedCategory
string raw_data[5][6] = {{"rangerPower", "Smit", "Rick", "smitRick@gmail.com", "1117", "power lifting"},
{"kittyKat72", "Smith", "Kathryn", "kat@gmail.com", "56", "health"},
{"lexi5", "Anderson", "Alexis", "lexi5@gmail.com", "900", "education"},
{"savage1", "Savage", "Ken", "ksavage@gmail.com", "17", "president"},
{"smithMan", "Smith", "Rick", "rick@hotmail.com", "77", "olympics"}};
TwitterData *twitter_data = new TwitterData[5];
for (int i = 0; i < 5; ++i)
{
twitter_data[i].setUserName(raw_data[i][0]);
twitter_data[i].setActualName(raw_data[i][2] + " " + raw_data[i][1]);
twitter_data[i].setEmail(raw_data[i][3]);
twitter_data[i].setNumTweets(stoi(raw_data[i][4]));
twitter_data[i].setCategory(raw_data[i][5]);
}
//
// Your code goes here
//
// Map Scenario 1: Search based on UserName
// Create a new std::map
map<string, TwitterData> userNameMap;
// Insert all Twitter data into the std::map.
for (int i = 0; i < 5; ++i)
{
userNameMap[twitter_data[i].getUserName()] = twitter_data[i];
}
// Iterate through the std::map and print the key-value pairs line by line
for (const auto& entry : userNameMap)
{
cout << entry.first << ": " << entry.second.print() << endl;
}
// Find the person whose username is savage1 and print out the entire record
auto it = userNameMap.find("savage1");
if (it != userNameMap.end())
{
cout << "Found savage1: " << it->second.print() << endl;
}
//Remove this person from the map
userNameMap.erase("savage1");
// Map Scenario 2: Search based on EmailAddress
// Create a new std::map
map<string, TwitterData> emailMap;
// Insert all Twitter data into the std::map.
for (int i = 0; i < 5; ++i)
{
emailMap[twitter_data[i].getEmail()] = twitter_data[i];
}
//Iterate through the std::map and print the key-value pairs line by line
for (const auto& entry : emailMap)
{
cout << entry.first << ": " << entry.second.print() << endl;
}
//Find the person whose email is kat@gmail.com and print out the entire record
it = emailMap.find("kat@gmail.com");
if (it != emailMap.end())
{
cout << "Found kat@gmail.com: " << it->second.print() << endl;
}
//Remove this person from the map
emailMap.erase("kat@gmail.com");
return 0;
}