Question
in c++ A compressed folder is fine, but just make sure you include all .h and .cpp files.This assignment is to give you practice with
in c++
A compressed folder is fine, but just make sure you include all .h and .cpp files.This assignment is to give you practice with STL priority_queues
The idea behind this assignment is to think of what would be useful to get a personalized tweet of the hour, or some regular period. We will make a lot of concessions to practicality, as you might imagine:
The personalized part will be modeled by having a file with hashtags of interest.
In real life, we would need to retrieve tweets on a regular basis. For this program, we will read tweets from a file.
To make parsing the text relatively easy, the file with the tweets will have a strict syntax:
o Every tweet has exactly 2 lines
o The first line has the hashtags, separated by spaces, like: #wandavision #agathaharkness
o The second line has the full tweet: It was #agathaharkness causing #wandavision all along
The highlighted tweet will include the most hashtags of interest of any stored tweet.
o For obvious reasons, getting a tweet will be modeled by writing it to cout.
Since testing such a program by waiting X minutes for the next one to appear would be tedious, you will just be displaying the tweets in order. But remember the point of this assignment is to use the priority queue data structure, so no credit if you just sort the data in an array or vector and then display it
Also for testing purposes, it will be easier to test the program by running the program with the file names for hashtags and tweets on the command line. Plus, if you have not used argc and argv in main(), you get to see how that works.
Sample tweets file:
#weather #Hayward
#weather in #Hayward: 53F at 10am
An untagged tweet
#CSUEB
My Story, My Truth at #CSUEB
#Hayward #weather
#weather in #Hayward: Humidity: 65%
#Hayward
#Hayward Transportation Division will hold an online community meeting starting at 6:30 p.m. on March 8
#Oakland #weather
#Oakland #weather: 51F-65F today
#Oakland
Share ur thoughts on #Oakland Flex streets
#Hayward #weather
#weather in #Hayward: Precipitation: 0%
Sample tags file:
#weather #Hayward
Sample run: (In a Terminal / Cmd / Powershell window, run something like: Debug\hw3.exe tweets2.txt hayweathtags.txt)
Displaying tweets in order of number of matching hashtags
#weather in #Hayward: 53F at 10am
#weather in #Hayward: Humidity: 65%
#weather in #Hayward: Precipitation: 0%
#Hayward Transportation Division will hold an online community meeting starting at 6:30 p.m. on March 8
#Oakland #weather: 51F-65F today
An untagged tweet
My Story, My Truth at #CSUEB
Share ur thoughts on #Oakland Flex streets
Some more details: (the priority queue material was pieced together from the documentation and code examples at priority_queue - C++ Reference (cplusplus.com) and especially the code for using the mycomparisonobject at priority_queue::priority_queue - C++ Reference (cplusplus.com))
To use command-line arguments to run your program, declare main() as follows: int main(int argc, char* argv[])
o argc = the number of space-separated words on the command line, which includes your executables name
o argv[0] = the executable (Debug\hw3.exe in the above example it was run in the project folder, where the project file, like hw3.vcxproj or hw3.cbp, might be)
o argv[1] = the name of the tweets file (tweets2.txt in the above example)
o argv[2] = the name of the tags file (hayweathtags.txt in the above example)
o The type of argv[1] or argv[2] is char *. If you need a string, just pass each to a constructor for string (like string(argv[1])
To use the STL priority_queue, #include
Define a class Tweet to represent a tweet. It should include a list of hashtags as well as the text of the tweet.
o The list should allow for any number of tags, so a vector is probably what you want for the list
Define a class called TweetComparator, which:
o includes the list of tags of interest
o overrides operator(Tweet&, Tweet&) and returns a bool
count up how many tags from the first parameter match the tags of interest
do the same for the 2nd parameter
if the first count is less than the second count, return true, else return false.
When declaring your priority_queue,
o you need to specify the type of the elements (Tweet), the type of the container holding the Tweets (vector
o Because we want to customize the tags list, we need to construct the priority queue with a specific TweetComparator object that has been initialized with the tags. My declaration ended up as:
o priority_queue
cmp is a pointer to a TweetComparator
Please follow the expected output text.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started