Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this assignment pls. C++ This assignment is to give you practice with STL priority_queues. The idea behind this assignment is to

I need help with this assignment pls. C++

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 mycomparison object 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 . You will probably use several other libraries

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), and the comparator type to use (TweetComparator)

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, TweetComparator> tweets(*cmp);

cmp is a pointer to a TweetComparator

Please follow the expected output text. This will allow the grader to grade your assignments faster so you get your grades earlier.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

3. Is IBMs program really a mentoring program? Why or why not?

Answered: 1 week ago