Question is under Alpha submission on first picture, other pages are useful to s
ID: 3684544 • Letter: Q
Question
Question is under Alpha submission on first picture, other pages are useful to solve it. occuming hashtags and "my" if the next frequently occurming hashtag, then both bite" and "metal" would have a rank of 1, and "my*would have a rank of2 5. Trend File Output For all hashtags that appears in the end sie, your program should output a maked list of hashtags, the nok position, and the change in rank between the start file and end file. Each hashtag should be output to the specified rank output file with one hashtag per line using the following format, using a single space to separate the entries R: W (RD) R is the rank of the hashtag within the end file. Ifa tie exists for that position, the rank should be proceded with the character T. Hashtag with the same rank should be output alphabetically N is the wond itself displayed using all lowercase characters RD is the difference in rank between the start fle and the end file. If the a word did not appear in the start file, the rank difference should be reported as "(new), If the rank did not change between the start file and the end file, the rank difference should be reponed as " o The following provides an example of the output file format: Tl: bite (+0 71: metal (+3) 3: shiny (-1) 4: please (new) 6. Alpha Submission Your alpha assignment is to implement the Hashtag class methods, and tum in your Hashtag.cpp file to the dropbox called Project 4 (alpha) on D2L. We will use your file with our own main function and test files, to check the behavior of each of the Hashtag method we prescribe. Use the same Hashtag.h file given above and provided from the website, or be in danger of your alpha not compiling. 7. Note on public testfiles For grading the assignment, the public test files 2 to 5 consist of actual hashtags extracted from top 100 public Twitter accounts, for a specific day. The following list a description of the public test files: testfile? 1: 2016-03-16 testfile22: 2016-03-17 testfile3 1: 2016-03-17 testfile3_2: 2016-03-20 testfile4 1: 2016-03-21 testfile4 2: 2016-03-22 testfile5 1: 2016-03-22 testfiles_2: 2016-03-23Explanation / Answer
class Hashtag{
private:
string word;
int startCount;
int endCount;
int startRank;
int endRank;
public:
Hashtag(string word){
this->word = word;
}
Hashtag(string word, int startCount,int endCount = 0){
this->word = word;
this->startCount = startCount;
this->endCount = endCount;
}
string getWord() const{
return word;
}
int getStartCount() const{
return startCount;
}
int getEndcount() const{
return endCount;
}
int getStartRank() const{
return startRank;
}
int getEndRank() const{
return endRank;
}
void setStartRank(int rank){
startRank = rank;
}
void setEndRank(int rank){
endRank = rank;
}
void IncrementStartCount(){
startCount += 1;
}
void IncrementEndCount(){
endCount += 1;
}
bool operator<(const Hashtag& rhs) const{
if (rhs.getEndcount() < lhs.getEndcount())
return true;
if (rhs.getEndcount() == lhs.getEndcount() && rhs.getEndcount() != 0 && lhs.getEndcount() != 0 && lhs.getWord() < rhs.getWord())
return true;
if (rhs.getEndcount() == 0 && lhs.endCount() == 0 && rhs.getStartCount() < lhs.getStartCount())
return true;
if (rhs.getEndcount() == 0 && lhs.endCount() == 0 && rhs.getStartCount() == lhs.getStartCount() && lhs.getWord() == rhs.getWord())
return true;
return false;
}
};
int find(vector<Hashtag> allTags, string s){
for (int i = 0; i < allTags.size(); i++){
if (allTags[i].getWord() == s)
return i;
}
return -1;
}
int main(){
vector<Hashtag> allTags;
ifstream infile_1,infile_2;
infile_1.open("startHashtagFile.txt");
infile_2.open("endHashtagFile.txt");
string s;
while (!infile_1.eof()){
infile_1 >> s;
int res = find(allTags,s);
if (res == -1){
Hashtag ht(s,1,0);
allTags.push_back(ht);
}
else
allTags[i].setStartRank(allTags[i].getStartRank()+1);
}
infile_1.close();
while (!infile_2.eof()){
infile_2 >> s;
int res = find(allTags,s);
if (res == -1){
Hashtag ht(s,0,1);
allTags.push_back(ht);
}
else
allTags[i].setEndRank(allTags[i].getEndRank()+1);
}
infile_2.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.