Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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() image text in transcribed

^^^ (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

/////

image text in transcribed

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 using namespace std;

// default constructor Trendtracker::Trendtracker() { E.clear(); S.clear(); //The S vector is something that I found from somewhere else. (Might need to include "vector S;" in the header file. }

//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 vector E- #cat #gig #hot #fad #ads #egg #big #dog 2 1 6 2 9 8 0 int pop Figure 1: Representing hashtags and their popularities using a vector-based data structure. In this homework, you'll implement an vector-based data structure that tracks information about a collection of hashtags, including which are most popular, i.e. are trending. The following files have been given to you: 1. A C++ header file (trendtracker.h) declaring the Trendtracker class. 2. A C++ source file (main.cpp) containing a main function with tests. 3. A text file (common.txt) containing 3612 common English words.? Download the files at: common.txt main.cpp trendtracker.h 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. Submit the source file trendtracker.cpp. 60 61 62 63 63 64 65 CE 66 67 // Test tweeted() 11. tweeted("#programming"); test(T1.popularity("#algorithms") == 0); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == 1); Ti.tweeted ("#programming"); test(T1.popularity("#algorithms") == 0); test(T1.popularity ("#cs4all") == @); test(T1.popularity("#programming") == 2); ; T1.tweeted("#programming"); test(T1.popularity("#algorithms") == 0); test(T1.popularity("#cs4all") == 0); test(T1.popularity("#programming") == 3); T1.tweeted ("#cs4all"); test(T1.popularity("#algorithms") == 0); test(T1.popularity ("#c54all") == 1); test(T1.popularity("#programming") == 3); 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 T1. tweeted("#algorithms"); test(T1.popularity("#algorithms") == 1); test(T1.popularity("#cs4all") == 1); test(T1.popularity("#programming") == 3); T1. tweeted("#cs4all"); test(T1.popularity("#algorithms") == 1); test(11.popularity("#c54all") == 2); test(T1.popularity("#programming") == 3); 3 93 T1. tweeted("#datastructures"); test(T1.popularity("#algorithms") == 1); test(T1.popularity("#cs4all") == 2); test(T1.popularity("#datastructures") == -1); test(T1.popularity("#programming") == 3); ; 94 95 96 97 98 99 100 101 t1.insert("#datastructures"); test(T1. popularity("#algorithms") == 1); test(T1.popularity("#c54all") == 2); test(T1.popularity("#datastructures") == 0); test(T1.popularity("#programming") == 3); ); T1. tweeted("#datastructures"); test(T1.popularity("#algorithms") == 1); test(T1.popularity("#cs4all") == 2); test(T1.popularity("#datastructures") == 1); test(T1.popularity ("#programming") == 3); ); T1. tweeted("#datastructures"); test(T1.popularity("#algorithms") == 1); test(71.popularity("#cs4all") == 2); 2 test(T1.popularity("#datastructures") == 2); 2) test(T1.popularity("#programming") == 3); ; 102 103 104 102 105 105 106 106 197 107 108 100 100 109 110 110 111 111 112 110 113 114 115 116 117 - 118 119 *** 120 121 122 123 124 125 126 127 128 T1. tweeted ("#datastructures"); test(T1.popularity("#algorithms") == 1); test(T1.popularity("#cs4all") == 2); 2 test(T1.popularity("#datastructures") == 3); test(T1.popularity("#programming") == 3); 3 11. tweeted ("#datastructures"); test(11.popularity("#algorithms") == 1); test(T1.popularity("#c54all") == 2); test(T1.popularity("#datastructures") == 4); test(11.popularity("#programming") == 3); Trendtracker T2; T2 incert/#3333). 120 #ifndef TRENDTRACKER_H #define TRENDTRACKER_H #include #include using namespace std; class Trendtracker { // For the mandatory running times below: Il n is the number of hashtags in the Trendtracker. public: // Creates a new Trendtracker tracking no hashtags. 11 1/ Must run in O(1) time. Trendtracker(); // Inserts a hashtag (tweeted 0 times) into the Trendtracker. // If the hashtag already is in Trendtracker, does nothing. // Must run in O(n) time. void insert(string ht); // Return the number of hashtags in the Trendtracker. // Must run in 0(1) time. int size(); // Adds 1 to the total number times a hashtag has been tweeted. // If the hashtag does not exist in TrendTracker, does nothing. // // Must run in O(n) time. void tweeted(string ht); // Returns the number of times a hashtag has been tweeted. // If the hashtag does not exist in Trendtracker, returns -1. // // Must run in O(n) time. int popularity (string name); // Returns a most-tweeted hashtag. // If the Trendtracker has no hashtags, returns "". // Must run in O(n) time. string top_trend(); // Fills the provided vector with the 3 most-tweeted hashtags, // in order from most-tweeted to least-tweeted. // // If there are fewer than 3 hashtags, then the vector is filled // with all hashtags (in most-tweeted to least-tweeted order). // Must run in O(n) time. void top_three_trends (vector &T); // Remove the given hashtag from the trendtracker. // // Must run in O(n) time. void remove(string ht); // Fills the provided vector with the k most-tweeted hashtags, // in order from most-tweeted to least-tweeted. // If there are fewer than k hashtags, then the vector is filled // with all hashtags (in most-tweeted to least-tweeted order). // Must run in O(nk) time. void top_k_trends(vector &T, int k); private: // A simple class representing a hashtag and // the number of times it has been tweeted. class Entry { public: string hashtag: int pop; }; // Entries containing each hashtag and its popularity. vector E; }; #endit

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago