Question: Create a C + + program that analyzes the frequency of the occurrence of hashtags within two inputs files, a startHashtagFile and an endHashtagFile. The

Create a C++ program that analyzes the frequency of the occurrence of hashtags within two inputs files, a startHashtagFile and an endHashtagFile. The program will analyze the change in rank of specific hashtags from the startHashtagFile to the endHashtagFile, where the highest ranked hashtag (i.e., hashtag with rank 1) appears most frequently.
Your program will output
- Hashtag with rank #1 in the end file with number of occurrences
- Hashtag with Ranking increases the most (with an increase value in ranking)
- Hashtag with Ranking decreases the most (with a decrease value in ranking)
- New Hashtags (first 10 by ranking) in the end file. Each one is printed with (count, rank)
Note: A hashtag in the End file is considered "new" if it is not a hashtag in the Start file.
[Input Hashtag]
For this assignment, the input text file will consist of uppercase and lowercase characters ('a' to 'z','A' to 'Z'). Each hashtag within the text file will be separated by one or more whitespace characters ('','\t','
','\r'). When reading in each hashtag, change every character of the hashtag to lowercase.
The startHashtagFile and endHashtagFile files are named testfilexStart.txt and testfilexEnd.txt, respectively. x is a number from 0 to 4.
[Hashtag Class]
The following Hashtag class definition must be used for the assignment. You may add data and/or function members to the class but do not modify the existing ones. You may create your own class(es) to do other tasks.
class Hashtag {
private:
string word; // The hashtag itself
int Count; // Number of occurrences in the file
int Rank; // Rank
public:
Hashtag(string word);
Hashtag(string word, int Count);
string getWord() const;
int getCount() const;
int getRank() const;
void setRank(int rank);
void IncrementCount(); //to increment Count
// Overloaded < and > operators for Hashtag objects
bool operator<(const Hashtag& rhs) const; };
[Overloading the < operator]
You should overload the < operator for the Hashtag class. The < operator is used to sort the hashtags to determine the ranking and ordering of hashtags. The hashtag with the largest count should appear first (rank 1). To achieve this, a hashtag with a larger count will be considered less than a hashtag with a smaller count. The left-hand side hashtag is the object on which the operator< function is called. The right-hand side object is passed as a reference argument to the operator< function.
The lefthand side (lhs) hashtag is less than the righthand (rhs) if (all string comparisons are case insensitive):
If the rhs count is less than the lhs count
If the rhs count is equal to the lhs count, and the lhs word is less than rhs word alphabetically
Note: If you program uses a vector, by overloading the < operator, you can use sort() function to sort a vector of Hashtag objects, as shown below:
vector allTags;
sort(allTags.begin(), allTags.end());
[Hashtag Counting]
As each hashtag is read from the input text file, your program must keep track of hashtags and the number of times each hashtag is used. While the input file may contain both uppercase and lowercase characters, the identification of unique hashtags is case insensitive. For example, "Party", "party", and "PARty" are all considered the same hashtag.
[Hashtag Ranking]
After processing the startHashtagFile, your program must determine the start rank for each hashtag. Similarly, after processing the endHashtagFile, your program must determine the end rank for each hashtag. The rank of a hashtag is the position within a list of hashtags sorted by decreasing count with 1 being the highest rank (corresponding to the most hashtag with the highest count).
Contents of testfile0Start:
Party Byte party MEtal My PARty byte metal paRty BYTE my MY EEE175 BYTE
Contents of testfile0End:
byte Party party MEtal eee201 PARty metal party paRty BYTE MeTAL my MY Metal Byte Metal METAL My EEE201 Party mY metal Party Test
Output (using testfile0Start.txt and testfile0End.txt):
Hashtag with Rank 1 in the End file: metal with 7 counts.
Hashtag with Ranking increases the most: metal(+2 in ranking)
Hashtag with Ranking decreases the most: byte(-2 in ranking)
New Hashtags (first 10 by ranking) in the End file:
eee201(2,4)
test (1,5)
Include a main.cpp, Hashtag.cpp, and Hashtag.h files.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!