Question
Create a new C++ source file named trendtracker.cpp that implements the Trendtracker class, so that trendtracker.cpp and the provided files compile into a program that
Create a new C++ source file named trendtracker.cpp that implements the Trendtracker class, so that trendtracker.cpp and the provided files compile into a program that runs with no failed tests.
main.cpp
/////
#include #include #include #include #include #include "trendtracker.h"
using namespace std;
inline void _test(const char* expression, const char* file, int line) { cerr
#define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__))
int main() {
// Setup vector R; string s, line;
// Test size(), insert() Trendtracker T1; test(T1.size() == 0); test(T1.popularity("#algorithms") == -1); test(T1.popularity("#cs4all") == -1); test(T1.popularity("#programming") == -1);
T1.insert("#cs4all"); test(T1.size() == 1); test(T1.popularity("#algorithms") == -1); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == -1);
T1.insert("#algorithms"); test(T1.size() == 2); test(T1.popularity("#algorithms") == 0); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == -1);
T1.insert("#programming"); test(T1.size() == 3); test(T1.popularity("#algorithms") == 0); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == 0);
T1.insert("#algorithms"); test(T1.size() == 3); test(T1.popularity("#algorithms") == 0); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == 0);
// Test tweeted()
^^^ (Due to chegg limit, had to convert this code portion into picture mode) ^^^ Trendtracker T2; T2.insert("#3333"); T2.insert("#programming"); T2.insert("#cs4all"); T2.insert("#C++"); T2.insert("#algorithms"); T2.tweeted("#programming"); T2.tweeted("#programming"); T2.tweeted("#programming"); T2.tweeted("#programming"); T2.tweeted("#programming"); T2.tweeted("#C++"); T2.tweeted("#C++"); T2.tweeted("#C++"); T2.tweeted("#C++"); T2.tweeted("#cs4all"); T2.tweeted("#cs4all"); T2.tweeted("#cs4all"); T2.tweeted("#algorithms"); T2.tweeted("#algorithms"); T2.tweeted("#3333"); test(T2.popularity("#programming") == 5); test(T2.popularity("#cs4all") == 3); test(T2.popularity("#algorithms") == 2); test(T2.popularity("#C++") == 4); test(T2.popularity("#3333") == 1); T2.insert("#3333"); T2.insert("#programming"); T2.insert("#cs4all"); T2.insert("#C++"); T2.insert("#algorithms"); test(T2.popularity("#programming") == 5); test(T2.popularity("#cs4all") == 3); test(T2.popularity("#algorithms") == 2); test(T2.popularity("#C++") == 4); test(T2.popularity("#3333") == 1);
// Enforce no usage of global variables test(T1.popularity("#algorithms") == 1); test(T1.popularity("#cs4all") == 2); test(T1.popularity("#datastructures") == 4); test(T1.popularity("#programming") == 3);
Trendtracker T3; test(T3.top_trend() == ""); T3.top_three_trends(R); test(R.size() == 0);
T3.insert("#programming"); test(T3.top_trend() == "#programming"); T3.top_three_trends(R); test(R.size() == 1); test(R[0] == "#programming");
T3.tweeted("#programming"); test(T3.top_trend() == "#programming"); T3.top_three_trends(R); test(R.size() == 1); test(R[0] == "#programming");
// At this point: // programming: 1
T3.insert("#C++"); T3.tweeted("#C++"); T3.tweeted("#C++"); test(T3.top_trend() == "#C++");
T3.top_three_trends(R); test(R.size() == 2); test(R[0] == "#C++"); test(R[1] == "#programming");
// At this point: // C++: 2 // programming: 1
T3.insert("#3333"); T3.tweeted("#3333"); T3.tweeted("#3333"); T3.tweeted("#3333"); test(T3.top_trend() == "#3333"); T3.top_three_trends(R); test(R.size() == 3); test(R[0] == "#3333"); test(R[1] == "#C++"); test(R[2] == "#programming");
// At this point: // 3333: 3 // C++: 2 // programming: 1
T3.insert("#cs4all"); T3.tweeted("#cs4all"); T3.tweeted("#cs4all"); T3.tweeted("#cs4all"); T3.tweeted("#cs4all"); test(T3.top_trend() == "#cs4all"); T3.top_three_trends(R); test(R.size() == 3); test(R[0] == "#cs4all"); test(R[1] == "#3333"); test(R[2] == "#C++");
// At this point: // cs4all: 4 // 3333: 3 // C++: 2 // programming: 1
T3.tweeted("#programming"); T3.tweeted("#programming"); T3.tweeted("#programming"); T3.tweeted("#programming"); test(T3.top_trend() == "#programming"); T3.top_three_trends(R); test(R.size() == 3); test(R[0] == "#programming"); test(R[1] == "#cs4all"); test(R[2] == "#3333");
// At this point: // programming: 5 // cs4all: 4 // 3333: 3 // C++: 2
T3.tweeted("#cs4all"); T3.tweeted("#cs4all"); T3.tweeted("#3333"); test(T3.top_trend() == "#cs4all"); T3.top_three_trends(R); test(R.size() == 3); test(R[0] == "#cs4all"); test(R[1] == "#programming"); test(R[2] == "#3333");
// At this point: // cs4all: 6 // programming: 5 // 3333: 4 // C++: 2
for (int i = 0; i
//Testing remove() T3.remove("#C++"); T3.remove("#programming"); T3.top_three_trends(R); test(R.size() == 2); test(R[0] == "#cs4all"); test(R[1] == "#3333"); test(T3.size() == 2);
Trendtracker T4;
ifstream f; f.open("common.txt"); assert(f.is_open()); // If this fails, you're missing common.txt while (getline(f, line)) T4.insert(line); f.close(); test(T4.size() == 3597);
f.open("common.txt"); while (getline(f, line)) T4.tweeted(line); f.close();
for (int i = 0; i
test(T4.top_trend() == "#finishing");
T4.top_three_trends(R); test(R[0] == "#finishing"); test(R[1] == "#completely"); test(R[2] == "#is"); }
//Test top_k_trends string weird = "#"; for (int i = 'a'; i
T4.top_k_trends(R, 50);
test(R[2] == "#up"); test(R[5] == "#so"); test(R[10] == "#ok"); test(R[15] == "#me"); test(R[29] == "#finishing"); test(R[32] == "#quieting");
cout
/////
trendtracker.h
/////
For trendtracker.h (Sorry for inconvenience but limit size prevents me!)
common.txt (It's a large text file of just words in ascending order of word-size-)
Find a simple data text file online that includes a range of words..
/////
trendtracker.cpp (My attempt so far...)
/////
#include "trendtracker.h" #include
// default constructor Trendtracker::Trendtracker() { E.clear(); S.clear(); //The S vector is something that I found from somewhere else. (Might need to include "vector
//Implementation of the method insert void Trendtracker::insert(string ht) { int i = S_index(ht); if (i == -1) { Entry en; en.hashtag = ht; en.pop = 0; E.push_back(en); } }
//Implementation of the method size int Trendtracker::size() { return E.size(); }
//Implementation of the method tweeted void Trendtracker::tweeted(string ht) {
int i = S_index(ht);
if (i != -1) { E[i].pop = E[i].pop + 1; if (E[i].pop > E[i - 1].pop) { swap(E[i], E[i - 1]); ///I need to update S as well } } }
//Implementation of the method popularity int Trendtracker::popularity(string name) { int i = S_index(name);
if (i != -1) return E[i].pop; else return -1; }
/////
Objective: Ensure it is under 1 minute of runtime and that it gets an "Assignment Complete" on console.
The Twitter website has become a de facto first source for many important events in the last decade. Twitter's hashtag feature lets users tag tweets with single words or phrases (e.g. #superbowl, #algorithms, or #vacaciones). Popular or trending hashtags indicate strong shared interest by many people in a topic, and tracking these trends is of interest to businesses, news outlets, and researchers. string hashtag vectorStep 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